Kubernetes Tutorial for Beginners: Container Orchestration Explained

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

DockerKubernetes
Builds and runs containersOrchestrates containerized applications
Commonly operates on one hostManages workloads across a cluster
Creates container imagesSchedules Pods on worker nodes
Does not provide complete cluster orchestrationProvides 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 containerd and 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:

  1. kubectl sends the manifest to the API server.
  2. The API server validates the request.
  3. The desired configuration is stored in etcd.
  4. Controllers detect that new Pods are required.
  5. The scheduler selects worker nodes.
  6. The kubelet asks the container runtime to start the containers.
  7. 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

(Kubernetes)

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:

  • development
  • testing
  • production

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

(Kubernetes)

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:

  1. Check Pod status:
kubectl get pods
  1. Review events and configuration:
kubectl describe pod <pod-name>
  1. Check application logs:
kubectl logs <pod-name>
  1. Verify Service selectors:
kubectl get service
kubectl get endpointslices
  1. 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:

  1. Pods
  2. Deployments and ReplicaSets
  3. Services
  4. Control plane and worker-node architecture
  5. ConfigMaps and Secrets
  6. Volumes
  7. Health probes
  8. Scaling and rollbacks
  9. YAML manifests
  10. Troubleshooting with kubectl

Understanding the relationship between Pod → Deployment → Service gives beginners the highest practical value.


Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top