Kubernetes for

Java Developers

Created by James Strachan / @jstrachan from Red Hat

How can we deliver business value faster?

despite increasing complexity, platforms, devices, SaaS, social media, IoC, integrations, capabilities, scale and data centres?

Microservices

  • refactor monolith into separate services
    • each microservice has its own release cycle
    • smaller independent releases
  • refactor team into separate teams
    • one team of Dev + Testing + Ops per microservice
    • 2 pizza rule rather than Mythical Man month
  • iterate faster and win!
    • scale teams and software through federation
    • reduce complexity per microservice so you can go faster

DevOps

  • immutable infrastructure
    • cattle not pets
  • automate everything
    • Continous Integration
    • Continous Delivery / Deployment

Docker

package your micro service into a shipping container

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

Docker

docker run -itP myuser/myservice

Kubernetes

orchestrate your containers!

https://kubernetes.io/

Project Atomic

micro service based Linux

projectatomic.io

RHEL Atomic is the product

OpenShift V3

docker / kubernetes based PaaS

openshift.github.io

Kubernetes Overview

https://kubernetes.io/

Kubernetes: sub atomic particles

  • Pods
  • Replication Controllers
  • Services

Pod

  • 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


apiVersion: "v1"
kind: "ReplicationController"
metadata:
  name: "elasticsearch"
spec:
  replicas: 1
  selector:
    component: "elasticsearch"
    provider: "fabric8"
  template:
    metadata:
      labels:
        component: "elasticsearch"
        provider: "fabric8"
    spec:
      containers:
        -
          name: "elasticsearch"
          image: "fabric8/elasticsearch-k8s:1.5.2"
          env:
            -
              name: "SERVICE_DNS"
              value: "elasticsearch-cluster"
          ports:
            -
              containerPort: 9200
              name: "http"

Replication Controller

Service

  • each service has its own unique IP address

apiVersion: "v1"
kind: "Service"
metadata:
  name: "elasticsearch"
  labels:
    component: "elasticsearch"
    provider: "fabric8"
spec:
  ports:
    -
      port: 80
      targetPort: 9200
  selector:
    component: "elasticsearch"
    provider: "fabric8"

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}/

Kubernetes: sub atomic particles

  • Pods
  • Replication Controllers
  • Services

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

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

Integration Testing

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

Any questions?

kubernetes.io orchestrate your containers
docker.com create container images for kubernetes
projectatomic.io kubernetes based Linux
openshift.github.io kubernetes based PaaS
fabric8.io console, tools and apps for kubernetes
@jstrachan