container orchestration systems kubernetes

Post on 16-Jan-2022

12 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Container Orchestration SystemsKubernetes

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

2110415 Software-Defined Systems

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

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

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

Evolution of Application Deployment

2110415 Software-Defined Systems

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

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

K8s Components

2110415 Software-Defined Systems

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

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)

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

K8s: Master and Worker Nodes

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

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

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

2110415 Software-Defined Systems

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

• 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

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

2110415 Software-Defined Systems

There are 2 clusters

There are 2 contexts

Current context

2110415 Software-Defined Systems

Running a container

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

2110415 Software-Defined Systems

Running a container

• Apply command uses yaml config file as a manifest file

2110415 Software-Defined Systems

2110415 Software-Defined Systems

2110415 Software-Defined Systems

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

2110415 Software-Defined Systems

Define remote NFS disk volume

Minimum requirements

Define volume mount point

Maximum limits

2110415 Software-Defined Systems

Check if app is still running

Check if app is ready to serve

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

2110415 Software-Defined Systems

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

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

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

2110415 Software-Defined Systems

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

2110415 Software-Defined Systems

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

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

2110415 Software-Defined Systems

Rollout Updates

2110415 Software-Defined Systems

Rollout Updates

Other K8s Vocabs

• StatefulSet• DaemonSets• Job• CronJob• ConfigMaps

2110415 Software-Defined Systems

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

top related