Kubernetes
Intro
Scaling & High availability
Kubernetes
Wrapping our current configuration to a K8S YAML
Monitoring tools
WS
WS
...lots of people..
Can we increase server resources?
How to handle high load?
HTTP
This is OK
I will add 128 GB RAM and more replace the CPU AMD Ryzen 9 3950X
Dinesh
Replacing hardware will require downtime,
lets add some separate cheap servers
Gilfoyle
ANTON
VS
No limitation of horizontal scaled instances | Hardware limitation |
It is difficult to implement | It is easy to implement |
It is costlier, as new server racks comprises of a lot of resources | It is cheaper as we need to just add new resources |
It takes more time to be done | It takes less time to be done |
No downtime | Downtime |
Which one is your choice ?
Horizontal scaling is almost always more desirable than vertical scaling because you don’t get caught in a resource deficit.
Chat Docker image
Container 1
Container 3
Container 2
docker run -p 3030:8080 -d localhost:32000/node-web-app:latest
docker run -p 3031:8080 -d localhost:32000/node-web-app:latest
docker run -p 3032:8080 -d localhost:32000/node-web-app:latest
Just create several instances of our chat containers on different ports
What if I want to run them on different hosts, how to organize the communication?
How to update the application automatically without downtime?
Auto-scale?
Load balancing?
Configuration stores?
SLI/SLO ?
Secrets?
with all these things!
Local development
Using Docker
Using docker-compose
Orchestration using Kubernetes
But Kubernetes is still the gold standart
Amazon Elastic Kubernetes Service (EKS)
Azure Kubernetes Service (AKS)
Google Kubernetes Engine (GKE)
Container Service for Kubernetes (ACK)
Oracle Kubernetes Engine
1. Build a Docker chat image
2. Push it to a registry
3. Start a Kubernetes cluster
4. Create a Deployment configuration YAML file
5. Setup a replication factor 2 for the Chat Pod
6. Apply YAML config using kubectl CLI
7. Kill a chat Pod and watch how Kubernetes handles it
Kubernetes, also known as K8s, is an open-source system for automating deployment, scaling, and management of containerized applications.
It groups containers that make up an application into logical units for easy management and discovery. Kubernetes builds upon 15 years of experience running production workloads at Google, combined with best-of-breed ideas and practices from the community.
Planet Scale
Designed on the same principles that allow Google to run billions of containers a week, Kubernetes can scale without increasing your ops team.
Never Outgrow
Whether testing locally or running a global enterprise, Kubernetes flexibility grows with you to deliver your applications consistently and easily no matter how complex your need is.
Run K8s Anywhere
Kubernetes is open source giving you the freedom to take advantage of on-premises, hybrid, or public cloud infrastructure, letting you effortlessly move workloads to where it matters to you.
IPv4/IPv6 dual-stack
Automated rollouts and rollbacks
Batch execution
Service Topology
Service discovery and load balancing
Horizontal scaling
Secret and configuration managment
Storage orchestration
Self-healing
Automatic bin packing
Official diagram from kubernetes.io
Node
DB
Pod
My app
Pod
Container runtime
Kubelet:
- interacts with both - container and Node
- starts the pod with a container inside
Processes
Node 1
DB
Pod
My app
Pod
Container runtime
Processes
Usually, there are multiple Nodes
Node 2
DB
Pod
My app
Pod
Container runtime
Processes
How to:
Node 1
Pod
Processes
Master Node
Pod
Node 2
Pod
Processes
Pod
Api Server
Client (kubelet, k8s API)
Some request
Api Server
validates request
..other processes..
Node 1
Pod
Processes
Master Node
Pod
Node 2
Pod
Processes
Pod
Api Server
Schedule new Pod
Api Server
Scheduler
Where to put the Pod?
Scheduler
60% used
30% used
Kubelet
Node 1
Pod
Processes
Master Node
Pod
Node 2
Pod
Processes
Pod
Api Server
Controller Manager
Scheduler
Scheduler
Kubelet
Controller Manager
detect cluster state changes
60% used
30% used
Node 1
Pod
Processes
Master Node
Pod
Node 2
Pod
Processes
Pod
Api Server
Scheduler
Controller Manager
60% used
30% used
etcd
Key Value Store
Node
Pod
Processes
Master
Pod
Api Server
Scheduler
Controller Manager
etcd
Master
Api Server
Scheduler
Controller Manager
etcd
Node
Pod
Processes
Pod
Node
Pod
Processes
Pod
Node
Pod
Processes
Pod
Master processes
Master and Node processes run on ONE machine
Minikube:
Node
Pod
Processes
Pod
Service
Secret
ConfigMap
Command-line tool for K8s cluster
Master processes - API Server enables interaction with the cluster
Api Server
Scheduler
Controller Manager
etcd
UI
API
CLI (kubectl)
Kubectl controls the Kubernetes cluster manager
kubectl create deployment nginx --image=nginx # Create NGINX deployment with 1 Pod (1 Container)
kubectl scale --replicas=3 deployment/nginx # Scale current NGINX servers to 3 replicas
kubectl delete deployment/nginx # delete everything
Instead of writing commands every time from scratch we can save them to a YAML file, and commit to the GitHub
kind: Deployment
apiVersion: apps/v1
metadata:
namespace: default
name: client-app
labels:
app: client-app
spec:
replicas: 1
selector:
matchLabels:
app: client-app
template:
metadata:
labels:
app: client-app
spec:
containers:
- name: client-app
image: iivashchuk/jsprocamp-client-app
env:
- name: API_HOST
value: "chat-service"
- name: API_PORT
value: "3001"
ports:
- name: web
containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: client-app
spec:
ports:
- protocol: TCP
name: web
port: 80
selector:
app: client-app
type: LoadBalancer
Use Helm to:
$ helm repo add bitnami https://charts.bitnami.com/bitnami $ helm install my-release bitnami/mongodb $ helm install my-redis --set cluster.slaveCount=0 bitnami/redis