container orchestration systems kubernetes

41
Container Orchestration Systems Kubernetes 2110415 Sofware-Defined Systems Asst. Prof. Natawut Nupairoj, Ph.D. Department of Computer Engineering Chulalongkorn University 2110415 Software-Defined Systems

Upload: others

Post on 16-Jan-2022

11 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Container Orchestration Systems Kubernetes

Container Orchestration SystemsKubernetes

2110415 Sofware-Defined SystemsAsst. Prof. Natawut Nupairoj, Ph.D.Department of Computer EngineeringChulalongkorn University

2110415 Software-Defined Systems

Page 2: Container Orchestration Systems Kubernetes

Overview

• Container enables the abilities to package, transfer, and run application code across many different environments

• The concept of Microservices further increases the flexibility of development and operation

• This also leads to dealing with large numbers of containers across multiple machines

2110415 Software-Defined Systems

Page 3: Container Orchestration Systems Kubernetes

Container Orchestration

• Container orchestration platforms make it easier to deploy, manager, and scale containerized applications in large clusters

2110415 Software-Defined Systems

Docker Swarm

Kubernetes

Apache Mesos

Page 4: Container Orchestration Systems Kubernetes

Kubernetes (K8s)

• Greek for "pilot" or "helmsman of a ship"• A Production-Grade Open-Sourced Container

Orchestrator by Google• Kubernetes distributions– For local installation: openshift, docker desktop,

minikube, rancher– In major cloud providers: GKE (Google), AKS

(Azure), EKS (AWS)

2110415 Software-Defined Systems

Page 5: Container Orchestration Systems Kubernetes

Evolution of Application Deployment

2110415 Software-Defined Systems

Page 6: Container Orchestration Systems Kubernetes

Decouples Infrastructure and Scaling

• Simplify service discovery and exposed• All services within K8s are natively load

balanced• Can scale up and down dynamically• Allow seamless upgrading and rollback of

applicaions• Enable self-healing

2110415 Software-Defined Systems

Page 7: Container Orchestration Systems Kubernetes

Self Healing

• K8s will always try and steer the cluster to its desired state– User: ”I want 3 healthy running instances of redis”– K8s: “Ok, I will ensure there are always 3 instances

of redis up and running”– After a while, K8s: “Oh, one redis has died,

attempt to spin up a new one”

2110415 Software-Defined Systems

Page 8: Container Orchestration Systems Kubernetes

K8s Components

2110415 Software-Defined Systems

Page 9: Container Orchestration Systems Kubernetes

K8s Objects: Pods• Smallest "unit of work" of K8s• One or more containers that are guaranteed to be co-located

on the host machine and can share resources• The basic scheduling unit in Kubernetes is a pod

2110415 Software-Defined Systems

Page 10: Container Orchestration Systems Kubernetes

2110415 Software-Defined Systems

K8s Objects: Nodes

• A node can be either a virtual or a physical machine

• Can be called worker nodes• K8s master schedules the

pods across the nodes• Every node runs at least:

– Kubelet: handling communication between the K8s Master and the node

– A container runtime (like Docker)

Page 11: Container Orchestration Systems Kubernetes

2110415 Software-Defined Systems

K8s Objects: Control Plane

• Can be called master node• Responsible for managing the

cluster• Coordinates all activities in

your cluster– scheduling applications– maintaining applications'

desired state– scaling applications– rolling out new updates

Page 12: Container Orchestration Systems Kubernetes

K8s: Master and Worker Nodes

Source: https://rancher.com/blog/2019/2019-04-12-understanding-kubernetes-node/

Page 13: Container Orchestration Systems Kubernetes

Running a K8s cluster

• Local single node (in docker): k3d, kind, k8s on docker desktop

• Local multiple nodes: k3s, microk8s• Cloud: GKE, AKS, EKS• For testing purpose, recommend using k3d or

k8s on docker desktop

2110415 Software-Defined Systems

Page 14: Container Orchestration Systems Kubernetes

Our Testing Program

• We will use an application called "kuard" from a book "Kubernetes: Up and Running, 2nd Edition"

• Let's try kuard in dockerdocker run -d --name kuard -p 8080:8080 \

gcr.io/kuar-demo/kuard-amd64:blue

• Use browser to connect to http://localhost:8080 or using curlcurl http://localhost:8080

2110415 Software-Defined Systems

Page 15: Container Orchestration Systems Kubernetes

2110415 Software-Defined Systems

Page 16: Container Orchestration Systems Kubernetes

Running K8s in Docker with k3dcurl -s https://raw.githubusercontent.com/rancher/k3d/main/install.sh | bash

k3d cluster create mycluster

2110415 Software-Defined Systems

Page 17: Container Orchestration Systems Kubernetes

• CLI tool for controlling K8s• Need config file– $HOME/.kube/config– Filename from KUBECONFIG environment variable– Filename from --kubeconfig flag

• Run command in the formatkubectl <command> <args>

kubectl

Page 18: Container Orchestration Systems Kubernetes

