package your java application using docker and kubernetes · service discovery & lb: docker...

50

Upload: others

Post on 22-May-2020

23 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Package your Java Application using Docker and Kubernetes · Service Discovery & LB: Docker Docker Compose – Define and run multi-container applications – Configuration defined
Page 2: Package your Java Application using Docker and Kubernetes · Service Discovery & LB: Docker Docker Compose – Define and run multi-container applications – Configuration defined

PackageyourJavaApplicationusingDockerandKubernetes

Arun Gupta, @arungupta

Page 3: Package your Java Application using Docker and Kubernetes · Service Discovery & LB: Docker Docker Compose – Define and run multi-container applications – Configuration defined

Docker Captain Java Champion

JavaOne Rock Star (4 years) NetBeans Dream Team

Silicon Valley JUG Leader Author Runner

Lifelong learner

2

Page 4: Package your Java Application using Docker and Kubernetes · Service Discovery & LB: Docker Docker Compose – Define and run multi-container applications – Configuration defined

DockerWorkflow

3

Page 5: Package your Java Application using Docker and Kubernetes · Service Discovery & LB: Docker Docker Compose – Define and run multi-container applications – Configuration defined

OrchestrationFrameworks▪Developer

– Core concepts – Cluster – Single container – Multi-container

– Service discovery & LB – Persistent Volumes – Local development

▪Ops – Multiple master – Scheduler – Rules and constraints – Monitoring – Rolling Update – Cloud/commercial support

4

Page 6: Package your Java Application using Docker and Kubernetes · Service Discovery & LB: Docker Docker Compose – Define and run multi-container applications – Configuration defined

CoreConcepts:DockerManager

5

docker swarm init --listen-addr <ip>:2377

Page 7: Package your Java Application using Docker and Kubernetes · Service Discovery & LB: Docker Docker Compose – Define and run multi-container applications – Configuration defined

CoreConcepts:DockerWorker

6

docker swarm join --token <worker_token> <manager>:2377

Page 8: Package your Java Application using Docker and Kubernetes · Service Discovery & LB: Docker Docker Compose – Define and run multi-container applications – Configuration defined

CoreConcepts:AddMoreWorkers

7

docker swarm join --token <worker_token> <manager>:2377

Page 9: Package your Java Application using Docker and Kubernetes · Service Discovery & LB: Docker Docker Compose – Define and run multi-container applications – Configuration defined

CoreConcepts:Primary/SecondaryMaster

8

docker swarm join --manager --token <manager_token> --listen-addr <master2>:2377 <master1>:2377

Page 10: Package your Java Application using Docker and Kubernetes · Service Discovery & LB: Docker Docker Compose – Define and run multi-container applications – Configuration defined

Swarm Manager

Swarm Worker Swarm WorkerSwarm Worker Swarm WorkerSwarm Worker

Swarm Manager Swarm Manager

Raft Consensus Group

Gossip Network

primary secondary secondary Container

CoreConcepts:Cluster

Strongly consistent Replicated (Raft based) Extremely fast (in-memory reads)

Page 11: Package your Java Application using Docker and Kubernetes · Service Discovery & LB: Docker Docker Compose – Define and run multi-container applications – Configuration defined

CoreConcepts:ReplicatedService

10

docker service create --replicas 3 --name web jboss/wildfly

Page 12: Package your Java Application using Docker and Kubernetes · Service Discovery & LB: Docker Docker Compose – Define and run multi-container applications – Configuration defined

CoreConcepts:NodeFailure

11

X

Page 13: Package your Java Application using Docker and Kubernetes · Service Discovery & LB: Docker Docker Compose – Define and run multi-container applications – Configuration defined

CoreConcepts:Desired!=Actual

12

Page 14: Package your Java Application using Docker and Kubernetes · Service Discovery & LB: Docker Docker Compose – Define and run multi-container applications – Configuration defined

CoreConcepts:Reconcile

13

Page 15: Package your Java Application using Docker and Kubernetes · Service Discovery & LB: Docker Docker Compose – Define and run multi-container applications – Configuration defined

