Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and...

110
Google Cloud Training and Certification Containers and Kubernetes

Transcript of Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and...

Page 1: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Training and Certification

Containers and Kubernetes

Page 2: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Agenda Slide

01

02

03

Introduction to Containers

Kubernetes 101

Demo

Page 3: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Training and Certification

Vic Iglesias

Cloud Solutions Architect

Graduated UCSB, 2008

[email protected]

@vicnastea

Page 4: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Training and Certification

What is a Cloud Solutions Architect?

Solve Customer Problems

Publish SolutionsEvangelize

the Platform

Page 5: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Training and Certification

Introduction to Containers

Page 6: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Training and Certification

Application Containers are changing the way people deploy and run applications

Photo by steve gibson from Airlie Beach, Australia (shipping containers) [CC BY 2.0 (http://creativecommons.org/licenses/by/2.0)], via Wikimedia Commons

Google Cloud Training and Certification

Page 7: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Training and Certification

Dedicated server

Kernel

Dependencies

Application Code

Hardware

Deployment ~monthsLow utilizationNot portable

Page 8: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Training and Certification

Virtual machine

Kernel

Dependencies

Application Code

Hardware + hypervisor

Dedicated server

Kernel

Dependencies

Application Code

Hardware

Deployment ~monthsLow utilizationNot portable

Deployment ~days (mins)Improved utilizationHypervisor specific

Page 9: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Training and Certification

Virtual machine

Kernel

Dependencies

Application Code

Hardware + hypervisor

Dedicated server

Kernel

Dependencies

Application Code

Hardware

Deployment ~monthsLow utilizationNot portable

Deployment ~days (mins)Hypervisor specific

Low isolation, Tied to OS

Application Code

Page 10: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Training and Certification

Virtual machine

Kernel

Dependencies

Hardware + hypervisor

Dedicated server

Kernel

Dependencies

Application Code

Hardware

Deployment ~monthsNot portable

Low utilization

Deployment ~days (mins)Hypervisor specific

Low isolation, Tied to OS

Virtual machine

Kernel

Dependencies

Application Code

Deployment ~days (mins)Hypervisor specific

Redundant OS

Application Code

Page 11: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Training and Certification

Virtual machine

Kernel

Dependencies

Application Code

Hardware + hypervisor

Dedicated server

Kernel

Dependencies

Application Code

Hardware

Container

Kernel +Container Runtime

Dependencies

Application Code

Hardware

Deployment ~mins (sec)Portable

Very Efficient

Deployment ~monthsNot portable

Low utilization

Deployment ~days (mins)Hypervisor specific

Low isolation, Tied to OS

Page 12: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem

Proprietary + Confidential

OS Virtualization Building Blocks

Process Security

Process Isolation

Page 13: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem

Proprietary + Confidential

OS Virtualization Building Blocks

Access Control

Capabilities

Control Groups

Namespaces

Page 14: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem

Proprietary + Confidential

Namespaces

Timeline by month

1. Replace body text by either typing directly into table boxes or copy and paste content in from other source

● Limit what a process can see

● Types

○ Net

○ Pid

○ IPC

○ Mount

○ and more...

Namespaces

Page 15: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem

Proprietary + Confidential

Control Groups

Timeline by month

1. Replace body text by either typing directly into table boxes or copy and paste content in from other source

● Limit the resources that a process can use

● Types

○ Memory

○ CPU

○ Network

○ Block I/O

○ and more...Control Groups

Page 16: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem

Proprietary + Confidential

Root Capabilities

Timeline by month

1. Replace body text by either typing directly into table boxes or copy and paste content in from other source

● Limits the things a process can do

● Granular permissions between a what a “regular user” and

root can do.

● Types

○ CAP_CHOWN

○ CAP_NET_ADMIN

○ CAP_SYS_TIME

○ CAP_SYS_BOOT

○ and more...

Capabilities

Page 17: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem

Proprietary + Confidential

Access Control

Timeline by month

1. Replace body text by either typing directly into table boxes or copy and paste content in from other source

● Fine grained controls over what processes can access on

a system

● Examples

○ Process X can open a socket on port 8888

○ Process Y can read from file /var/log/syslog

● Implementations

○ SELinux

○ AppArmor

○ and more...

Access Control

Page 18: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem

Proprietary + Confidential

Linux Container Technology Timeline

Timeline by month

1. Replace body text by either typing directly into table boxes or copy and paste content in from other source

1998 1999 2001 2002 2006 2008 2009 2013 2014

Capabilities

SELinux AppArmor

Namespaces

Source: https://www.nccgroup.trust/globalassets/our-research/us/whitepapers/2016/april/ncc_group_understanding_hardening_linux_containers-10pdf

ControlGroups

LXC

KubernetesApacheMesos

Docker

Page 19: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Training and Certification

Why Developers Care?● “Separation of code and compute”

○ Consistency across dev, test, and production○ Consistency across bare-metal, VMs, and

cloud○ No more “it worked on my computer”

● Packaged applications○ Agile application creation and deployment○ Continuous Integration/Delivery

● A path to microservices○ Introspectable○ Isolated/loosely coupled, distributed, and

elastic

Container

Kernel

Dependencies

Application Code

Hardware

Container

Dependencies

Application Code

Page 20: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Source: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis non erat sem

Proprietary + Confidential

So… What is Docker?

Timeline by month

1. Replace body text by either typing directly into table boxes or copy and paste content in from other source

● Polished user interface to create Linux containers

● Layered image format for portability and speed and

deployment

● Configuration file for creating portable images

● API for exposing

○ Container management operations

○ Container metrics

○ Available images

Page 21: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Training and Certification

Introduction to Docker

Page 22: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Training and Certification

import tornado.ioloopimport tornado.webimport socketclass MainHandler(tornado.web.RequestHandler): def get(self): self.write("Hostname: " + socket.gethostname())def make_app(): return tornado.web.Application([ (r"/", MainHandler), ])if __name__ == "__main__": app = make_app() app.listen(8888) tornado.ioloop.IOLoop.current().start()

web-server.py

$> python web-server.py

Page 23: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Training and Certification

Dockerfile

$ docker build -t py-web-server .

$ docker run -d py-web-server

You can also do stuff like:

$ docker images$ docker ps$ docker logs <container id>$ docker stop py-web-server

FROM library/python:3.6.0-alpineRUN pip install tornadoADD web-server.py /web-server.pyCMD ["python", "/web-server.py"]

Page 24: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Training and Certification

Build Container Image

● Build a container image with docker and push the image up to GCR (Google Container Registry)

docker build \-t gcr.io/$PROJECT_ID/py-web-server:v1 .

gcloud docker -- push \gcr.io/$PROJECT_ID/py-web-server:v1

docker run -d -p 8080:8080 \--name py-web-server \gcr.io/$PROJECT_ID/py-web-server:v1

Page 25: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Training and Certification

ubuntu:16.04

c22013c84729

d74508fb6632

91e54dfb1179

d3a1f33e8a5a

194.5 KB

1.895 KB

0 B

188.1 MB

Container layerThin R/W layer

Base Image layers (R/O)

Example container(based on ubuntu:16.04 image)

Page 26: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Containers are the new package format

● Bundle your app with its dependencies

● Ship your application reliably

● Only update the parts that change

● Run it across infrastructures○ Bare metal○ Public Cloud○ Private Cloud

Page 27: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Training and Certification

Kubernetes 101

Page 28: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Training and Certification

Introduction to Kubernetes

Page 29: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Platform

kubelet

UI

kubelet CLI

API

users master nodes

The 10000 foot view

etcd

kubelet

scheduler

controllers

apiserver

Page 30: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Platform

UI

All users really care about

APIContainer

Cluster

Page 31: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

cluster

Page 32: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

clustervirtual

machines that Kubernetes

manages

Page 33: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

clusternodemaster node node

Page 34: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

clusternodemaster node node

node node node

node node node

node node node

node node node

node node node

node node nodemaster

master

Page 35: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

pod

Page 36: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

podgroup of

containers sharing storage

and network

Page 37: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

podcontainer container container

volume A volume B

network interface

Page 38: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

pod.yaml

apiVersion: v1kind: Podmetadata: name: my-appspec: containers: - name: my-app image: my-app - name: nginx-ssl image: nginx ports: - containerPort: 80 - containerPort: 443

Page 39: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

pod.yamlnodemaster node node

Page 40: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

pod.yamlnodemaster node node

Page 41: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

pod.yamlnodemaster node node

Page 42: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Deployment

Page 43: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Deploymentensure N pods are running

Page 44: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

app.yaml

kind: DeploymentapiVersion: v1beta1metadata: name: frontendspec: replicas: 4 selector: role: web template: metadata: name: web labels: role: web spec: containers:

- name: my-app image: my-app - name: nginx-ssl image: nginx ports: - containerPort: 80 - containerPort: 443

Page 45: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

app.yaml

kind: DeploymentapiVersion: v1beta1metadata: name: frontendspec: replicas: 4 selector: role: web template: metadata: name: web labels: role: web spec: containers:

- name: my-app image: my-app - name: nginx-ssl image: nginx ports: - containerPort: 80 - containerPort: 443

Page 46: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

app.yaml

kind: DeploymentapiVersion: v1beta1metadata: name: frontendspec: replicas: 4 selector: role: web template: metadata: name: web labels: role: web spec: containers:

- name: my-app image: my-app - name: nginx-ssl image: nginx ports: - containerPort: 80 - containerPort: 443

Page 47: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

app.yaml

kind: DeploymentapiVersion: v1beta1metadata: name: frontendspec: replicas: 4 selector: role: web template: metadata: name: web labels: role: web spec: containers:

- name: my-app image: my-app - name: nginx-ssl image: nginx ports: - containerPort: 80 - containerPort: 443

Page 48: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

app.yamlnodemaster node node

Page 49: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

app.yamlnodemaster node node

Page 50: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

app.yamlnodemaster node node

Page 51: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Proprietary + ConfidentialProprietary + Confidential

Proprietary + Confidential

How do podscommunicate witheach other?

Page 52: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

service

Page 53: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

serviceabstraction to communicate

with pods

Page 54: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

servicemaster

service

Page 55: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

servicemaster

service

Page 56: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

servicemaster

service

service

Page 57: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

servicemaster

service

public load balancer

service

Page 58: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

svc.yaml

kind: ServiceapiVersion: v1metadata: name: web-frontendspec: ports: - name: http port: 80 targetPort: 80 protocol: TCP selector: role: web type: LoadBalancer

Page 59: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

svc.yaml

kind: ServiceapiVersion: v1metadata: name: web-frontendspec: ports: - name: http port: 80 targetPort: 80 protocol: TCP selector: role: web type: LoadBalancer

Page 60: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

svc.yaml

kind: ServiceapiVersion: v1metadata: name: web-frontendspec: ports: - name: http port: 80 targetPort: 80 protocol: TCP selector: role: web type: LoadBalancer

Page 61: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Platform

Labels & Selectors

Page 62: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Platform

Arbitrary metadata

Attached to any API object

Generally represent identity

Queryable by selectors• think SQL ‘select ... where ...’

The only grouping mechanism• pods under a ReplicationController• pods in a Service• capabilities of a node (constraints)

Labels

Page 63: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Platform

App: MyApp

Phase: prod

Role: FE

App: MyApp

Phase: test

Role: FE

App: MyApp

Phase: prod

Role: BE

App: MyApp

Phase: test

Role: BE

Selectors

Page 64: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Platform

App: MyApp

Phase: prod

Role: FE

App: MyApp

Phase: test

Role: FE

App: MyApp

Phase: prod

Role: BE

App: MyApp

Phase: test

Role: BE

App = MyApp

Selectors

Page 65: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Platform

App: MyApp

Phase: prod

Role: FE

App: MyApp

Phase: test

Role: FE

App: MyApp

Phase: prod

Role: BE

App: MyApp

Phase: test

Role: BE

App = MyApp, Role = FE

Selectors

Page 66: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Platform

App: MyApp

Phase: prod

Role: FE

App: MyApp

Phase: test

Role: FE

App: MyApp

Phase: prod

Role: BE

App: MyApp

Phase: test

Role: BE

App = MyApp, Role = BE

Selectors

Page 67: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Platform

App: MyApp

Phase: prod

Role: FE

App: MyApp

Phase: test

Role: FE

App: MyApp

Phase: prod

Role: BE

App: MyApp

Phase: test

Role: BE

App = MyApp, Phase = prod

Selectors

Page 68: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Platform

App: MyApp

Phase: prod

Role: FE

App: MyApp

Phase: test

Role: FE

App: MyApp

Phase: prod

Role: BE

App: MyApp

Phase: test

Role: BE

App = MyApp, Phase = test

Selectors

Page 69: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Training and Certification

Monitoring & Health Checking

Page 70: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Training and Certification

Monitoring & Health Checks (1 of 8)

Node

Kubelet PodPodapp v1

Page 71: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Training and Certification

Hey, app v1... You alive?

Node

Kubelet Podapp v1app v1

Monitoring & Health Checks (2 of 8)

Page 72: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Training and Certification

Node

Kubelet Nope!Pod

app v1app v1

Monitoring & Health Checks (3 of 8)

Page 73: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Training and Certification

OK, then I’m going to restart you...

Node

Kubelet Podapp v1app v1

Monitoring & Health Checks (4 of 8)

Page 74: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Training and Certification

Node

Kubelet Pod

Monitoring & Health Checks (5 of 8)

Page 75: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Training and Certification

Node

Kubelet Podapp v1

Monitoring & Health Checks (6 of 8)

Page 76: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Training and Certification

Node

Kubelet

Hey, app v1...You alive?

Podapp v1

Monitoring & Health Checks (7 of 8)

Page 77: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Training and Certification

Node

Kubelet Yes!Pod

app v1

Monitoring & Health Checks (8 of 8)

Page 78: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Training and Certification

Configuration & Volumes

Page 79: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Training and Certification

Volumes

Page 80: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Training and Certification

Volumes (1 of 3)

Kubernetes Master

etcdAPI

Server

Node

Kubeletvolume

$ kubectl create secret generic tls-certs --from-file=tls/

volume

Page 81: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Training and Certification

$ kubectl create -f pods/secure-monolith.yaml

Kubernetes Master

etcdAPI

Server

Node

Kubeletpod

volume

Volumes (2 of 3)

Page 82: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Training and Certification

Kubernetes Master

etcdAPI

Server

Node

KubeletAPI

Server

Node

Kubelet Pod

Pod

/mnt/vol

nginx

10.10.1.100

volume

NFS/iSCSI

Volumes (3 of 3)

Page 83: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Training and Certification

ConfigMaps

Page 84: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Training and Certification

ConfigMaps (1 of 3)

Kubernetes Master

etcdAPI

Server

Node

Kubeletconfigmap

$ kubectl create configmap my-configmap --from-file=config.conf

Page 85: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Training and Certification

$ kubectl create -f pods/mypod.yaml

Kubernetes Master

etcdAPI

Server

Node

Kubeletpod

ConfigMaps (2 of 3)

Page 86: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Training and Certification

Kubernetes Master

etcdAPI

Server

Node

KubeletAPI

Server

Node

Kubelet Pod

Pod

/etc/conf

nginx

10.10.1.100

configmap

ConfigMaps (3 of 3)

Page 87: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Training and Certification

Deploying to Kubernetes

Page 88: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Training and Certification

Introduction to Deployments

Page 89: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Training and Certification

Deployments

ReplicaSet- replicas: 3- selector:

- app: hello- version: 1.0.0

Deployment- name: hello

Pod- containers:

- name: hello- image: hello

Page 90: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Training and Certification

observe

diff

act

Deployments

Page 91: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Training and Certification

Deployments

ReplicaSet- replicas: 4- selector:

- app: hello- version: 1.0.0

Deployment- name: hello

Pod- containers:

- name: hello- image: hello

Page 92: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Training and Certification

Deployments

ReplicaSet- replicas: 3- selector:

- app: hello- version: 1.0.0

Deployment- name: hello

Pod- containers:

- name: hello- image: hello

Page 93: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Training and Certification

Deployments

ReplicaSet- replicas: 3- selector:

- app: hello- version: 1.0.0

Deployment- name: hello

Pod- containers:

- name: hello- image: hello

Page 94: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Training and Certification

Rolling Updates

Page 95: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Training and Certification

Rolling Updates(1 of 8)

kubectl apply ...

ReplicaSet- replicas: 3- selector:

- app: hello- version: 1.0.0

Deployment- name: hello

Page 96: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Training and Certification

ReplicaSet- replicas: 3- selector:

- app: hello- version: 1.0.0

ReplicaSet- replicas: 0- selector:

- app: hello- version: 2.0.0

Deployment- name: hello

Rolling Updates(2 of 8)

Page 97: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Training and Certification

ReplicaSet- replicas: 3- selector:

- app: hello- version: 1.0.0

ReplicaSet- replicas: 1- selector:

- app: hello- version: 2.0.0

Deployment- name: hello

Rolling Updates(3 of 8)

Page 98: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Training and Certification

ReplicaSet- replicas: 2- selector:

- app: hello- version: 1.0.0

ReplicaSet- replicas: 1- selector:

- app: hello- version: 2.0.0

Deployment- name: hello

Rolling Updates(4 of 8)

Page 99: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Training and Certification

ReplicaSet- replicas: 2- selector:

- app: hello- version: 1.0.0

ReplicaSet- replicas: 2- selector:

- app: hello- version: 2.0.0

Deployment- name: hello

Rolling Updates(5 of 8)

Page 100: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Training and Certification

ReplicaSet- replicas: 1- selector:

- app: hello- version: 1.0.0

ReplicaSet- replicas: 2- selector:

- app: hello- version: 2.0.0

Deployment- name: hello

Rolling Updates(6 of 8)

Page 101: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Training and Certification

ReplicaSet- replicas: 1- selector:

- app: hello- version: 1.0.0

ReplicaSet- replicas: 3- selector:

- app: hello- version: 2.0.0

Deployment- name: hello

Rolling Updates(7 of 8)

Page 102: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Training and Certification

ReplicaSet- replicas: 0- selector:

- app: hello- version: 1.0.0

ReplicaSet- replicas: 3- selector:

- app: hello- version: 2.0.0

Deployment- name: hello

Rolling Updates(8 of 8)

Page 103: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Training and Certification

Canary Deployments

Page 104: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Training and Certification

Canary Deployments(1 of 2)

Deployment- app: hello

Service- app: hello

Page 105: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Training and Certification

Deployment- app: hello

Service- app: hello

Deployment- app: hello- track: canary

Canary Deployments(2 of 2)

Page 106: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Training and Certification

Blue-Green Deployments

Page 107: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Training and Certification

Blue-GreenDeployments(1 of 4)

Service- app: hello- version: 1.0.0

Deployment- version: 1.0.0

Page 108: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Training and Certification

Deployment- version: 2.0.0

Deployment- version: 1.0.0

Service- app: hello- version: 1.0.0

Blue-GreenDeployments(2 of 4)

Page 109: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Training and Certification

Deployment- version: 2.0.0

Deployment- version: 1.0.0

Service- app: hello- version: 1.0.0

Blue-GreenDeployments(3 of 4)

Page 110: Containers and Kubernetes - GaeBlogX...Kubernetes Apache Mesos Docker Google Cloud Training and Certification Why Developers Care? “Separation of code and compute” Consistency

Google Cloud Training and Certification

Deployment- version: 2.0.0

Deployment- version: 1.0.0

Service- app: hello- version: 2.0.0

Blue-GreenDeployments(4 of 4)