Back to Tech Blog
KubernetesContainer OrchestrationDevOpsCloud

Understanding Kubernetes: Basics of K8s and its Components

A comprehensive guide to Kubernetes architecture, control plane, worker nodes, and core components.

December 20, 2024
7 min read

Kubernetes, often abbreviated as K8s, is an open-source container orchestration platform designed to automate the deployment, scaling, and management of containerized applications. It is an essential tool for managing modern cloud-native applications.

Why Kubernetes Over Docker?#

While Docker revolutionized application development by enabling containerization, it lacked advanced orchestration capabilities. Docker Swarm provided some functionality but fell short in scalability and flexibility. Kubernetes emerged as the preferred solution due to:

  • Scalability: Handles thousands of containers across multiple nodes with ease
  • Automation: Automates container scheduling, scaling, and self-healing
  • Networking: Provides robust networking for seamless container communication
  • Portability: Cloud-agnostic, allowing workloads to run on any infrastructure
  • Rich Ecosystem: Supports ConfigMaps, Secrets, and custom resource definitions (CRDs)

Docker focuses on container creation and management, whereas Kubernetes orchestrates and manages clusters of containers effectively.

Kubernetes Architecture#

Kubernetes follows a client-server architecture comprising the control plane and worker nodes, which together form the Kubernetes cluster.

Loading diagram...

kubectl interacts with the control plane in two ways:

  1. Declarative - through YAML files
  2. Imperative - through specific commands

The control plane is the brain of the Kubernetes cluster, managing overall state and operations:

  • API Server: The front end handling all RESTful API requests and central management point
  • Scheduler: Places Pods onto worker nodes based on resource availability and constraints
  • Controller Manager: Runs controllers ensuring actual state matches desired state
  • etcd: A distributed key-value store holding cluster configuration and state

Worker Nodes#

Worker nodes are machines where application workloads run. Each includes:

  • Kubelet: Agent communicating with the control plane, ensuring containers run in Pods
  • Kube-proxy: Manages network rules and facilitates Pod communication
  • Container Runtime: Software running containers (Docker or containerd)

Inside the Worker Node#

Loading diagram...

Containers#

Lightweight, portable, isolated application units packaging code and dependencies for consistency across environments.

Pods#

The smallest deployable units in Kubernetes. Each Pod can host one or more tightly coupled containers sharing storage volumes, network namespace, and configuration.

Container Runtime#

The underlying software managing containers on worker nodes, handling lifecycle tasks like starting, stopping, and deleting containers.


Control Plane Deep Dive#

Loading diagram...

API Server#

The API Server uses REST APIs for client interactions, providing a standardized interface for accessing cluster resources.

Key Responsibilities:

  • Resource Management: Manages Pods, Services, Deployments, PVs, and Namespaces
  • Request Handling: Processes kubectl commands and scaling requests
  • State Management: Maintains cluster state consistency
  • Security: Handles authentication and authorization

How It Works:

  1. Receives incoming requests via REST APIs
  2. Checks authentication and authorization
  3. Retrieves current cluster state from etcd
  4. Executes operations and updates etcd
  5. Returns response to client

Impact of Failure:

  • Client requests hang until restoration
  • Pods may not be scheduled
  • Services might become unavailable

Controller Manager#

Coordinates and runs controllers to ensure cluster resources match desired state.

Key Functions:

  • Resource allocation for controllers and pods
  • Pod lifecycle management (creation, scaling, termination)
  • Service registration with etcd
  • Deployment updates and scaling
  • Event processing for consistency

Components:

  • Controller Registry tracking registered controllers
  • Pod Status Update mechanism
  • Service Registration manager
  • Event Handling Loop for continuous processing

etcd#

A distributed, highly available key-value store serving as the core of Kubernetes' control plane.

Key Roles:

  • Cluster State Management: Stores node information, pod assignments, and cluster state
  • Leader Election: Uses Raft consensus algorithm for single leader at a time
  • Configuration Storage: Holds control plane configuration data

Architecture Features:

  • Leader election among cluster instances
  • Multiple data copies across nodes for high availability
  • Configurable cluster size and election timeout

Benefits:

  • High availability during node failures
  • Easy scalability by adding instances
  • Centralized configuration management

Challenges:

  • Adds complexity for large deployments
  • Requires careful performance tuning
  • Needs encryption and security planning

Scheduler#

Decides which nodes run each pod by evaluating resources, topology, and requirements.

Decision Criteria:

  • CPU Affinity: Optimizes CPU-bound workloads
  • Memory Allocation: Ensures sufficient memory
  • Network Topology: Minimizes latency, maximizes throughput
  • Storage Availability: Matches pods with suitable storage classes

Workflow:

  1. Receives pod creation requests from API server
  2. Evaluates available resources on nodes
  3. Selects suitable nodes for pods
  4. Allocates CPU, memory, and storage
  5. Monitors node availability continuously

kubectl#

A command-line tool for interacting with the cluster's API server.

Primary Functions:

  • Manage pod operations (create, update, delete)
  • Inspect cluster state (clusters, nodes, pods, services)
  • Apply configuration changes from YAML/JSON manifests

Worker Node Deep Dive#

Loading diagram...

Kubelet#

An agent running on each worker node managing resources and interacting with the API server.

Responsibilities:

  • Resource Management: Monitors CPU/memory and reports to API server
  • Pod Scheduling: Receives pod assignments and runs Pods on available resources
  • Runtime Monitoring: Tracks container status, image health, and metrics

Workflow:

  1. Connects to API server for pod assignments
  2. Evaluates resources and schedules pods
  3. Monitors node resource usage continuously
  4. Updates container status via runtime interface
  5. Launches and manages pods

Common Issues:

  • Resource limitations causing pod failures
  • Container runtime errors disrupting updates
  • Network problems hindering API communication

Kube-Proxy#

Manages service networking by routing and load-balancing traffic to Pods.

Responsibilities:

  • Service Traffic Management: Routes traffic from Cluster IPs to Pods using load-balancing
  • NodePort Management: Maps external ports to Pods for external access
  • Status Reporting: Updates API server about service changes

Workflow:

  1. Registers node with API server
  2. Creates/updates service proxy rules for new Services
  3. Distributes requests among Pods (round-robin)
  4. Reports Pod failures or restarts

Benefits:

  • High availability even during instance failures
  • Efficient traffic distribution for scalability
  • Service-level monitoring insights

Container Runtime#

Manages the lifecycle of containers from creation to termination.

Responsibilities:

  • Container creation from images
  • Resource allocation (CPU, memory)
  • Networking and volume handling
  • Health monitoring and termination

Types:

  • Kubernetes-Native: Docker (runc), CRI-O, containerd
  • Third-Party: rkt (CoreOS), cri-containers

Key Features:

  • Container isolation for security
  • Efficient networking and IPC
  • Optimized resource management

Summary#

Kubernetes architecture consists of two main components:

ComponentRole
Control PlaneManages cluster state, scheduling, and orchestration
Worker NodesRun application workloads as Pods

The control plane includes the API Server, Scheduler, Controller Manager, and etcd. Worker nodes contain the Kubelet, Kube-proxy, and Container Runtime.

In the next part, we'll explore Kubernetes objects like Deployments, Services, ConfigMaps, and more. Stay tuned!

Share: