Kubernetes Architecture Using Examples (Day-26)

Kubernetes Architecture Using Examples (Day-26)

Welcome to DevOps Day 26! Today, we're diving into the fascinating world of Kubernetes architecture. Whether you're a beginner or an experienced developer, understanding Kubernetes is crucial for modern DevOps practices. Let's break down the key components and concepts with easy-to-understand examples.

1. Kubernetes Architecture using Examples

At its core, Kubernetes is an open-source container orchestration platform designed to automate the deployment, scaling, and management of containerized applications. The architecture is divided into two main parts: the control plane and the data plane.

2. Kubernetes Control Plane

The control plane is the brain of Kubernetes, responsible for making decisions about the cluster and managing its overall state. Let's explore its components:

a. etcd

Etcd is a distributed key-value store that acts as Kubernetes' database. It stores all cluster data, including configurations and the current state. Think of etcd as the memory of Kubernetes.

Example:

apiVersion: v1
kind: ConfigMap
metadata:
  name: etcd-config
data:
  cluster-name: my-k8s-cluster

b. API Server

The API server is the communication hub for all components in the control plane. It exposes the Kubernetes API, allowing users and controllers to interact with the cluster.

Example:

kubectl get pods

c. Controller Manager

The Controller Manager ensures that the cluster's desired state matches its actual state. It watches for changes and performs actions to maintain the desired configuration.

Example:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  replicas: 3

d. Scheduler

The Scheduler assigns newly created pods to nodes based on resource availability, constraints, and policies. It's like a traffic cop directing pods to the right place.

Example:

apiVersion: v1
kind: Pod
metadata:
  name: nginx-pod
spec:
  containers:
  - name: nginx-container
    image: nginx:latest

e. Cloud Controller Manager (CCM)

The Cloud Controller Manager extends the Kubernetes control plane with cloud-specific control loops. It manages interactions with the underlying cloud infrastructure, handling tasks like node management and load balancing.

Example (for AWS):

apiVersion: v1
kind: Service
metadata:
  name: my-load-balancer
spec:
  type: LoadBalancer
  selector:
    app: my-app
  ports:
    - protocol: TCP
      port: 80
      targetPort: 8080

3. Kubernetes Data Plane

The data plane, also known as the node plane, manages the execution of containers. It includes nodes and the components running on them.

a. Kubelet

Kubelet is an agent running on each node, responsible for communication between the node and the control plane. It ensures that containers are running in a Pod.

Example:

kubectl describe node <node-name>

b. Kube-Proxy

Kube-Proxy maintains network rules on nodes. It enables communication across pods and external services by managing network routing.

Example:

apiVersion: v1
kind: Service
metadata:
  name: nginx-service
spec:
  selector:
    app: nginx
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80

c. Container Runtime

The Container Runtime is responsible for pulling container images from a registry, running the containers, and managing their lifecycle. Common container runtimes include Docker, containerd, and cri-o.

Example:

apiVersion: v1
kind: Pod
metadata:
  name: nginx-pod
spec:
  containers:
  - name: nginx-container
    image: nginx:latest

4. Kubernetes Components with Examples

Now, let's explore some common Kubernetes components used in everyday scenarios:

a. Pods

Pods are the smallest deployable units in Kubernetes, representing a single instance of a running process. They encapsulate containers and share network and storage resources.

Example:

apiVersion: v1
kind: Pod
metadata:
  name: nginx-pod
spec:
  containers:
  - name: nginx-container
    image: nginx:latest

b. Deployments

Deployments define desired pod states, allowing for easy updates and rollbacks. They ensure that a specified number of replicas are running at all times.

Example:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx-container
        image: nginx:latest

c. Services

Services enable communication between pods and external services. They provide a stable IP address and DNS name for a set of pods.

Example:

apiVersion: v1
kind: Service
metadata:
  name: nginx-service
spec:
  selector:
    app: nginx
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80

In conclusion, understanding Kubernetes architecture is pivotal for anyone venturing into DevOps. With this guide, you're equipped to explore and experiment with Kubernetes, unlocking the potential for scalable and resilient containerized applications.


Keep Exploring...