Skip to main content

Kubernetes

Kubernetes (K8s) is an open-source container management platform that automates the deployment, scaling, and management of containerized applications.

Kubernetes is particularly effective for distributed systems where many containers must coordinate and scale efficiently. It automates complex operational tasks such as scheduling, load balancing, scaling, and failure recovery, simplifying container management across clusters.

Kubernetes enables developers and DevOps teams to focus on application development rather than infrastructure management. It is widely used in modern cloud-native application development, especially for microservices architectures.

Kubernetes Architecture

Kubernetes utilizes a control plane–worker node architecture to manage and orchestrate containers across a cluster.

Control Plane

The control plane manages and controls the Kubernetes cluster. It manages scheduling, cluster state, and deployment decisions, keeps track of the system's overall state, and determines where and when containers should run. The following are the key components of the control plane:

  • kube-apiserver: This is the control plane's front end, exposing the Kubernetes API. It accepts incoming REST requests, validates them, and routes them to the appropriate components.
  • kube-scheduler: This monitors newly created pods and assigns them to nodes according to resource availability, constraints, and policies.
  • kube-controller-manager: This ensures the system functions properly by monitoring the cluster's status and making necessary changes. For example, if a pod fails, the controller manager will create a replacement.
  • etcd: This is a distributed key-value store that keeps track of all cluster data, including node, pod, and configuration states. It serves as Kubernetes' source of truth.

Nodes

Nodes are the machines that run containerized applications. The following are the key components of each node to run and manage containers:

  • kubelet: This is an agent that runs on each node to ensure that containers run as expected. It communicates with the API server and monitors pod definitions and health checks.
  • kube-proxy: This handles network routing, ensuring that service requests are routed to the appropriate pods, as well as load balancing.
  • Container runtime: This is the software that runs containers. Docker is a common container runtime, but Kubernetes also supports containerd and CRI-O.

Kubernetes Key Concepts

  • Containers: The containers are lightweight, portable, and self-contained units that run software. They bundle an application and its dependencies (libraries, configuration files, and binaries) to ensure consistent performance across multiple environments. Kubernetes is designed to manage these containers at scale.
  • Pods: A Pod is the smallest and most basic unit in Kubernetes. A pod can hold one or more containers that use the same network namespace and storage. Pods ensure that containers within the same pod can communicate easily. Pods are ephemeral, which means Kubernetes can automatically destroy and recreate them, typically when scaling or updating an application.
  • Nodes: A node is a physical or virtual machine in a Kubernetes cluster that runs containerized applications. Kubernetes schedules pods to nodes, which are where the workload runs. There are two types of nodes:
    • Control Plane: Controls the cluster.
    • Node: Runs the application.
  • Clusters: The Kubernetes cluster is a collection of nodes that work together to run containerized applications. It consists of two components: the control plane and the nodes (where containers run). Kubernetes manages the cluster, keeping it healthy and scalable.
  • ReplicaSets: A ReplicaSet ensures that a set number of identical pods are running at any given time. It automatically adjusts the number of pods running to match the user-defined desired state. Its common use is scaling applications to handle increased traffic or workloads.
  • Deployments: A deployment is a higher-level abstraction that manages ReplicaSets and ensures the application has the correct number of pod replicas. Deployments manage rolling updates and rollbacks, allowing you to update applications without any downtime. For example, if you want to deploy a new version of an application, Kubernetes will gradually replace old pods with new ones while the application remains operational.
  • Services: A service is an abstraction that defines a logical set of pods along with the policies that govern access to them. Services provide a consistent endpoint (DNS name or IP address) for accessing pods, which may change over time due to scaling or pod replacement. There are several types of services:
    • ClusterIP: Exposes the service within the cluster.
    • NodePort: Exposes the service to the outside world through a static port on each node.
    • LoadBalancer: Exposes the service via a load balancer (e.g., on cloud providers).
    • ExternalName: Maps the service to an external DNS name.
  • Namespaces: Namespaces enable you to divide your cluster into virtual clusters. They aid in resource organization within a cluster, particularly in environments with multiple teams or environments (development, staging, production). Resources within a namespace are separate from those in other namespaces, which improves security and resource management.
  • ConfigMaps: ConfigMap stores non-sensitive configuration data in key-value pairs. Containers can easily consume these as environmental variables or configuration files.
  • Secrets: Secrets contain sensitive data such as passwords, tokens, and certificates. Secrets are base64-encoded and can be accessed safely within containers.
  • Persistent Storage: Kubernetes enables you to manage storage resources in a containerized environment using Persistent Volumes (PVs) and Persistent Volume Claims (PVCs). A PV is a storage unit configured by an administrator. A PVC is a user-made request for storage. This ensures data persistence across pod restarts or rescheduling events.

Benefits of Kubernetes

  • Automated Container Orchestration: Kubernetes automates the deployment, scaling, and management of application containers across clusters.
  • High Availability: Kubernetes can keep applications running by detecting and automatically recovering from errors.
  • Portability: Kubernetes works in different environments (public/private cloud, on-premises), allowing moving workloads without regard for the underlying infrastructure.
  • Scalability: Kubernetes can scale applications up and down automatically based on demand, which is critical for handling traffic spikes.
  • Self-Healing: Kubernetes continuously monitors pod and node health and automatically restarts, replaces, or reschedules them in case of failure.
  • Resource Efficiency: Kubernetes efficiently schedules pods across available nodes to maximize resource utilization. It also supports resource limits and requests to help balance workloads and avoid over-provisioning.