Kubectl Sample Commands• kubectl config view• kubectl get• kubectl apply• kubectl create• kubectl explain• kubectl run• kubectl expose• kubectl rollout• kubectl scale• kubectl delete

2110415 Software-Defined Systems

Create or modify resources using a manifest file

Create resources using command line

Page 19: Container Orchestration Systems Kubernetes

2110415 Software-Defined Systems

There are 2 clusters

There are 2 contexts

Current context

Page 20: Container Orchestration Systems Kubernetes

2110415 Software-Defined Systems

Page 21: Container Orchestration Systems Kubernetes

Running a container

• There are two possible ways to run a container, run command or apply command

2110415 Software-Defined Systems

Page 22: Container Orchestration Systems Kubernetes

Running a container

• Apply command uses yaml config file as a manifest file

2110415 Software-Defined Systems

Page 23: Container Orchestration Systems Kubernetes

2110415 Software-Defined Systems

Page 24: Container Orchestration Systems Kubernetes

2110415 Software-Defined Systems

Page 25: Container Orchestration Systems Kubernetes

Other Commandskubectl logs kuardkubectl exec kuard date

kubectl exec -it kuard – ash

kubectl cp $HOME/config.txt <pod-name>:/config.txt

2110415 Software-Defined Systems

Page 26: Container Orchestration Systems Kubernetes

2110415 Software-Defined Systems

Define remote NFS disk volume

Minimum requirements

Define volume mount point

Maximum limits

Page 27: Container Orchestration Systems Kubernetes

2110415 Software-Defined Systems

Check if app is still running

Check if app is ready to serve

Page 28: Container Orchestration Systems Kubernetes

Labels and Annotations

• Useful concepts to define sets of items to organize and work with them as groups efficiently

• Label – key/value metadata or "tags" on K8s objects e.g. pods, replicasets– Useful tags include version number, running environment,

application domain, etc.– Can select objects based on label e.g. --selector

• Annotation – similar to label, but more like notes for communicating between tools or admins

2110415 Software-Defined Systems

Page 29: Container Orchestration Systems Kubernetes

2110415 Software-Defined Systems

Page 30: Container Orchestration Systems Kubernetes

Deployment

• Running pods is very simple, but have limited functionality

• K8s provides "deployment", which describeds the desired state of the application

• Deployment enables– Expose services– Scale replicas– Rollout new versions

2110415 Software-Defined Systems

Page 31: Container Orchestration Systems Kubernetes

2110415 Software-Defined Systems

apiVersion: apps/v1kind: Deploymentmetadata:name: kuardlabels:app: kuard

spec:selector:matchLabels:app: kuard

replicas: 1template:metadata:labels:app: kuard

spec:containers:- name: kuardimage: gcr.io/kuar-demo/kuard-amd64:blueports:- containerPort: 8080

Page 32: Container Orchestration Systems Kubernetes

K8s Scaling

2110415 Software-Defined Systems

• Deployment created only one Pod for running our application• When traffic increases, we will need to scale the application

to keep up with user demand

Scaling

Page 33: Container Orchestration Systems Kubernetes

2110415 Software-Defined Systems

Page 34: Container Orchestration Systems Kubernetes

2110415 Software-Defined Systems

K8s Objects: Services• An abstraction which defines a

logical set of Pods and a policy by which to access them

• Durable resource: static cluster IP, namespaces, DNS name

• Allow applications to receive traffic similar to API Gateway + Service Discovery

• Set of Pods targeted by a Service is usually determined by LabelSelector

Page 35: Container Orchestration Systems Kubernetes

2110415 Software-Defined Systems

Page 36: Container Orchestration Systems Kubernetes

K8s Ingress – beyond port-forwarding

• Ingress exposes HTTP and HTTPS routes from outside the cluster to services within the cluster

• Ingress has "load balancing" capability

2110415 Software-Defined Systems

Page 37: Container Orchestration Systems Kubernetes

2110415 Software-Defined Systems

Important note: • ingress does not work out of the box for k3d• You will have to start with port redirection:

k3d cluster create --api-port 6550 -p "8081:80@loadbalancer" mycluster

Page 38: Container Orchestration Systems Kubernetes

2110415 Software-Defined Systems

Rollout Updates

Page 39: Container Orchestration Systems Kubernetes

2110415 Software-Defined Systems

Rollout Updates

Page 40: Container Orchestration Systems Kubernetes

Other K8s Vocabs

• StatefulSet• DaemonSets• Job• CronJob• ConfigMaps

2110415 Software-Defined Systems

Page 41: Container Orchestration Systems Kubernetes

References

• https://kubernetes.io/docs/tutorials/kubernetes-basics/

• https://dzone.com/articles/microservices-with-kubernetes-and-docker

• Burns, Brendan, Joe Beda, and Kelsey Hightower. Kubernetes: up and running: dive into the future of infrastructure. O'Reilly Media, 2019

• https://www.slideshare.net/rishabhindoria52/introduction-to-kubernetes-139878615

2110415 Software-Defined Systems