Kubernetes Demystified: Understanding Its Core Components, Objects, and How It Works
Kubernetes, often abbreviated as K8s, is an open-source platform for automating the deployment, scaling, and management of containerized applications. Think of it as the operating system for your containerized workloads, helping you efficiently manage applications in complex environments. Kubernetes simplifies the operational tasks that come with running containers at scale, such as balancing workloads, scaling applications, and recovering from failures.
Core Components of Kubernetes and How They Work:
At its heart, Kubernetes operates on a cluster model. A Kubernetes cluster consists of one or more nodes, and these nodes work together to run your applications.
1. Control Plane
The control plane manages the cluster and its overall state. It consists of several components:
API Server: This is the gateway for all administrative commands. Users, administrators, and even internal components communicate with Kubernetes through the API server. It validates requests and updates the cluster's state accordingly.
etcd: A key-value store that serves as Kubernetes' "brain." It stores all cluster data, including configurations, desired states, and metadata. If the etcd database is lost, the cluster state is lost too.
Controller Manager: Manages controllers, which are background processes that continuously monitor the cluster's state. For example, the Node Controller ensures that nodes are functioning properly, while the Deployment Controller maintains the desired number of application replicas.
Scheduler: Decides which node will host a newly created pod (the smallest deployable unit in Kubernetes). The scheduler considers factors like resource availability and node labels.
2. Worker Nodes
Worker nodes are where your applications (in the form of pods) actually run. Each worker node has several key components:
Kubelet: This agent runs on every node and ensures that containers are running as expected. It communicates with the control plane to receive instructions.
Kube-proxy: Manages network communication within the cluster. It ensures that traffic is routed correctly between pods and services.
Container Runtime: Responsible for running containers on the node. Popular container runtimes include Docker, containerd, and CRI-O.
Kubectl: This agent using for run command in cluster and worker node. It communicates with the control plane and others node.
How Kubernetes Works in a Cluster
A user submits a deployment request via the API server.
The API server validates the request and updates the desired state in etcd.
The scheduler assigns the deployment to a suitable node based on resource availability.
The kubelet on that node pulls the necessary container images, starts the containers, and keeps them running.
Kube-proxy manages communication between the newly deployed containers and other components in the cluster.
Common Kubernetes Objects and How They Work
Kubernetes uses objects to represent the desired state of your cluster. Let’s explore the most common ones:
1. Pod
A pod is the smallest unit in Kubernetes and typically represents a single instance of a running application. Pods can contain one or more tightly coupled containers that share resources like storage and networking.
- How It Works: Pods act as a wrapper for containers, providing them with shared IP addresses, storage volumes, and metadata. If a pod fails, Kubernetes replaces it with a new one to maintain the desired state.
2. Service
A service provides a stable IP and DNS name to expose a group of pods. Even if pods are replaced, the service ensures that users can still reach your application.
- How It Works: Kubernetes uses labels to match services with pods. When a pod is scaled up or down, the service dynamically updates its endpoints.
3. Deployment
A deployment manages a set of pods, ensuring they are always running and up-to-date. It defines the desired state, such as the number of replicas, and takes care of rolling updates or rollbacks.
- How It Works: If a deployment specifies three replicas of a pod, Kubernetes will always ensure there are three pods running. If a pod crashes, a new one is automatically created.
4. ReplicaSet
A ReplicaSet ensures a specified number of pod replicas are running at any time. Deployments typically manage ReplicaSets, so you rarely need to interact with them directly.
- How It Works: If a pod managed by a ReplicaSet goes down, the ReplicaSet creates a new pod to maintain the desired replica count.
5. ConfigMap
ConfigMaps store configuration data in key-value pairs, allowing applications to be easily reconfigured without changing code.
- How It Works: Applications can mount ConfigMaps as files or environment variables, dynamically applying configuration changes without redeploying the application.
6. Secret
Similar to ConfigMaps, Secrets store sensitive data like API keys, passwords, and certificates. Secrets encrypt this data for added security.
- How It Works: Applications use Secrets in the same way as ConfigMaps, but the data is encoded to prevent accidental exposure.
7. StatefulSet
StatefulSets manage stateful applications where each pod has a unique identity and persistent storage.
- How It Works: Unlike ReplicaSets, StatefulSets maintain order and stability, ensuring that pods are created, updated, or deleted sequentially.
8. DaemonSet
A DaemonSet ensures that a specific pod runs on every node (or a subset of nodes) in the cluster.
- How It Works: DaemonSets are used for tasks like log collection, monitoring, or running system-level services.
9. Job and CronJob
Job: Runs a task until completion and then stops.
CronJob: Schedules Jobs to run at specified intervals, like a cron job in Linux.
How They Work: For one-off tasks, a Job creates the necessary pods and ensures they complete successfully. For recurring tasks, CronJobs create Jobs based on a predefined schedule.
Subscribe to my newsletter
Read articles from Nahid directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Nahid
Nahid
I am Mozahidul Islam Nahid, an engineer driven by a passion for continuous learning and growth. With six years of diverse professional experience. Which includes one year as DevOps engineer and four and a half years as administration and procurement specialist. Now I am dedicated to advance my career in DevOps engineering and cloud engineering.I am particularly passionate about server management and ongoing maintenance of websites post-deployment and I aspire to be a crucial part of these essential tasks for any company . Thank you!