Kubernetes

for Java Developers



fabric8.io


Doing Microservices with Fabric8!

Docker

Package your micro service into a shipping container.

https://www.docker.com

Containers v/s VMs

https://www.docker.com

Docker

  • Packaging for a linux process:
    • immutable images
    • run everywhere
    • images are small and easy to cache
  • Isolate processes:
    • each container has its own file system and ports
      • avoids conflicts between containers
    • set limits: IO, CPU, memory, ...
      • helps pack containers onto hosts
    • run 1000s of containers per node rather than 10s of VMs

Kubernetes

orchestrate your containers!

https://kubernetes.io

OpenShift V3

Docker / kubernetes based PaaS

openshift.github.io

Kubernetes Overview

Kubernetes is an open-source system for automating deployment, scaling, and management of containerized applications.

  • Automatic binpacking.
  • Self-healing.
  • Horizontal scaling.
  • Service discovery and load balancing.
  • Automated rollouts and rollbacks.
  • Secret and configuration management.
  • Storage orchestration.


https://kubernetes.io

Kubernetes: Sub Atomic particles


  • Pods
  • Replication Controllers
  • Services

Pod

group of one or more containers

  • One or more Docker containers with:
    • environment variables
    • ports
    • volumes
  • Pod has its own unique IP address
  • Containers can work locally together
    • communicate locally on the pod IP and container ports
    • share local or persistent disk

Replication Controller

makes sure that a pod is always up & available


   apiVersion: v1
   kind: ReplicationController
   metadata:
     name: nginx
   spec:
     replicas: 3
     selector:
       app: nginx
       spec:
         containers:
          - name: nginx
            image: nginx
            ports:
          - containerPort: 80

Service

each service has its own unique IP addres


   kind: Service
   apiVersion: v1
   metadata:
      name: myapp-service
   spec:
     selector:
        app: nginx
     ports:
        - protocol: TCP
          port: 80
          targetPort: 9376
     type: LoadBalancer //ClusterIp and NodePort
	  

Microservice on Kubernetes?


Each microservice typically has:

  • Replication Controller
  • Service

Kubernetes service discovery


For a service called foo-bar here is how you discover to it:

  • $FOO_BAR_SERVICE_HOST
  • $FOO_BAR_SERVICE_PORT


e.g. http://${FOO_BAR_SERVICE_HOST}:${FOO_BAR_SERVICE_PORT}

Develop microservices on Kubernetes


  • Write some code
  • Put code into docker image
  • Create kubernetes metadata
  • Apply the metadata
  • Resize and rolling upgrades

Fabric8

https://fabric8.io

What is Fabric8?


  • Microservices that run on Kubernetes
    • Management: (Console, Logging, Metrics)
    • Continuous Delivery
    • iPaaS
  • Tools for Java developers

Fabric8: Java Tools


  • Maven plugin
  • Dependency Injection
    • CDI
    • Spring
  • Java Libraries
  • Integration Testing
    • Arquillian plugin for JUnit

Fabric8: Maven Plugin


Build docker image:


   $ mvn docker:build
					

Generate kubernetes json:


   $ mvn fabric8:json
					

Apply kubernetes json and image to kubernetes:


   $ mvn fabric8:apply
					

CDI / Spring


   @Inject
   @ServiceName("myapp-service")
   String myServiceUrl;
   
   @Inject
   @ServiceName("some-other-app")
   @Protocol("http")
   @External
   String externalAppUrl;
   
   @Inject
   @Endpoint
   @ServiceName("cheese-service")
   List<String> cheeseEndpointUrls;
   

http://fabric8.io/guide/cdi.html

Fabric8: Ops Tools


  • Console
  • Logging
    • Elasticsearch
    • Kibana
  • Metrics
    • Prometheus
    • Grafana

Fabric8: Team Tools


  • Chat, Issues & Notification
    • Hubot
    • Lets Chat
    • Slack
  • Issues & Kanban
    • Taiga
  • Source code
    • Gogs
    • Gerrit
    • Gitlab

Fabric8: iPaaS


  • Integration as a Service
    • Apache Camel
  • Messaging as a Service
    • Apache ActiveMQ
  • APIs
    • Apiman
    • API Registry
  • Console & Web IDE
    • hawtio
    • Eclipse Orion

CI/CD Pipeline in Fabric8

Demo


  1. Aviation Monolith App with CI/CD pipeline.
  2. Deploy it to various Environments.
  3. Make changes in the code and push the changes to see automated build.
  4. MySQL database in Kubernetes.
  5. Other features inside Fabric8 console:
    • CI/CD - Jenkins, Gogs, Nexus
    • Docker Registry
    • ChatOps
    • Logging & Metrics
    • Messaging
    • Zookeeper
    • Zipkin

Questions?


© 2017. Sanjay Rawat



E-Mail
@RawSanj
@Raw_Sanj
stackoverflow