👤
📦 Module 1 5 Labs Est. 45 min

Core Concepts

Learn the fundamental building blocks of Kubernetes: Pods, Deployments, Services, and Replicasets.

Theory: The Building Blocks

Kubernetes (K8s) doesn't run containers directly; it wraps one or more containers into a higher-level structure called a Pod.

1. Pods

The smallest deployable unit. Usually, 1 Pod = 1 Container. They share network IP, storage, and lifecycle.

2. ReplicaSets & Deployments

If a Pod dies, it doesn't come back. To ensure high availability, you use a ReplicaSet to state "I always want 3 copies of this Pod running". A Deployment is a wrapper around a ReplicaSet that makes updating the application (e.g., v1 -> v2) smooth and rollback-able.

Deep Dive: Kubernetes Architecture

A Kubernetes Cluster consists of a Control Plane (the brain) and Worker Nodes (the muscle). The Control Plane makes global decisions about the cluster, while worker nodes actually run the pods.

graph TD; subgraph Control Plane API[Kube-API Server] ETCD[(etcd)] SCHED[Kube-Scheduler] CM[Controller Manager] API --- ETCD API --- SCHED API --- CM end subgraph Worker Node 1 K1[Kubelet] KP1[Kube-Proxy] P1((Pod A)) K1 --- P1 end subgraph Worker Node 2 K2[Kubelet] KP2[Kube-Proxy] P2((Pod B)) K2 --- P2 end API <--> K1 API <--> K2
YAML
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
        image: nginx:1.14.2
        ports:
        - containerPort: 80

Hands-on Labs

Complete the following tasks to master this module. Toggle the checklist items once you successfully run the logic.

Lab 1: Your First Pod
Deploy a simple Nginx Pod Imperatively using the kubectl run command.
kubectl run my-first-pod --image=nginx
Lab 2: Listing Resources
Check the status of your running pods to see if it successfully initialized.
kubectl get pods
Lab 3: Extracting Details
Inspect the internal state of the pod, including its internal IP and event logs.
kubectl describe pod my-first-pod
Lab 4: Creating a Deployment
Create a Deployment with 3 replicas of the nginx image to ensure high availability.
kubectl create deployment nginx-deploy --image=nginx --replicas=3
Lab 5: Scaling the Deployment
Scale the deployment up from 3 replicas to 5 dynamically without editing files.
kubectl scale deployment nginx-deploy --replicas=5

Interview Prep: Core Concepts

Q: What exactly happens under the hood when you run `kubectl run`?

The kubectl client validates the request and sends it to the API server. The API server stores the Pod object in etcd. The Scheduler notices the unassigned pod and assigns it to a Node. The Kubelet on that Node instructs the container runtime (like containerd) to pull the image and start the container.

Q: What is the difference between a Container and a Pod?

A container is a runtime instance of an image (like Docker). A Pod is the smallest deployable K8s object, which acts as a wrapper that can encapsulate one or more tightly coupled containers sharing network IP and storage volumes.

Module Knowledge Check

Question 1

Terminal Simulator
K8s.Learn Simulator connected.
Type 'help' for available commands.
root@k8s-master:~#