Kubernestes from Zero
What is Kubernetes (k8s)?
Ofical definition:
- Open source
container orchestration tool
- Developed by
Google
- Hepls you
manage containerized applications
(e.g. Docker) in differentdeployment environments
(phycial, virtual, cloud machine)
Why we need a container orchestration tool?
- Trend from Monolith to
Microservices
- Increased usage of
containers
- Demand for a
proper way
ofmanaging
those hundreds of containers
What features do orchestration tools offer?
High Availability
or no downtime (app is always accessable)Scalability
or high performance (load fast, response fast to users actions)Disaster recovery
- backup and restore (data is lost, server error,… we still have mechanism to backup and restore -> not lose data)
Kubernetes components
Pod
- smallest unit of K8s
- abstraction over container (it creates a running environmennt or a layer on top of the containers -> we only interact with the Kubernetes layer)
- usually 1 application per Pod
- each Pod gets its own IP address (each pod can communicate each other via the IP address)
- new IP address on re-creation (hard to communicate -> Service will solve the problem)
Service
- static/permanent IP address (attach to each Pod)
- load balancer
- lifecyle of Pod and Service NOT connected (When Pod dead, Service is still alive => IP address is still accessable)
- external service -> open to public requests/browsers
- internal service -> not open to public requets (e.g. database)
Ingress
- requests go to Ingress and it will be forwarded to Service
ConfigMap
- external configuration of your application (urls of database or other services. Pod gets data from configMap. It helps Pods communicate wihout re-build images when we change endpoint of database, etc.)
Secret
- just like configMap but to store secret data
- base64 encoded
Volumes
- is data storage of Pod
- physical storage in local or remote
- when DB Pod restarted, volumes keep data there
- K8s doesn’t manage data persistance!
Deployment
- blueprint for my-app pods (define how many replica of Pods. When a Pod dies, app will connect to another Pod)
- you create Deployments
- abstraction of Pods
- DB can’t be replicated via Deployment!
- for stateLESS apps
StatefulSet
- for stateFUL apps or Databases
=> Deployment and StatefulSet used for Replication -> avoid downtime
Kubernetes Architecture
Node (working machine in k8s cluster)
- each Node has multiple Pods on it
- 3 processes must be installed in every Node (Container runtime such as Docker, Kubelet - interacts with container runtime and Node/Machine, Kube Proxy - forwards the requests)
- Worker Nodes do the actual work
Master Node
- 4 processes (API server-cluster gateway,acts as a gatekeeper for authentication; Scheduler-just decides on which Node new Pod should be scheduled,kubelet in each Node will do the actual schedule;Controller Manager-detects cluster state changes such as Pods die;etcd-cluster brain,key value store,cluster changes get stored into key value store,application data is NOT stored in etcd)
Api server
is load balancedetcd
is distributed across all Master Nodes