Kubernets Architecture
flowchart TD
subgraph Master["Master Node / Control Plane"]
CM["Controller Manager"]
SCH["Scheduler"]
ETCD["etcd"]
AO["Add Ons"]
API["API Server"]
end
subgraph W1["WORKER_NODE-1 / Agent Node"]
W1Idle["idle worker"]
end
subgraph W2["WORKER_NODE-2 / Agent Node"]
KP2["Kubelet / kubectl proxy"]
KProxy2["Kube-Proxy"]
Meta2["Node status and metadata"]
AddOns2["Add Ons"]
subgraph Docker["Docker - container runtime"]
subgraph NS2["Namespace_2"]
POD_a2["POD_a2"]
C22["Container-22 docker"]
end
subgraph NS1["Namespace_1"]
subgraph POD_a["POD_a"]
subgraph C2["Container-2 sidecar localhost:9191"]
H2["Helper<br>Log Forwarder"]
R2["Runtime-2"]
D2["Depedencies-2"]
end
subgraph C1["Container-1 JAMS localhost:9192"]
A1["Application-1<br>jams-server<br>TargetPort=8080"]
R1["Runtime-1"]
D1["Depedencies-1"]
end
end
subgraph POD_b["POD_b"]
subgraph CXYZ["Container XYZ"]
An["Application-n TargetPort=8080"]
Rn["Runtime-n"]
Dn["Depedencies-n"]
end
end
end
end
end
Note_NS1["Namespace can have multiple pods"]
Note_Pod["Pod can have multiple containers"]
C22 -.-> Note_NS1
A1 -.-> Note_Pod
API --> W1Idle
API --> KP2
API --> KProxy2
Master Node/Control Plane
-
User Interacts with Master node(using yaml file). Master node
create/destroy worker nodes. Daemons in Master node
1. API Server
Manages all communication with Worker nodes(using kubelet)
2. etcd store
Stores state of kubernets cluster
3. Scheduler
Schedules pods to run on worker nodes
How Scheduler Decides Where to Place Pods? (Filtering, Scoring, Binding)
1. Filtering:
The scheduler looks at all the worker nodes in your cluster and
eliminates any node that cannot run the pod.
Does the node have enough free CPU and memory (requests/limits)?
Does the pod require a specific port that is already in use?
2. Scoring:
Filtered Nodes are given score from 0 to 100 based on a set of
ranking rules.
3. Binding:
Highest rank node wins. Scheduler decides to place pod on it and
sends message back to API server
4. Controller Manager (go process)
Controller manager is a go process which runs several
Controllers/Operators as goroutines
Once state changes of Pod goes down, Controller Manager updates same to
API server and asks kubelet to correct the state.
Check Sequence Diagram here
5. Addons
Provides additional functionality
Worker Node = VM
-
Worker node is seperate installation(eg: VM). When load increases pods
inside worker nodes will be scaled.
We would need Cluster scalar(eg: Karpenter) which will automatically spawn a new worker node on load
Worker node handles workload. Worker nodes hosts PODS. 1 Pod can contain 1 or more containers, Eg: docker.
Deamons in Worker Node
Kubelets
Recieves instructions from API Server to run/manage container.
Container Runtime
This actually runs the container. Several runtimes kubernets supports: Docker, containerd, CRI-O
Kube-proxy
For communication with other nodes in cluster
Add-Ons
Additional functionality.
Node status & Meta-data
Each worker node maintains meta-data about itself. Example: IP Address, hostname, Current status (Ready, Not Ready, Out of Disk space etc)
POD (Inside Worker Node)
-
POD is smallest deployable unit in kubernets. 1 Pod can contain 1 or
more containers
Each POD has its own: IP & namespace. Containers in POD share resources and can communicate using 'localhost' and can share storage volumes. Memory is allocated to Pods using Volumes.
Can Container has multiple executables running?
Yes, But its not recommended. Container should ideally run only 1 process.
Terms
Ambassador API Gateway, Namespace, Ports(Nodeport, ContainerPort, HostPort), PVC(Persistant Volume Claims), Authorization(Service Tokens, Istio Authorization Policy)
kubelet
kubectl is a command-line tool used by humans to send commands to the API-Server(on control plane). kubectl command directly reaches API server, does not route via kubelet.