Docker Compose and Panamax - ContainerDays Boston - June 2015
Package your Java Application using Docker and Kubernetes · Service Discovery & LB: Docker Docker...
Transcript of Package your Java Application using Docker and Kubernetes · Service Discovery & LB: Docker Docker...
![Page 1: Package your Java Application using Docker and Kubernetes · Service Discovery & LB: Docker Docker Compose – Define and run multi-container applications – Configuration defined](https://reader031.fdocuments.in/reader031/viewer/2022013021/5ec980d8673f5a76c75dcf07/html5/thumbnails/1.jpg)
![Page 2: Package your Java Application using Docker and Kubernetes · Service Discovery & LB: Docker Docker Compose – Define and run multi-container applications – Configuration defined](https://reader031.fdocuments.in/reader031/viewer/2022013021/5ec980d8673f5a76c75dcf07/html5/thumbnails/2.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022013021/5ec980d8673f5a76c75dcf07/html5/thumbnails/3.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022013021/5ec980d8673f5a76c75dcf07/html5/thumbnails/4.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022013021/5ec980d8673f5a76c75dcf07/html5/thumbnails/5.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022013021/5ec980d8673f5a76c75dcf07/html5/thumbnails/6.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022013021/5ec980d8673f5a76c75dcf07/html5/thumbnails/7.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022013021/5ec980d8673f5a76c75dcf07/html5/thumbnails/8.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022013021/5ec980d8673f5a76c75dcf07/html5/thumbnails/9.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022013021/5ec980d8673f5a76c75dcf07/html5/thumbnails/10.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022013021/5ec980d8673f5a76c75dcf07/html5/thumbnails/11.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022013021/5ec980d8673f5a76c75dcf07/html5/thumbnails/12.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022013021/5ec980d8673f5a76c75dcf07/html5/thumbnails/13.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022013021/5ec980d8673f5a76c75dcf07/html5/thumbnails/14.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022013021/5ec980d8673f5a76c75dcf07/html5/thumbnails/15.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022013021/5ec980d8673f5a76c75dcf07/html5/thumbnails/16.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022013021/5ec980d8673f5a76c75dcf07/html5/thumbnails/17.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022013021/5ec980d8673f5a76c75dcf07/html5/thumbnails/18.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022013021/5ec980d8673f5a76c75dcf07/html5/thumbnails/19.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022013021/5ec980d8673f5a76c75dcf07/html5/thumbnails/20.jpg)
©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](https://reader031.fdocuments.in/reader031/viewer/2022013021/5ec980d8673f5a76c75dcf07/html5/thumbnails/21.jpg)
©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](https://reader031.fdocuments.in/reader031/viewer/2022013021/5ec980d8673f5a76c75dcf07/html5/thumbnails/22.jpg)
©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](https://reader031.fdocuments.in/reader031/viewer/2022013021/5ec980d8673f5a76c75dcf07/html5/thumbnails/23.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022013021/5ec980d8673f5a76c75dcf07/html5/thumbnails/24.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022013021/5ec980d8673f5a76c75dcf07/html5/thumbnails/25.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022013021/5ec980d8673f5a76c75dcf07/html5/thumbnails/26.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022013021/5ec980d8673f5a76c75dcf07/html5/thumbnails/27.jpg)
©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](https://reader031.fdocuments.in/reader031/viewer/2022013021/5ec980d8673f5a76c75dcf07/html5/thumbnails/28.jpg)
©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](https://reader031.fdocuments.in/reader031/viewer/2022013021/5ec980d8673f5a76c75dcf07/html5/thumbnails/29.jpg)
©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](https://reader031.fdocuments.in/reader031/viewer/2022013021/5ec980d8673f5a76c75dcf07/html5/thumbnails/30.jpg)
©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](https://reader031.fdocuments.in/reader031/viewer/2022013021/5ec980d8673f5a76c75dcf07/html5/thumbnails/31.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022013021/5ec980d8673f5a76c75dcf07/html5/thumbnails/32.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022013021/5ec980d8673f5a76c75dcf07/html5/thumbnails/33.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022013021/5ec980d8673f5a76c75dcf07/html5/thumbnails/34.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022013021/5ec980d8673f5a76c75dcf07/html5/thumbnails/35.jpg)
©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](https://reader031.fdocuments.in/reader031/viewer/2022013021/5ec980d8673f5a76c75dcf07/html5/thumbnails/36.jpg)
©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](https://reader031.fdocuments.in/reader031/viewer/2022013021/5ec980d8673f5a76c75dcf07/html5/thumbnails/37.jpg)
©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](https://reader031.fdocuments.in/reader031/viewer/2022013021/5ec980d8673f5a76c75dcf07/html5/thumbnails/38.jpg)
©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](https://reader031.fdocuments.in/reader031/viewer/2022013021/5ec980d8673f5a76c75dcf07/html5/thumbnails/39.jpg)
©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](https://reader031.fdocuments.in/reader031/viewer/2022013021/5ec980d8673f5a76c75dcf07/html5/thumbnails/40.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022013021/5ec980d8673f5a76c75dcf07/html5/thumbnails/41.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022013021/5ec980d8673f5a76c75dcf07/html5/thumbnails/42.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022013021/5ec980d8673f5a76c75dcf07/html5/thumbnails/43.jpg)
©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](https://reader031.fdocuments.in/reader031/viewer/2022013021/5ec980d8673f5a76c75dcf07/html5/thumbnails/44.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022013021/5ec980d8673f5a76c75dcf07/html5/thumbnails/45.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022013021/5ec980d8673f5a76c75dcf07/html5/thumbnails/46.jpg)
©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](https://reader031.fdocuments.in/reader031/viewer/2022013021/5ec980d8673f5a76c75dcf07/html5/thumbnails/47.jpg)
©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](https://reader031.fdocuments.in/reader031/viewer/2022013021/5ec980d8673f5a76c75dcf07/html5/thumbnails/48.jpg)
©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](https://reader031.fdocuments.in/reader031/viewer/2022013021/5ec980d8673f5a76c75dcf07/html5/thumbnails/49.jpg)
References
▪Docker: docker.io ▪Kubernetes: kubernetes.io ▪Slides: https://github.com/javaee-samples/docker-java
48