1 of 29

Kubernetes

CIS 1912

2 of 29

HW1 Recap

3 of 29

Docker/Docker Compose

Recap

4 of 29

Docker

Recap

docker run

Container

Task app

Running on port 80

Local Machine

5 of 29

Docker

Recap

docker run -p 80:80

Container

Task app

Running on port 80

Local Machine

6 of 29

Docker

Recap

docker run -p 80:8000

Container

Task app

Running on port 80

Local Machine

7 of 29

Docker

Recap

docker run -p 8000:80

Container

Task app

Running on port 80

Local Machine

8 of 29

Docker Compose

Recap

services:

web:

Image: web:v1

command: poetry run uvicorn main:app --host 0.0.0.0

--port _____

ports:

- "_____:_____"

depends_on:

- redis

redis:

image: redis:latest

command: ["redis-server", "--appendonly", "yes"]

9 of 29

Docker Compose → k8s

Clustering Wishlist

  • Declarative
  • API-Driven
  • Open-source
  • Community
  • Technically solid
    • Horizontal scaling
    • High Availability
    • Networking
    • Observability

10 of 29

What is Kubernetes?

  • Tool for orchestrating containers (Docker in our case)
  • Takes us from local development to production

11 of 29

Pods

  • Base unit of work
  • Each has an IP address
  • Almost always 1 to 1 with container (like Pod 1)
  • Can be labeled for later querying
  • What happens if pod errors or fails?

12 of 29

Pods

apiVersion: v1

kind: Pod

metadata:

name: static-web

labels:

app: nginx

release: stable

spec:

containers:

- name: web

image: nginx:1.21.6

ports:

- name: web

containerPort: 80

protocol: TCP

13 of 29

Nodes

  • Hosts for pods
  • VMs, your laptop, physical servers
  • Main/Master & Worker nodes

14 of 29

Deployments

  • Group of Pods
  • Grouped by label

15 of 29

Deployments

apiVersion: apps/v1

kind: Deployment

metadata:

name: nginx-deployment

spec:

selector:

matchLabels:

app: nginx

replicas: 2 # pod count

template:

metadata:

labels:

app: nginx

spec:

containers:

- name: nginx

image: nginx:1.14.2

ports:

- containerPort: 80

16 of 29

Deployments

apiVersion: apps/v1

kind: Deployment

metadata:

name: nginx-deployment

spec:

selector:

matchLabels:

app: nginx

replicas: 2 # pod count

template:

metadata:

labels:

app: nginx

spec:

containers:

- name: nginx

image: nginx:1.14.2

ports:

- containerPort: 80

If we define a deployment,

do we need to define pods?

17 of 29

Services

  • Network pods together
  • Grouped by label

18 of 29

Services

apiVersion: v1

kind: Service

metadata:

name: my-service

spec:

selector:

app: nginx

ports:

- protocol: TCP

port: 80

targetPort: 9376

19 of 29

https://dev.to/lovestaco/6-kubernetes-ports-a-definitive-look-expose-nodeport-targetport-more-2enc

20 of 29

Kubernetes Demo (github.com/cis1912/kube-demo)

21 of 29

Cattle not Pets

22 of 29

k8s in practice

…unless you h8 k8s

✨Extra Info✨

23 of 29

Microservice

apiVersion: v1

kind: Service

metadata:

name: micro-service

spec:

selector:

app: MyApp

ports:

- protocol: TCP

port: 80

targetPort: 9376

24 of 29

Microservice

25 of 29

Microservice

  • One task at a time
  • Stateless
  • Scales separately from other services
  • Communication is key

26 of 29

Microservice

27 of 29

Fin

  • HW1 due next week!
  • Come to office hours!

28 of 29

Fin

  • Lab 2: Local Kubernetes will be out tonight!
  • Come to office hours!

29 of 29

Credits