SlideShare a Scribd company logo
Container Deployment and
Management
with kubernetes
1 July 2015
Loh Siu Yin
Technology Consultant, Beyond Broadcast LLP
1 of 27
Kubernetes
A system to manage docker containers across a cluster of hosts.
See: kubernetes.io(http://kubernetes.io)
and github.com/GoogleCloudPlatform/kubernetes(https://github.com/GoogleCloudPlatform/kubernetes)
2 of 27
Prerequisites
Docker (boot2docker, coreos, static binary)
Images (from hub.docker.com or build your own)
kubernetes
3 of 27
Docker Essentials
4 of 27
Docker Overview
5 of 27
Build a base image
Dockerfile for gozmq: A standardized environment my golang and ZeroMQ programs
to run in.
# Dockerfile for gozmq
FROM ubuntu:14.04
ADD libzmq.so.1 /usr/lib/
CMD ["/bin/bash"]
Building the image:
#!/bin/sh
# image_build.sh
PGM='gozmq'
MAIN_VER=20150525
#MAIN_VER=`date +%Y%m%d`
SUB_VER=
VER=${MAIN_VER}${SUB_VER}
docker build -t siuyin/${PGM}:${VER} .
Check with: docker images | grep gozmq
6 of 27
Build application image: master-publisher
The publisher in a pub-sub system.
# Dockerfile for publisher
FROM siuyin/gozmq:20150525
ENV PULL_BIND_PORT='tcp://*:5123'
ENV PUB_BIND_PORT='tcp://*:5124'
ADD publisher /usr/bin/
CMD ["/usr/bin/publisher"]
#!/bin/sh
# image_build for publisher
PGM='publisher'
#MAIN_VER=`date +%Y%m%d`
MAIN_VER=20150525
SUB_VER=
VER=${MAIN_VER}${SUB_VER}
docker build -t siuyin/${PGM}:${VER} .
Check with: docker images | grep publisher
7 of 27
Publisher
Demo:
cd ~/prog/go_workspace/src/siuyin/zmqcomp/publisher (vim start.sh)
test_pusher, publisher then test_subscriber
8 of 27
Nice: Fully functional but limited to running on the docker host
Note: localhost and port configuration via environment variables.
#!/bin/sh
# test_pusher
# local docker host
#PUSH_CONNECT_HOST=localhost PUSH_CONNECT_PORT=5123 go run main.go
# kubernetes cluster network 1
#PUSH_CONNECT_HOST=172.17.0.17 PUSH_CONNECT_PORT=5123 go run main.go
# kubernetes cluster network 2
PUSH_CONNECT_HOST=10.0.0.50 PUSH_CONNECT_PORT=5123 go run main.go
# kubernetes node local
#PUSH_CONNECT_HOST=localhost PUSH_CONNECT_PORT=30516 go run main.go
Enter kubernetes
Brendan Burns of Google: "kubernetes -- ancient greek for pilot"
I am thinking: The Borg Cube: "resistance is futile ... you will be assimilated"
9 of 27
Kubernetes
10 of 27
Kubernetes Overview
11 of 27
Kubernetes Survival Guide
12 of 27
Resources
pod:
One or more closely coupled docker containers
replication controller (or rc):
Actively manages pods
service (or svc):
A stable end-point to connect to running pods
node (previously minion):
A host that runs pods.
13 of 27
(Re)starting kubernetes
After a reboot, kubernetes containers from gcr.io/google ... will not be running.
Restart them with this script:
docker ps -a| grep gcr.io/google | awk '{print $1}'|xargs docker start
14 of 27
Kubernetes operations
get: retrieve summary status on a resource (pod, rc, svc, node)
describe: get more details on a resource (eg. describe svc master-publisher)
delete: deletes a resource
create: creates a resource
Demo: kubectl get nodes
kubernetes cluster api-controller runs on localhost:8080(http://localhost:8080)
Possible to curl to localhost:8080 with the api:
curl -L http://localhost:8080/api/v1beta3/nodes
or with GET requests on your browser localhost:8080/api/v1beta3/nodes(http://localhost:8080
/api/v1beta3/nodes)
15 of 27
Creating a ReplicationController which creates pods
Defined in a .json or .yaml file:
"containers": [{
"name": "publisher",
"image": "siuyin/publisher:20150525",
"imagePullPolicy": "IfNotPresent",
"env": [{
"name": "PULL_BIND_PORT",
"value": "5123"
},{
"name": "PUB_BIND_PORT",
"value": "5124"
}],
"ports": [{
"containerPort": 5123,
"protocol": "TCP"
},
{
"containerPort": 5124,
"protocol": "TCP"
}
]
}],
"restartPolicy": "Always",
"volumes": []
16 of 27
publisher-controller.json
view ~/prog/go_workspace/src/siuyin/zmqcomp/publisher/publisher-controller.json
17 of 27
Demo: Create a replication controller
Note: kubectl delete rc -l name=master-publisher before re-creating replication
controller.
Demo:
cd ~/prog/go_workspace/src/siuyin/zmqcomp/publisher
kubectl create -f publisher-controller.json
kubectl get rc
Same effect with: kubectl get replicationcontrollers
Online scaling:
kubectl scale --replicas=3 rc master-publisher
18 of 27
Where is the pod?
Demo:
kubectl get pods
or better
kubectl get pods -l 'name=master-publisher'
Same as: kubectl get pods --selector='name=master-publisher'
Note the IP Address of this pod.
19 of 27
Pod IP address
Double-check: docker ps | grep master-publisher
Also: docker inspect <container UUID> | grep IPAddress
But where is the IP address in the docker container?
The network configuration is held in the "pause" container.
Demo: master-publisher pod running in dedicated sub-net
cd ~/prog/go_workspace/src/siuyin/zmqcomp/publisher
copy pod IP address to clipboard
configure and start test_pusher
configure and start test_subscriber
20 of 27
Scenario: Container or Pod failure
Suppose bad code or hardware causes the docker container or pod to fail.
Can kubernetes heal the system?
Demo: kill the docker container
docker ps | grep master-publisher
docker kill <container UUID>
Demo: delete the pod
kubectl get pod -l name=master-publisher
kubectl delete pod <pod-name>
or similarly:
kubectl delete pod -l name=master-publisher
21 of 27
How to survive a pod failure
The failed pod was re-created by the replication controller:
kubectl get pod -l name=master-publisher
note the pod's IP address
cat ~/prog/go_workspace/src/siuyin/zmqcomp/publisher/test_pusher/start.sh
The IP address changed!
Kubernetes made no attempt to revive the failed pod. Instead it created a new one and
gave it a new IP address.
22 of 27
We need a stable IP address!
Enter: kubernetes service
"kind":"Service",
"apiVersion":"v1beta3",
"metadata":{
"name":"master-publisher",
"labels":{
"name":"master-publisher"
}
},
"spec":{
view ~/prog/go_workspace/src/siuyin/zmqcomp/publisher/publisher-service.json
Note the NodePort type and port declarations.
23 of 27
Inspecting the service
I've already created the service with (don't create it again):
kubectl create -f publisher-service.json
Check it with:
kubectl get service -l name=master-publisher
kubectl describe svc master-publisher
Demo: reconfigure to use service IP address:
reconfigure test_pusher
reconfigure test_subscriber
Demo: fail the pod again
kubectl delete pod -l name=master-publisher
24 of 27
Making the service accessible from outside the cluster
Specify a publicIP in the service declaration and use it:
#!/bin/sh
# test_pusher
# local docker host
#PUSH_CONNECT_HOST=localhost PUSH_CONNECT_PORT=5123 go run main.go
# kubernetes cluster network 1
#PUSH_CONNECT_HOST=172.17.0.17 PUSH_CONNECT_PORT=5123 go run main.go
# kubernetes cluster network 2
PUSH_CONNECT_HOST=10.0.0.50 PUSH_CONNECT_PORT=5123 go run main.go
# kubernetes node local
#PUSH_CONNECT_HOST=localhost PUSH_CONNECT_PORT=30516 go run main.go
To define your own port map, refer to NODEPORT entries in:
iptables -t nat -S
25 of 27
Slides Download
http://www.slideshare.net/siuyin/siuyin-dockerkubernetes
26 of 27
Thank you
Loh Siu Yin
Technology Consultant, Beyond Broadcast LLP
siuyin@beyondbroadcast.com(mailto:siuyin@beyondbroadcast.com)
27 of 27

More Related Content

PDF
Why Go Lang?
PDF
Practical Docker for OpenStack (Juno Summit - May 15th, 2014)
PDF
[Open stack] heat + docker
PDF
From dev to prod: Kubernetes on AWS (short ver.)
PDF
How to debug the pod which is hard to debug (디버그 하기 어려운 POD 디버그 하기)
PDF
Docker for mere mortals
PDF
Cluster Networking with Docker
PDF
Containerize! Between Docker and Jube.
Why Go Lang?
Practical Docker for OpenStack (Juno Summit - May 15th, 2014)
[Open stack] heat + docker
From dev to prod: Kubernetes on AWS (short ver.)
How to debug the pod which is hard to debug (디버그 하기 어려운 POD 디버그 하기)
Docker for mere mortals
Cluster Networking with Docker
Containerize! Between Docker and Jube.

What's hot (20)

PPTX
GKE vs OpenStack Magnum
PDF
Rex gke-clustree
PDF
Using Kubernetes for Continuous Integration and Continuous Delivery
PDF
Very Early Review - Rocket(CoreOS)
PDF
Kubernetes Basis: Pods, Deployments, and Services
PDF
Kubernetes 101 and Fun
PDF
Docker as an every day work tool
PDF
Cantainer CI/ CD with Kubernetes
PPTX
Introduzione a GitHub Actions (beta)
PPTX
Docker-hanoi meetup #1: introduction about Docker
PDF
Kubernetes for Java developers
PDF
Kubernetes in 20 minutes - HDE Monthly Technical Session 24
PDF
Docker at Djangocon 2013 | Talk by Ken Cochrane
PPTX
Docker Warsaw Meetup 12/2017 - DockerCon 2017 Recap
PPTX
Django via Docker
PDF
Using Containers for Continuous Integration and Continuous Delivery. KubeCon ...
PDF
Using Docker with OpenStack - Hands On!
PDF
Docker 101 2015-05-28
PDF
Docker 활용법: dumpdocker
PDF
Docker by Example - Quiz
GKE vs OpenStack Magnum
Rex gke-clustree
Using Kubernetes for Continuous Integration and Continuous Delivery
Very Early Review - Rocket(CoreOS)
Kubernetes Basis: Pods, Deployments, and Services
Kubernetes 101 and Fun
Docker as an every day work tool
Cantainer CI/ CD with Kubernetes
Introduzione a GitHub Actions (beta)
Docker-hanoi meetup #1: introduction about Docker
Kubernetes for Java developers
Kubernetes in 20 minutes - HDE Monthly Technical Session 24
Docker at Djangocon 2013 | Talk by Ken Cochrane
Docker Warsaw Meetup 12/2017 - DockerCon 2017 Recap
Django via Docker
Using Containers for Continuous Integration and Continuous Delivery. KubeCon ...
Using Docker with OpenStack - Hands On!
Docker 101 2015-05-28
Docker 활용법: dumpdocker
Docker by Example - Quiz
Ad

Similar to Container Deployment and Management with kubernetes (20)

PPTX
Learn kubernetes in 90 minutes
PDF
Hands-On Introduction to Kubernetes at LISA17
PPTX
Pod Sandbox workflow creation from Dockershim
PDF
Docker, Kubernetes, and Google Cloud
PDF
Kubernetes Node Deep Dive
PPTX
Migrating GitHub Actions with Nested Virtualization to Cloud Native Ecosystem
PPTX
Migrating GitHub Actions with Nested Virtualization to Cloud Native Ecosystem...
PDF
Kubernetes - Sailing a Sea of Containers
PPTX
KuberneteSADASDSADASDASDASDASDASDAs Labs.pptx
PDF
Kubernetes
PDF
時代在變 Docker 要會:台北 Docker 一日入門篇
PDF
Présentation de Docker
PPTX
Java microservicesdockerdockerhubusecase2
PDF
Build Your Own CaaS (Container as a Service)
PDF
kubernetes_start_tutorial_by_ruben_tejero.pdf
PDF
手把手帶你學 Docker 入門篇
PDF
Docker workshop 0507 Taichung
PDF
Scaling docker with kubernetes
PPTX
Kubernetes Introduction
PPTX
K8s in 3h - Kubernetes Fundamentals Training
Learn kubernetes in 90 minutes
Hands-On Introduction to Kubernetes at LISA17
Pod Sandbox workflow creation from Dockershim
Docker, Kubernetes, and Google Cloud
Kubernetes Node Deep Dive
Migrating GitHub Actions with Nested Virtualization to Cloud Native Ecosystem
Migrating GitHub Actions with Nested Virtualization to Cloud Native Ecosystem...
Kubernetes - Sailing a Sea of Containers
KuberneteSADASDSADASDASDASDASDASDAs Labs.pptx
Kubernetes
時代在變 Docker 要會:台北 Docker 一日入門篇
Présentation de Docker
Java microservicesdockerdockerhubusecase2
Build Your Own CaaS (Container as a Service)
kubernetes_start_tutorial_by_ruben_tejero.pdf
手把手帶你學 Docker 入門篇
Docker workshop 0507 Taichung
Scaling docker with kubernetes
Kubernetes Introduction
K8s in 3h - Kubernetes Fundamentals Training
Ad

Recently uploaded (20)

PDF
Electronic commerce courselecture one. Pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Modernizing your data center with Dell and AMD
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Encapsulation theory and applications.pdf
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
Cloud computing and distributed systems.
PDF
KodekX | Application Modernization Development
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Empathic Computing: Creating Shared Understanding
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
Big Data Technologies - Introduction.pptx
PDF
NewMind AI Monthly Chronicles - July 2025
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
Electronic commerce courselecture one. Pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Modernizing your data center with Dell and AMD
Encapsulation_ Review paper, used for researhc scholars
Encapsulation theory and applications.pdf
MYSQL Presentation for SQL database connectivity
Cloud computing and distributed systems.
KodekX | Application Modernization Development
Spectral efficient network and resource selection model in 5G networks
Empathic Computing: Creating Shared Understanding
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Review of recent advances in non-invasive hemoglobin estimation
Big Data Technologies - Introduction.pptx
NewMind AI Monthly Chronicles - July 2025
The AUB Centre for AI in Media Proposal.docx
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Mobile App Security Testing_ A Comprehensive Guide.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
Advanced methodologies resolving dimensionality complications for autism neur...

Container Deployment and Management with kubernetes

  • 1. Container Deployment and Management with kubernetes 1 July 2015 Loh Siu Yin Technology Consultant, Beyond Broadcast LLP 1 of 27
  • 2. Kubernetes A system to manage docker containers across a cluster of hosts. See: kubernetes.io(http://kubernetes.io) and github.com/GoogleCloudPlatform/kubernetes(https://github.com/GoogleCloudPlatform/kubernetes) 2 of 27
  • 3. Prerequisites Docker (boot2docker, coreos, static binary) Images (from hub.docker.com or build your own) kubernetes 3 of 27
  • 6. Build a base image Dockerfile for gozmq: A standardized environment my golang and ZeroMQ programs to run in. # Dockerfile for gozmq FROM ubuntu:14.04 ADD libzmq.so.1 /usr/lib/ CMD ["/bin/bash"] Building the image: #!/bin/sh # image_build.sh PGM='gozmq' MAIN_VER=20150525 #MAIN_VER=`date +%Y%m%d` SUB_VER= VER=${MAIN_VER}${SUB_VER} docker build -t siuyin/${PGM}:${VER} . Check with: docker images | grep gozmq 6 of 27
  • 7. Build application image: master-publisher The publisher in a pub-sub system. # Dockerfile for publisher FROM siuyin/gozmq:20150525 ENV PULL_BIND_PORT='tcp://*:5123' ENV PUB_BIND_PORT='tcp://*:5124' ADD publisher /usr/bin/ CMD ["/usr/bin/publisher"] #!/bin/sh # image_build for publisher PGM='publisher' #MAIN_VER=`date +%Y%m%d` MAIN_VER=20150525 SUB_VER= VER=${MAIN_VER}${SUB_VER} docker build -t siuyin/${PGM}:${VER} . Check with: docker images | grep publisher 7 of 27
  • 8. Publisher Demo: cd ~/prog/go_workspace/src/siuyin/zmqcomp/publisher (vim start.sh) test_pusher, publisher then test_subscriber 8 of 27
  • 9. Nice: Fully functional but limited to running on the docker host Note: localhost and port configuration via environment variables. #!/bin/sh # test_pusher # local docker host #PUSH_CONNECT_HOST=localhost PUSH_CONNECT_PORT=5123 go run main.go # kubernetes cluster network 1 #PUSH_CONNECT_HOST=172.17.0.17 PUSH_CONNECT_PORT=5123 go run main.go # kubernetes cluster network 2 PUSH_CONNECT_HOST=10.0.0.50 PUSH_CONNECT_PORT=5123 go run main.go # kubernetes node local #PUSH_CONNECT_HOST=localhost PUSH_CONNECT_PORT=30516 go run main.go Enter kubernetes Brendan Burns of Google: "kubernetes -- ancient greek for pilot" I am thinking: The Borg Cube: "resistance is futile ... you will be assimilated" 9 of 27
  • 13. Resources pod: One or more closely coupled docker containers replication controller (or rc): Actively manages pods service (or svc): A stable end-point to connect to running pods node (previously minion): A host that runs pods. 13 of 27
  • 14. (Re)starting kubernetes After a reboot, kubernetes containers from gcr.io/google ... will not be running. Restart them with this script: docker ps -a| grep gcr.io/google | awk '{print $1}'|xargs docker start 14 of 27
  • 15. Kubernetes operations get: retrieve summary status on a resource (pod, rc, svc, node) describe: get more details on a resource (eg. describe svc master-publisher) delete: deletes a resource create: creates a resource Demo: kubectl get nodes kubernetes cluster api-controller runs on localhost:8080(http://localhost:8080) Possible to curl to localhost:8080 with the api: curl -L http://localhost:8080/api/v1beta3/nodes or with GET requests on your browser localhost:8080/api/v1beta3/nodes(http://localhost:8080 /api/v1beta3/nodes) 15 of 27
  • 16. Creating a ReplicationController which creates pods Defined in a .json or .yaml file: "containers": [{ "name": "publisher", "image": "siuyin/publisher:20150525", "imagePullPolicy": "IfNotPresent", "env": [{ "name": "PULL_BIND_PORT", "value": "5123" },{ "name": "PUB_BIND_PORT", "value": "5124" }], "ports": [{ "containerPort": 5123, "protocol": "TCP" }, { "containerPort": 5124, "protocol": "TCP" } ] }], "restartPolicy": "Always", "volumes": [] 16 of 27
  • 18. Demo: Create a replication controller Note: kubectl delete rc -l name=master-publisher before re-creating replication controller. Demo: cd ~/prog/go_workspace/src/siuyin/zmqcomp/publisher kubectl create -f publisher-controller.json kubectl get rc Same effect with: kubectl get replicationcontrollers Online scaling: kubectl scale --replicas=3 rc master-publisher 18 of 27
  • 19. Where is the pod? Demo: kubectl get pods or better kubectl get pods -l 'name=master-publisher' Same as: kubectl get pods --selector='name=master-publisher' Note the IP Address of this pod. 19 of 27
  • 20. Pod IP address Double-check: docker ps | grep master-publisher Also: docker inspect <container UUID> | grep IPAddress But where is the IP address in the docker container? The network configuration is held in the "pause" container. Demo: master-publisher pod running in dedicated sub-net cd ~/prog/go_workspace/src/siuyin/zmqcomp/publisher copy pod IP address to clipboard configure and start test_pusher configure and start test_subscriber 20 of 27
  • 21. Scenario: Container or Pod failure Suppose bad code or hardware causes the docker container or pod to fail. Can kubernetes heal the system? Demo: kill the docker container docker ps | grep master-publisher docker kill <container UUID> Demo: delete the pod kubectl get pod -l name=master-publisher kubectl delete pod <pod-name> or similarly: kubectl delete pod -l name=master-publisher 21 of 27
  • 22. How to survive a pod failure The failed pod was re-created by the replication controller: kubectl get pod -l name=master-publisher note the pod's IP address cat ~/prog/go_workspace/src/siuyin/zmqcomp/publisher/test_pusher/start.sh The IP address changed! Kubernetes made no attempt to revive the failed pod. Instead it created a new one and gave it a new IP address. 22 of 27
  • 23. We need a stable IP address! Enter: kubernetes service "kind":"Service", "apiVersion":"v1beta3", "metadata":{ "name":"master-publisher", "labels":{ "name":"master-publisher" } }, "spec":{ view ~/prog/go_workspace/src/siuyin/zmqcomp/publisher/publisher-service.json Note the NodePort type and port declarations. 23 of 27
  • 24. Inspecting the service I've already created the service with (don't create it again): kubectl create -f publisher-service.json Check it with: kubectl get service -l name=master-publisher kubectl describe svc master-publisher Demo: reconfigure to use service IP address: reconfigure test_pusher reconfigure test_subscriber Demo: fail the pod again kubectl delete pod -l name=master-publisher 24 of 27
  • 25. Making the service accessible from outside the cluster Specify a publicIP in the service declaration and use it: #!/bin/sh # test_pusher # local docker host #PUSH_CONNECT_HOST=localhost PUSH_CONNECT_PORT=5123 go run main.go # kubernetes cluster network 1 #PUSH_CONNECT_HOST=172.17.0.17 PUSH_CONNECT_PORT=5123 go run main.go # kubernetes cluster network 2 PUSH_CONNECT_HOST=10.0.0.50 PUSH_CONNECT_PORT=5123 go run main.go # kubernetes node local #PUSH_CONNECT_HOST=localhost PUSH_CONNECT_PORT=30516 go run main.go To define your own port map, refer to NODEPORT entries in: iptables -t nat -S 25 of 27
  • 27. Thank you Loh Siu Yin Technology Consultant, Beyond Broadcast LLP siuyin@beyondbroadcast.com(mailto:siuyin@beyondbroadcast.com) 27 of 27