Kubernetes is an open-source container orchestration platform designed to automate deployment, scaling, and management of containerized applications. It provides a robust framework for managing distributed systems with resilience and scalability.
Kubernetes Architecture
Kubernetes follows a master-worker architecture comprising various components that work together to manage and scale containers.

1. Master Node
The master node controls and manages the Kubernetes cluster. Key components include:
- API Server: The entry point for all Kubernetes REST commands. It validates and processes requests.
- Scheduler: Assigns workloads to appropriate nodes based on resource availability.
- Controller Manager: Monitors and reconciles the state of the cluster with the desired state.
- etcd: A distributed key-value store for storing cluster state and configuration.
2. Worker Nodes
Worker nodes run the containerized applications and handle workloads assigned by the master node. Key components include:
- Kubelet: Agent running on each worker node that ensures containers are running as expected.
- Kube Proxy: Handles networking, enabling communication between pods and external networks.
- Container Runtime: Executes containers (e.g., Docker, CRI-O, containerd).
3. Pods
- The smallest deployable unit in Kubernetes.
- Each pod encapsulates one or more containers that share resources like storage and networking.
4. Persistent Volumes (PVs) and Persistent Volume Claims (PVCs)
- PVs: Provide storage for Kubernetes pods.
- PVCs: Request specific storage from PVs.
5. Cluster Networking
- Enables communication between pods, nodes, and external systems.
- Supports service discovery, load balancing, and DNS resolution.
Common Kubernetes Commands
Cluster Management
kubectl cluster-info: Display cluster information.kubectl get nodes: List all nodes in the cluster.kubectl describe node <node-name>: Show detailed information about a node.
Pod Management
kubectl get pods: List all pods in the default namespace.kubectl describe pod <pod-name>: Show detailed information about a specific pod.kubectl logs <pod-name>: View logs from a pod.kubectl delete pod <pod-name>: Delete a specific pod.
Deployment Management
kubectl create deployment <name> --image=<image>: Create a deployment.kubectl get deployments: List all deployments.kubectl scale deployment <name> --replicas=<number>: Scale a deployment.kubectl delete deployment <name>: Delete a deployment.
Service Management
kubectl expose deployment <name> --type=<type> --port=<port>: Expose a deployment as a service.kubectl get services: List all services.kubectl describe service <service-name>: Show details of a service.
Namespace Management
kubectl get namespaces: List all namespaces.kubectl create namespace <name>: Create a new namespace.kubectl delete namespace <name>: Delete a namespace.
Configuration Management
kubectl get configmaps: List all ConfigMaps.kubectl create configmap <name> --from-literal=<key>=<value>: Create a ConfigMap.kubectl describe configmap <name>: Show details of a ConfigMap.
Uses of Kubernetes
- Container Orchestration
- Automates container deployment, scaling, and management.
- Load Balancing and Service Discovery
- Provides built-in load balancing for distributing traffic across pods.
- Scaling
- Automatically scales applications horizontally or vertically based on metrics.
- Self-Healing
- Restarts failed containers, reschedules pods on healthy nodes, and replaces pods when nodes fail.
- Resource Optimization
- Efficiently utilizes hardware resources by scheduling workloads based on resource availability.
- Infrastructure Abstraction
- Decouples applications from underlying infrastructure, enabling portability across environments.
Examples of Kubernetes Usage
1. Deploying an Application
Create a Deployment
kubectl create deployment nginx-deployment --image=nginx
Expose the Deployment
kubectl expose deployment nginx-deployment --type=NodePort --port=80
View the Application
- Get the NodePort:
kubectl get service nginx-deployment - Access the application using the Node IP and NodePort.
2. Scaling an Application
Scale the Deployment
kubectl scale deployment nginx-deployment --replicas=3
Verify Scaling
kubectl get pods
3. Using ConfigMaps and Secrets
Create a ConfigMap
kubectl create configmap app-config --from-literal=key=value
Create a Pod Using the ConfigMap
apiVersion: v1
kind: Pod
metadata:
name: configmap-pod
spec:
containers:
- name: app-container
image: nginx
env:
- name: APP_KEY
valueFrom:
configMapKeyRef:
name: app-config
key: key
Apply the Pod Configuration
kubectl apply -f configmap-pod.yaml
Advantages of Kubernetes
- Scalability: Efficiently scales applications to meet varying demands.
- Resilience: Self-healing capabilities ensure application availability.
- Portability: Runs across on-premises and cloud environments.
- Automation: Automates repetitive tasks like deployment and scaling.
- Resource Utilization: Optimizes hardware usage.
This document provides an in-depth understanding of Kubernetes, its architecture, commands, and practical examples.