## Kubernetes Cluster Architecture
A Kubernetes cluster consists of a set of control plane components and worker nodes. The control plane manages the cluster, while worker nodes run the actual applications (pods).
## Control Plane Components
These components make global decisions about the cluster (e.g., scheduling) and detect and respond to cluster events.
- kube-apiserver: The front-end of the Kubernetes control plane. It exposes the Kubernetes API, which all other components and users interact with. It's the only control plane component directly exposed.
- etcd: A consistent and highly available key-value store that stores all cluster data, configuration, and state. It's the single source of truth for the cluster.
- kube-scheduler: Watches for newly created Pods with no assigned node and selects a node for them to run on, based on resource requirements, policies, and affinity/anti-affinity specifications.
- kube-controller-manager: Runs various controller processes. Each controller is a separate process, but they are compiled into a single binary to reduce complexity. Examples include the Node Controller, Replication Controller, Endpoints Controller, and Service Account & Token Controllers.
- cloud-controller-manager: (Optional) Interacts with the underlying cloud provider to manage cloud-specific resources like load balancers, persistent volumes, and node lifecycle.
## Worker Node Components
These components run on each worker node and are responsible for maintaining running pods and providing the Kubernetes runtime environment.
- kubelet: An agent that runs on each node in the cluster. It ensures that containers are running in a Pod as specified by the control plane. It registers the node with the API server.
- kube-proxy: A network proxy that runs on each node. It maintains network rules on nodes, allowing network communication to your Pods from network sessions inside or outside the cluster. It handles Service abstraction.
- Container Runtime: The software responsible for running containers. Kubernetes supports various runtimes through the Container Runtime Interface (CRI), such as containerd, CRI-O, or Docker (via containerd shim).
## Cluster Installation & Configuration with kubeadm
kubeadm is a tool designed to easily bootstrap a minimum viable Kubernetes cluster. It handles the setup of control plane components and allows worker nodes to join.
- `kubeadm init`: Initializes a control plane node. It performs pre-flight checks, generates certificates, sets up the kube-apiserver, etcd, kube-scheduler, and kube-controller-manager as static pods or systemd services.
- `kubeadm join`: Allows worker nodes to join an existing cluster. It takes a token and the control plane's IP address to securely connect.
- Pod Network Add-on (CNI): After `kubeadm init`, a Container Network Interface (CNI) plugin (e.g., Calico, Flannel) must be installed to enable pod-to-pod communication. Without it, pods will remain in a `Pending` state or fail to communicate.
- kubeconfig: A file that stores cluster access information (cluster details, user credentials, context) for `kubectl` and other tools.
What is the primary function of the **kube-apiserver**?
It exposes the Kubernetes API and is the front-end for the control plane, handling all communication.
tap to reveal
Which component stores the entire state of the Kubernetes cluster?
**etcd**
tap to reveal
What is the role of the **kubelet** on a worker node?
It's an agent that ensures containers are running in a Pod as specified by the control plane.
tap to reveal
What does `kubeadm init` accomplish?
It initializes a Kubernetes control-plane node, setting up all necessary control plane components and certificates.
tap to reveal
Why is a **CNI plugin** necessary for a Kubernetes cluster?
It provides pod networking, allowing pods to communicate with each other across nodes.
tap to reveal
What is the purpose of **kube-proxy**?
It maintains network rules (e.g., iptables or IPVS) on nodes to enable network communication to Pods via Services.
tap to reveal
Where are the credentials and configuration for accessing a Kubernetes cluster stored?
In **kubeconfig** files.
tap to reveal
Name two components of the Kubernetes control plane.
kube-apiserver, etcd, kube-scheduler, kube-controller-manager (any two).
tap to reveal