Tuesday, December 31, 2024

Basics of Kubernetes

 Kubernetes, often abbreviated as K8s, is an open-source platform designed to automate the deployment, scaling, and management of containerised applications. It provides a framework for running distributed systems resiliently, ensuring high availability, scalability, and efficient resource utilisation.

Key Features of Kubernetes:

  1. Container Orchestration: Manages and schedules containers across a cluster of machines.
  2. Self-Healing: Automatically restarts failed containers, replaces unresponsive nodes, and kills unresponsive containers.
  3. Load Balancing and Service Discovery: Distributes traffic across containers and offers a stable networking interface.
  4. Scaling: Automatically scales applications up or down based on resource usage or manual input.
  5. Rollouts and Rollbacks: Ensures smooth updates to applications and allows rolling back to previous versions if something goes wrong.
  6. Storage Management: Mounts storage systems (local, cloud, or network) to containers.
  7. Configuration Management: Manages secrets and configuration details securely without embedding them in application code.

Components of Kubernetes:


1. Control Plane Components

The control plane is responsible for managing the overall Kubernetes cluster.

a. API Server (kube-apiserver)

  • Role: Acts as the main entry point for the Kubernetes control plane.
  • Function:
    • Serves the Kubernetes REST API.
    • Handles requests from users, CLI (kubectl), and other components.
    • Validates and processes API calls.
  • Communication: Authenticates requests and forwards them to the appropriate component (e.g., Scheduler, etcd).

b. etcd

  • Role: A distributed key-value store that serves as Kubernetes' backing store.
  • Function:
    • Stores cluster state and configuration data (e.g., pod details, namespace definitions).
    • Ensures data consistency across the cluster.
    • Provides a reliable database for leader election and other critical cluster operations.
  • Importance: If etcd fails, the entire cluster state could be compromised.

c. Scheduler (kube-scheduler)

  • Role: Assigns workloads (pods) to worker nodes based on resource requirements and constraints.
  • Function:
    • Evaluates the cluster's current state and finds a suitable node for each pod.
    • Considers factors like resource availability (CPU, memory), affinity/anti-affinity rules, and taints/tolerations.
    • Ensures balanced workloads across the cluster.

d. Controller Manager (kube-controller-manager)

  • Role: Runs various controllers that monitor and reconcile the desired state of the cluster with its actual state.
  • Function:
    • Node Controller: Monitors the health of worker nodes.
    • Replication Controller: Ensures the correct number of pod replicas are running.
    • Endpoint Controller: Updates endpoints for services.
    • Service Account Controller: Manages service accounts for accessing the API server.

e. Cloud Controller Manager (Optional)

  • Role: Manages interactions with the cloud provider.
  • Function:
    • Provisions and manages cloud-specific resources (e.g., load balancers, storage volumes).
    • Includes controllers like:
      • Node Controller: Handles node lifecycle in cloud environments.
      • Route Controller: Manages network routes.
      • Volume Controller: Manages cloud storage volumes.

2. Node Components

These components run on every worker node and are responsible for running and managing workloads.

a. Kubelet

  • Role: The agent running on each node that ensures containers are running as specified.
  • Function:
    • Communicates with the control plane to receive pod specifications.
    • Ensures containers in pods are healthy and running.
    • Reports node status to the control plane.

b. Kube-proxy

  • Role: A network proxy managing network rules for communication within the cluster.
  • Function:
    • Forwards requests to the appropriate pod/service.
    • Maintains network connectivity for services across nodes using iptables or IPVS.
    • Supports Kubernetes services (ClusterIP, NodePort, LoadBalancer).

c. Container Runtime

  • Role: Executes containers on the node.
  • Function:
    • Manages the lifecycle of containers (starting, stopping, etc.).
    • Examples: Docker, containerd, CRI-O.
  • Integration: Communicates with the kubelet via the Container Runtime Interface (CRI).

3. Additional Components

a. Pod

  • The smallest deployable unit in Kubernetes.
  • Encapsulates one or more containers with shared networking and storage.

b. Cluster DNS (CoreDNS)

  • Role: Provides DNS for the Kubernetes cluster.
  • Function:
    • Resolves service names to IPs within the cluster.
    • A default add-on in most Kubernetes distributions.

c. Ingress

  • Role: Manages external HTTP/S access to services in the cluster.
  • Function:
    • Provides load balancing, SSL termination, and routing.
    • Simplifies access to internal services via a single external endpoint.

4. Add-Ons

Kubernetes also supports optional components to extend its functionality:

  • Metrics Server: Aggregates and provides resource metrics for autoscaling.
  • Dashboard: A web UI to manage and monitor the cluster.
  • Logging Solutions: Integrations with systems like Fluentd, Elasticsearch, and Kibana.

Interaction Between Components

  1. Users interact with the API Server using kubectl or other tools.
  2. The API server validates and stores data in etcd.
  3. Controllers and schedulers act based on the desired state stored in etcd.
  4. Kubelet on worker nodes ensures pods are running as defined.

This modular architecture enables Kubernetes to manage containerized applications efficiently and at scale.



No comments:

Basics of Kubernetes

 Kubernetes, often abbreviated as K8s , is an open-source platform designed to automate the deployment, scaling, and management of container...