CoreConcepts:ContainerFailure

14

X

Page 16: Package your Java Application using Docker and Kubernetes · Service Discovery & LB: Docker Docker Compose – Define and run multi-container applications – Configuration defined

CoreConcepts:Desired!=Actual

15

Page 17: Package your Java Application using Docker and Kubernetes · Service Discovery & LB: Docker Docker Compose – Define and run multi-container applications – Configuration defined

CoreConcepts:Reconcile

16

Page 18: Package your Java Application using Docker and Kubernetes · Service Discovery & LB: Docker Docker Compose – Define and run multi-container applications – Configuration defined

CoreConcepts:Scale

17

docker service scale web=6

Page 19: Package your Java Application using Docker and Kubernetes · Service Discovery & LB: Docker Docker Compose – Define and run multi-container applications – Configuration defined

CoreConcepts:GlobalService

18

docker service create --mode=global --name=prom prom/prometheus

Page 20: Package your Java Application using Docker and Kubernetes · Service Discovery & LB: Docker Docker Compose – Define and run multi-container applications – Configuration defined

©2016CouchbaseInc.

CoreConcepts:Kubernetes▪Pods: colocated group of containers that share an IP, namespace, storage volume ▪Replica Set: manages the lifecycle of pods and ensures specified number are running (next gen Replication Controller) ▪Service: Single, stable name for a set of pods, also acts as LB ▪Label: used to organize and select group of objects

19

“db”

port 8091 port 8091

NodeDocker

Pod

Containers

Page 21: Package your Java Application using Docker and Kubernetes · Service Discovery & LB: Docker Docker Compose – Define and run multi-container applications – Configuration defined

©2016CouchbaseInc.

CoreConcepts:Kubernetes▪Node: Machine or VM in the cluster ▪Master: Central control plane, provides unified view of the cluster

– etcd: distributed key-value store used to persist Kubernetes system state

▪Worker: Docker host running kubelet (node agent) and proxy services

– Runs pods and containers – Monitored by systemd (CentOS) or

monit (Debian)

20

Master

API Server(pods, services, …)

Controller Manager

etcdetcdetcd

Scheduler

Worker

Docker

Kubelet Proxy

Page 22: Package your Java Application using Docker and Kubernetes · Service Discovery & LB: Docker Docker Compose – Define and run multi-container applications – Configuration defined

©2016CouchbaseInc.

Master

Worker

Docker

21

Kubelet

API Server(pods, services, …)

Controller ManagerScheduler

etcdetcdetcd

Proxy

Worker

Docker

Kubelet Proxy

kubectl

Internet

Load Balancer

Kubernetes Cluster

Page 23: Package your Java Application using Docker and Kubernetes · Service Discovery & LB: Docker Docker Compose – Define and run multi-container applications – Configuration defined

ServiceDiscovery&LB:Docker

▪Docker Compose – Define and run multi-container applications – Configuration defined in one or more files

– docker-compose.yml (default)– docker-compose.override.yml (default)– Multiple files specified using -f

– Deployed as Docker Stack– Great for dev, staging, and CI

22

Page 24: Package your Java Application using Docker and Kubernetes · Service Discovery & LB: Docker Docker Compose – Define and run multi-container applications – Configuration defined

ServiceDiscoverywithDocker

23

docker stack deploy --compose-file=docker-compose.yml webapp

Page 25: Package your Java Application using Docker and Kubernetes · Service Discovery & LB: Docker Docker Compose – Define and run multi-container applications – Configuration defined

24

StackService

Task

Page 26: Package your Java Application using Docker and Kubernetes · Service Discovery & LB: Docker Docker Compose – Define and run multi-container applications – Configuration defined

25

docker service create --replicas 3 --name web -p 8080:8080 jboss/wildfly

LoadBalancing:Docker

Load Balancer

Page 27: Package your Java Application using Docker and Kubernetes · Service Discovery & LB: Docker Docker Compose – Define and run multi-container applications – Configuration defined

©2016CouchbaseInc.

ServiceDiscovery:Kubernetes

▪Service: Abstract a set of pods as a single IP and port – Simple TCP/UDP load balancing

▪Creates environment variables in other pods or DNS resolution ▪Stable endpoint for pods to reference

– Allows list of pods to change dynamically

26

Page 28: Package your Java Application using Docker and Kubernetes · Service Discovery & LB: Docker Docker Compose – Define and run multi-container applications – Configuration defined

©2016CouchbaseInc.

ServiceDiscoverywithKubernetes

27

Page 29: Package your Java Application using Docker and Kubernetes · Service Discovery & LB: Docker Docker Compose – Define and run multi-container applications – Configuration defined

©2016CouchbaseInc.

Node

Couchbase Service

CouchbaseService:Kubernetes

28

Page 30: Package your Java Application using Docker and Kubernetes · Service Discovery & LB: Docker Docker Compose – Define and run multi-container applications – Configuration defined

©2016CouchbaseInc.

“backend”

“frontend”

ServiceandReplicaSet:Kubernetes

29

Couchbase Service

Page 31: Package your Java Application using Docker and Kubernetes · Service Discovery & LB: Docker Docker Compose – Define and run multi-container applications – Configuration defined

DockerVolumes:PersistentContainers

30

Implicit Per-Container

Explicit Per-Container Per-Host Multi-Host

What? Default sandbox Explicit volume Directory on hostStorage on

distributed file systems

Location /var/lib/docker/volumes on the host

/var/lib/docker/volumes on the host

Mounted within container

Ceph, GlusterFS, NFS, …

Container crash Directory unavailable Directory unavailable Yes Yes

Host crash Directory unavailable Directory unavailable No Yes

Shared No Yes Yes (host only) Yes (cluster wide)

Page 32: Package your Java Application using Docker and Kubernetes · Service Discovery & LB: Docker Docker Compose – Define and run multi-container applications – Configuration defined

DockerVolumePlugin

▪“Batteries included, but replaceable” ▪Includes default driver for host-based volumes ▪Plugins enables containers to be integrated with external storage systems

– For example, Amazon EBS, Azure Storage and GCE Persistent Disks

31

Page 33: Package your Java Application using Docker and Kubernetes · Service Discovery & LB: Docker Docker Compose – Define and run multi-container applications – Configuration defined

DockerVolumePluginArchitecture

32

Docker Client

Docker Host

Plugin Client

PluginDaemon

StorageBackend

Storage Backend

StorageBackend

StorageBackend

local

Page 34: Package your Java Application using Docker and Kubernetes · Service Discovery & LB: Docker Docker Compose – Define and run multi-container applications – Configuration defined

DockerVolumePluginwithPortworx

33

Docker Client

Docker Host

Portworx Client PX-Dev Amazon

EBSportworx

Page 35: Package your Java Application using Docker and Kubernetes · Service Discovery & LB: Docker Docker Compose – Define and run multi-container applications – Configuration defined

©2016CouchbaseInc.

KubernetesVolume

▪Directory accessible to the containers in a pod ▪Volume outlives any containers in a pod ▪Common types

– hostPath– nfs– awsElasticBlockStore– gcePersistentDisk

34

Page 36: Package your Java Application using Docker and Kubernetes · Service Discovery & LB: Docker Docker Compose – Define and run multi-container applications – Configuration defined

©2016CouchbaseInc.

KubernetesPersistentVolume

35

Provision Network Storage Request Storage Use Claim

PersistentVolume PersistentVolumeClaim Claims are mounted as

volumes

1 2 3

http://blog.couchbase.com/2016/july/stateful-containers-kubernetes-amazon-ebs

Page 37: Package your Java Application using Docker and Kubernetes · Service Discovery & LB: Docker Docker Compose – Define and run multi-container applications – Configuration defined

©2016CouchbaseInc.

Amazon Web Services

“worker”“master”

KubernetesVolume:PersistentContainer

36

“worker”

Kubernetes Cluster

Pod

Couchbase Docker

Container

Replication Controller Publicly

accessible Service

Storage

Page 38: Package your Java Application using Docker and Kubernetes · Service Discovery & LB: Docker Docker Compose – Define and run multi-container applications – Configuration defined

©2016CouchbaseInc.

Amazon Web Services

“worker”“master”

KubernetesVolume:PersistentContainer

37

“worker” EBS

http://blog.couchbase.com/2016/july/stateful-containers-kubernetes-amazon-ebs

Page 39: Package your Java Application using Docker and Kubernetes · Service Discovery & LB: Docker Docker Compose – Define and run multi-container applications – Configuration defined

©2016CouchbaseInc.

Amazon Web Services

“worker”“master”

Kubernetes:PersistentContainerswithPortworx

38

“worker”

EBS

S3SAN

SSD

HDD

https://github.com/arun-gupta/couchbase-kubernetes/tree/master/cluster-petset-portworx

Page 40: Package your Java Application using Docker and Kubernetes · Service Discovery & LB: Docker Docker Compose – Define and run multi-container applications – Configuration defined

Development:Docker▪Docker Community Edition

– Docker for Mac/Windows/Linux – Monthly edge and quarterly stable releases – Native desktop or cloud provider experience

39

Page 41: Package your Java Application using Docker and Kubernetes · Service Discovery & LB: Docker Docker Compose – Define and run multi-container applications – Configuration defined

Development:Kubernetes

▪Single node cluster – minikube

▪Multi-node cluster – kops – kube-aws (CoreOS + AWS) – kube-up (deprecated) – Google Cloud, Azure, Tectonic, …

40

Page 42: Package your Java Application using Docker and Kubernetes · Service Discovery & LB: Docker Docker Compose – Define and run multi-container applications – Configuration defined

RollingUpdate:Docker

41

docker service update web --image wildfly:2 --update-parallelism 2 --update-delay 10s

2 2

22

2

2

1 1

11

1

1

Page 43: Package your Java Application using Docker and Kubernetes · Service Discovery & LB: Docker Docker Compose – Define and run multi-container applications – Configuration defined

©2016CouchbaseInc.

RollingUpdate:Kubernetes

42

Application Service

1 1 1

2 2 2 etcd

webapp-rc

webapp-rc-xxxxwebapp-rc

https://github.com/arun-gupta/kubernetes-java-sample/tree/master/rolling-update

Page 44: Package your Java Application using Docker and Kubernetes · Service Discovery & LB: Docker Docker Compose – Define and run multi-container applications – Configuration defined

Monitoring:Docker

43

▪docker container stats CLI ▪Docker Remote API ▪docker system events CLI ▪In-built Prometheus endpoint ▪cAdvisor

Page 45: Package your Java Application using Docker and Kubernetes · Service Discovery & LB: Docker Docker Compose – Define and run multi-container applications – Configuration defined

Monitoring:Docker

44

Page 46: Package your Java Application using Docker and Kubernetes · Service Discovery & LB: Docker Docker Compose – Define and run multi-container applications – Configuration defined

©2016CouchbaseInc.

Worker

45

Kubelet cAdvisor

Monitoring:Kubernetes

WorkerKubelet cAdvisor

WorkerKubelet cAdvisor

InfluxDB + Grafana Heapster

Master

Page 47: Package your Java Application using Docker and Kubernetes · Service Discovery & LB: Docker Docker Compose – Define and run multi-container applications – Configuration defined

©2016CouchbaseInc.

Page 48: Package your Java Application using Docker and Kubernetes · Service Discovery & LB: Docker Docker Compose – Define and run multi-container applications – Configuration defined

©2016CouchbaseInc.

Monitoring:DockerandKubernetes

47

Page 49: Package your Java Application using Docker and Kubernetes · Service Discovery & LB: Docker Docker Compose – Define and run multi-container applications – Configuration defined

References

▪Docker: docker.io ▪Kubernetes: kubernetes.io ▪Slides: https://github.com/javaee-samples/docker-java

48

Page 50: Package your Java Application using Docker and Kubernetes · Service Discovery & LB: Docker Docker Compose – Define and run multi-container applications – Configuration defined

www.modsummit.com

www.developersummit.com