Kubernetes
Greekfor“Helmsman”;alsotherootofthewords“governor”and “cybernetic”
• Runsandmanagescontainers• InspiredandinformedbyGoogle’sexperiencesand
internalsystems• Supportsmultiplecloudandbare-metal
environments• Supportsmultiplecontainerruntimes• 100%Opensource,writteninGo
Manageapplications,notmachines
Everything atGooglerunsincontainers:
• Gmail,WebSearch,Maps,...• MapReduce,batch,...• GFS,Colossus,...• EvenGoogle’sCloudPlatform: VMsrunincontainers!
Googlelaunchover2billioncontainersperweek
Start with a Cluster
• Laptop tohigh-availabilitymulti-nodecluster• Hosted orselfmanaged• On-Premise orCloud• BareMetal orVirtualMachines• MostOSes(inc. RedHat Atomic,Fedora,CentOS)• OrjustabunchofRaspberryPis• Manyoptions,SeeMatrixfordetails
Kubernetes Cluster Matrix: http://bit.ly/1MmhpMW
etcd
scheduler
controller-manager
apiserver
kubelet docker kube-proxy iptables
1. UsersendsPodrequesttoAPIserver
2. APIserversavespodinfotoetcd(unscheduled)
3. Schedulerfindsunscheduledpodandschedulesittonode.
4. Kubelet seespodscheduledtoitandtellsdocker torunthecontainer.
5. Dockerrunsthecontainer.
1
2
5
3
4
Theatomofschedulingforcontainers
Representsanapplicationspecificlogicalhost
Hostscontainers andvolumes
Eachhasitsownroutable(noNAT)IPaddress
Ephemeral• Podsarefunctionallyidenticalandtherefore
ephemeralandreplaceablePod
WebServer
Volume
Consumers
A pod of whales containers
Pods
Pod
GitSynchronizer
Node.jsAppContainer
Volume
ConsumersgitRepoCanbeusedtogroupmultiplecontainers&sharedvolumes
Containerswithinapodare tightly coupled
Sharednamespaces• ContainersinapodshareIP,portandIPC
namespaces• Containersinapodtalktoeachotherthrough
localhost
Pod Networking (across nodes)PodshaveIPswhichareroutable
PodscanreacheachotherwithoutNAT
Evenacrossnodes
NoBrokeringofPortNumbers
Thesearefundamentalrequirements
Manysolutions
Flannel,Weave,OpenVSwitch,Cloud Provider
10.1.2.0/24
10.1.1.0/24
10.1.1.211 10.1.1.2
10.1.2.106
10.1.3.0/24
10.1.3.4510.1.3.17
10.1.3.0/24
Client
Pod
Container
Pod
Container
Pod
ContainerContainer
Alogicalgroupingofpodsthatperformthesamefunction• groupedbylabelselector
Loadbalancesincomingrequestsacrossconstituentpods
Choiceofpodisrandombutsupportssessionaffinity(ClientIP)
Getsastable virtualIPandport• alsoaDNSnametype =FE
Services
Service
Labelselector:type=FE
VIP
type=FE type=FE type=FE
Pod Pod
frontend
Pod
frontend
Pod Pod
type=FE
version=v2
type=FE version=v2
● Metadatawithsemanticmeaning
● Membershipidentifier
● TheonlyGroupingMechanism
Behavior Benefits➔ Allowforintentofmanyusers(e.g.dashboards)
➔ Buildhigherlevelsystems…
➔ QueryablebySelectors
Labels
Dashboard
selector:type=FE
Dashboard
selector:version=v2
ReplicationController Pod Pod
frontend
Pod
frontend
Pod Pod
ReplicationController
#pods=1version=v2
show:version=v2
version=v1 version=v1 version=v2
ReplicationController
#pods=2version=v1
show:version=v2Behavior Benefits
● KeepsPodsrunning
● GivesdirectcontrolofPods
● GroupedbyLabelSelector
➔ RecreatesPods,maintainsdesiredstate
➔ Fine-grainedcontrolforscaling
➔ Standardgroupingsemantics
Replication Controllers
Replication ControllersReplicationController
ReplicationController- Name=“backend”- Selector={“name”:“backend”}- Template={...}- NumReplicas=4
APIServer
3
Start1more
OK 4
Howmany?
Howmany?
Canonicalexampleofcontrolloops
Haveonejob:ensureNcopiesofapod• iftoofew,startnewones• iftoomany,killsome• group==selector
Replicatedpodsarefungible• Noimpliedorderoridentity
Pod Pod
frontend
Pod
frontend
Pod Pod
type=FE
version=v2
type=FE version=v2
● Metadatawithsemanticmeaning
● Membershipidentifier
● TheonlyGroupingMechanism
Behavior Benefits➔ Allowforintentofmanyusers(e.g.dashboards)
➔ Buildhigherlevelsystems…
➔ QueryablebySelectors
Labels
Dashboard
selector:type=FE
Dashboard
selector:version=v2
Deployment
RS
RS
Pod Pod Pod
env: test env: test env: test
Pod
env: testversion: v2 version: v2 version: v2 version: v2
Reliablemechanismforcreating,updatingandmanagingPods
Deploymentmanagesreplicachanges,includingrollingupdatesandscaling
EditDeploymentconfigurationsinplacewithkubectledit orkubectlapply
Managedrolloutsandrollbacks
Status:BETAinKubernetesv1.2
Deployments:UpdatesasaService
...
Pod Pod
frontend
Pod
frontend
Pod Pod
env=qa env=test
● env= prod
● tier!= backend
● env= prod,tier!=backend
Expressions● envin (test,qa)
● releasenotin (stable,beta)
● tier
● !tier
Generalized Labels (1.2)
env=prod
Pod
env=prod
Dashboard
selector:env=notin(prod)
ReplicationController Pod Pod
frontend
Pod
frontend
Pod Pod
app=demo app=demo app=demo
ReplicaSet
#pods=3app=democolorin(blue,grey)show:version=v2
SimilartoReplicationControllerbutsupportsgeneralizedSelectors
ReplicaSets(1.2)
selector:matchLabels:app:demomatchExpressions:- {key:color,operator:In,values:[blue,grey]}
color=blue color=blue color=grey
Rolling Update
kubectlrolling-update
API
kubectlrolling-update
Createfrontend-rc-v2
kubectlrolling-update
Createfrontend-rc-v2
Scalefrontend-rc-v2upto1
kubectlrolling-update
Createfrontend-rc-v2
Scalefrontend-rc-v2upto1
Scalefrontend-rc-v1downto1
kubectlrolling-update
Createfrontend-rc-v2
Scalefrontend-rc-v2upto1
Scalefrontend-rc-v1downto1
Scalefrontend-rc-v2upto2
kubectlrolling-update
Createfrontend-rc-v2
Scalefrontend-rc-v2upto1
Scalefrontend-rc-v1downto1
Scalefrontend-rc-v2upto2
Scalefrontend-rc-v1downto0
kubectlrolling-update
Scalefrontend-rc-v2upto1
Scalefrontend-rc-v1downto1
Scalefrontend-rc-v2upto2
Scalefrontend-rc-v1downto0
Deletefrontend-rc-v1 Pod Pod
frontend
Pod
version=v1version=v2version=v1
RCversion= v1type= BE#pods=2
show:version=v2
type=BE type=BE
RCversion= v2type= BE#pods=0
show:version=v2
Pod
version=v2
type=BE
kubectl rolling-updateisimperative,client-side
RCversion= v1type= BE#pods=2
show:version=v2
RCversion= v1type= BE#pods=1
show:version=v2
RCversion= v1type= BE#pods=0
show:version=v2
RCversion= v2type= BE#pods=1
show:version=v2
RCversion= v2type= BE#pods=2
show:version=v2
be-svc
Rollout
API
DeploymentDeployment
Createfrontend-1234567
Deployment
Createfrontend-1234567
Scalefrontend-1234567upto1
Deployment
Createfrontend-1234567
Scalefrontend-1234567upto1
Scalefrontend-7654321downto0
Pod Pod
frontend
Pod
version=v1
ReplicaSet
frontend-1234567version= v2type= BE#pods=0
show:version=v2
ReplicaSet
frontend-7654321version= v1type= BE#pods=2
version:v2
ReplicaSet
frontend-7654321version:v1type:BE#pods=0
version:v1
ReplicaSet
frontend-1234567version= v2type= BE#pods=1
show:version=v2
ReplicaSet
frontend-1234567version:v2type:BE#pods=2
type=BE type=BE
Pod
version:v2
type=BE
Servicebe-svc
Deployment
Createfrontend-1234567
Scalefrontend-1234567upto1
Scalefrontend-7654321downto0
Scalefrontend-1234567upto2
kubectleditdeployment...