Kubernetes, also called K8s, is an open-source container orchestration platform. It automates the deployment, scaling, networking, recovery, and management of containerized applications. (Kubernetes)
Instead of manually managing containers across multiple servers, Kubernetes groups those servers into a cluster and maintains the application’s desired state.
The provided notes correctly emphasize orchestration, scaling, self-healing, load balancing, fault tolerance, and rollbacks as important Kubernetes capabilities.
Why Is Kubernetes Needed?
Docker can build and run containers, but operating many containers across multiple servers creates additional problems:
- What happens when a container crashes?
- How do users reach changing Pod IP addresses?
- How do we run multiple application copies?
- How do we update an application without downtime?
- How do we distribute containers across servers?
Kubernetes solves these problems through scheduling, controllers, Services, health checks, scaling, and declarative configuration.
Docker vs. Kubernetes
| Docker | Kubernetes |
|---|---|
| Builds and runs containers | Orchestrates containerized applications |
| Commonly operates on one host | Manages workloads across a cluster |
| Creates container images | Schedules Pods on worker nodes |
| Does not provide complete cluster orchestration | Provides scaling, recovery, networking, and updates |
Kubernetes does not require Docker Engine. Modern clusters use Container Runtime Interface-compatible runtimes such as containerd or CRI-O. (Kubernetes)
Kubernetes Architecture
A Kubernetes cluster contains:
- Control plane: Manages the cluster.
- Worker nodes: Run application workloads inside Pods.
The architecture diagram in the provided notes shows the control plane managing Pods distributed across multiple nodes.
Control Plane Components
kube-apiserver
- Front end of the Kubernetes control plane
- Receives requests from
kubectl, YAML manifests, and API clients - Validates and processes Kubernetes API requests
etcd
- Distributed key-value database
- Stores cluster configuration and state
- Acts as the cluster’s source of truth
kube-scheduler
- Finds suitable worker nodes for newly created Pods
- Considers resources, constraints, affinity, and scheduling policies
kube-controller-manager
- Runs controllers that compare actual state with desired state
- Creates or replaces resources when the two states do not match
These are the principal control-plane components in the current Kubernetes architecture. (Kubernetes)
Worker Node Components
kubelet
- Agent running on each worker node
- Ensures assigned Pods and containers are running
Container runtime
- Pulls images
- Starts and stops containers
- Examples include
containerdand CRI-O
kube-proxy
- Maintains network rules used to implement Kubernetes Services
- Does not normally assign Pod IP addresses
Pod networking and IP allocation are generally handled through the cluster’s networking or CNI implementation. (Kubernetes)
How Kubernetes Processes a Deployment
When you run:
kubectl apply -f deployment.yaml
The following process occurs:
kubectlsends the manifest to the API server.- The API server validates the request.
- The desired configuration is stored in
etcd. - Controllers detect that new Pods are required.
- The scheduler selects worker nodes.
- The kubelet asks the container runtime to start the containers.
- Kubernetes continuously compares actual state with desired state.
This is called declarative management: you define the required result, and Kubernetes determines how to achieve it.
Important Kubernetes Objects
Pod
A Pod is the smallest deployable unit in Kubernetes. It usually contains one container, although it can contain multiple tightly coupled containers sharing networking and storage.
Pods are temporary. Applications should normally be managed through higher-level controllers rather than standalone Pods.
ReplicaSet
A ReplicaSet maintains a specified number of identical Pod replicas.
In normal application deployments, you usually create a Deployment, which manages the ReplicaSet automatically.
Deployment
A Deployment manages stateless application Pods and provides:
- Replica management
- Rolling updates
- Rollbacks
- Self-healing through replacement Pods
- Declarative application updates
The provided interview notes identify Deployments as the resource responsible for managing Pod replicas, updates, and rollbacks.
Service
Pod IP addresses can change when Pods are recreated. A Service provides a stable network endpoint and distributes traffic to matching Pods through labels and selectors. (Kubernetes)
Common Service types:
- ClusterIP: Internal cluster access
- NodePort: Access through a static port on every node
- LoadBalancer: External access through a supported load balancer
ConfigMap
A ConfigMap stores non-sensitive configuration such as:
- Environment settings
- Application properties
- Configuration files
- Command-line arguments
It separates environment configuration from the container image. (Kubernetes)
Secret
A Secret stores sensitive information such as:
- Passwords
- API tokens
- Certificates
- Registry credentials
⚠️ Base64 encoding is not encryption. Kubernetes Secrets are stored unencrypted in etcd by default unless encryption at rest is configured. Use encryption, RBAC, restricted access, and an external secret-management solution where appropriate. (Kubernetes)
Namespace
Namespaces logically divide cluster resources between teams, projects, or environments.
Examples:
developmenttestingproduction
PersistentVolume and PersistentVolumeClaim
- PersistentVolume: Storage available to the cluster
- PersistentVolumeClaim: A workload’s request for storage
- StorageClass: Defines how storage should be dynamically provisioned
Persistent storage allows data to survive Pod replacement. (Kubernetes)
Health Checks
Kubernetes supports three important probes:
- Startup probe: Checks whether the application has started
- Readiness probe: Determines whether the Pod should receive traffic
- Liveness probe: Determines whether the container should be restarted
Scaling
Manual Scaling
kubectl scale deployment web-app --replicas=5
Automatic Scaling
A HorizontalPodAutoscaler can automatically change the number of replicas based on metrics such as CPU or memory usage. Autoscaling must be configured; it does not happen automatically for every Deployment. (Kubernetes)
Simple Deployment and Service Example
apiVersion: apps/v1
kind: Deployment
metadata:
name: web-app
spec:
replicas: 2
selector:
matchLabels:
app: web-app
template:
metadata:
labels:
app: web-app
spec:
containers:
- name: nginx
image: nginx:stable-alpine
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: web-service
spec:
selector:
app: web-app
ports:
- port: 80
targetPort: 80
type: ClusterIP
Apply it:
kubectl apply -f web-app.yaml
Check the resources:
kubectl get deployments
kubectl get pods
kubectl get services
Essential kubectl Commands
kubectl get nodes
kubectl get pods -A
kubectl describe pod <pod-name>
kubectl logs <pod-name>
kubectl exec -it <pod-name> -- /bin/sh
kubectl apply -f app.yaml
kubectl delete -f app.yaml
kubectl rollout status deployment/<name>
kubectl rollout history deployment/<name>
kubectl rollout undo deployment/<name>
kubectl scale deployment/<name> --replicas=3
Common Troubleshooting Process
When an application is not working:
- Check Pod status:
kubectl get pods
- Review events and configuration:
kubectl describe pod <pod-name>
- Check application logs:
kubectl logs <pod-name>
- Verify Service selectors:
kubectl get service
kubectl get endpointslices
- Check rollout status:
kubectl rollout status deployment/<name>
Important Interview Questions
What is Kubernetes?
Kubernetes is an open-source platform that automates the deployment, scaling, networking, and management of containerized applications.
What is the difference between a Pod and a Deployment?
A Pod runs one or more containers. A Deployment manages multiple Pod replicas and supports updates, scaling, recovery, and rollbacks.
What is a Service?
A Service provides stable networking and load balancing for a group of Pods selected through labels.
What is the difference between ConfigMap and Secret?
A ConfigMap stores non-sensitive configuration. A Secret stores sensitive information, but additional security controls such as encryption at rest and RBAC are still required.
What is the difference between readiness and liveness probes?
Readiness determines whether traffic should reach a container. Liveness determines whether Kubernetes should restart it.
What is the difference between ClusterIP and NodePort?
ClusterIP exposes an application only inside the cluster. NodePort exposes it through a static port on each worker node.
What is declarative configuration?
Declarative configuration defines the required state in YAML or JSON. Kubernetes continuously works to maintain that state.
How do you roll back a failed Deployment?
kubectl rollout undo deployment/<deployment-name>
The supplied Q&A also covers Services, ConfigMaps, Secrets, namespaces, scaling, storage, probes, Jobs, CronJobs, and rolling updates.
Final Takeaway
For job and interview preparation, focus first on:
- Pods
- Deployments and ReplicaSets
- Services
- Control plane and worker-node architecture
- ConfigMaps and Secrets
- Volumes
- Health probes
- Scaling and rollbacks
- YAML manifests
- Troubleshooting with
kubectl
Understanding the relationship between Pod → Deployment → Service gives beginners the highest practical value.