DEV Community

Aisalkyn Aidarova
Aisalkyn Aidarova

Posted on

Pods Deployments ReplicaSets StatefulSets Storage Troubleshooting

πŸš€ JumpToTech Kubernetes Core Hands-On Lab

Objective

By the end of this lab, you should understand:

  • Control Plane
  • Worker Nodes
  • Pods
  • Containers
  • Deployment
  • ReplicaSet
  • Self-healing
  • Scaling
  • Labels and selectors
  • StatefulSet
  • Stable Pod identity
  • PersistentVolume (PV)
  • PersistentVolumeClaim (PVC)
  • StorageClass
  • Basic Kubernetes troubleshooting

PART 1 β€” Understand Your Kubernetes Cluster

Before creating anything, check the cluster.

Run:

kubectl cluster-info
Enter fullscreen mode Exit fullscreen mode

Then:

kubectl get nodes
Enter fullscreen mode Exit fullscreen mode

Now:

kubectl get nodes -o wide
Enter fullscreen mode Exit fullscreen mode

Question

What are these nodes?

Answer

Nodes are machines participating in the Kubernetes cluster.

Application workloads normally run on Worker Nodes.

A simplified architecture looks like this:

                    KUBERNETES CLUSTER

                       CONTROL PLANE
                 β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                 β”‚ API Server          β”‚
                 β”‚ Scheduler           β”‚
                 β”‚ Controller Manager  β”‚
                 β”‚ etcd                β”‚
                 β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                            β”‚
                 ───────────┼──────────
                            β”‚
                β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                ↓                       ↓
          WORKER NODE 1           WORKER NODE 2
          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
          β”‚ kubelet    β”‚          β”‚ kubelet    β”‚
          β”‚ Pod        β”‚          β”‚ Pod        β”‚
          β”‚ Container  β”‚          β”‚ Container  β”‚
          β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜          β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
Enter fullscreen mode Exit fullscreen mode

Important components

API Server

Receives Kubernetes API requests.

For example:

kubectl get pods
Enter fullscreen mode Exit fullscreen mode

and:

kubectl apply -f deployment.yaml
Enter fullscreen mode Exit fullscreen mode

communicate with the Kubernetes API.

Scheduler

Decides which Worker Node should run a newly created unscheduled Pod.

Controller Manager

Runs controllers that continuously work to make the actual state match the desired state.

etcd

Stores Kubernetes cluster state.

kubelet

Runs on each Worker Node and makes sure assigned Pods are running.


PART 2 β€” Create a Standalone Pod

Create a new directory:

mkdir kubernetes-core-lab
cd kubernetes-core-lab
Enter fullscreen mode Exit fullscreen mode

Create:

nano pod.yaml
Enter fullscreen mode Exit fullscreen mode

Add:

apiVersion: v1
kind: Pod

metadata:
  name: nginx-pod
  labels:
    app: nginx

spec:
  containers:
    - name: nginx
      image: nginx:1.27
      ports:
        - containerPort: 80
Enter fullscreen mode Exit fullscreen mode

Save the file.

Apply it:

kubectl apply -f pod.yaml
Enter fullscreen mode Exit fullscreen mode

Check:

kubectl get pods
Enter fullscreen mode Exit fullscreen mode

You should see:

NAME        READY   STATUS    RESTARTS   AGE
nginx-pod   1/1     Running   0          ...
Enter fullscreen mode Exit fullscreen mode

Now:

kubectl get pods -o wide
Enter fullscreen mode Exit fullscreen mode

Question

What additional information do you see?

You should see information including:

IP
NODE
Enter fullscreen mode Exit fullscreen mode

The NODE column tells you which Worker Node is running the Pod.


PART 3 β€” Inspect the Pod

Run:

kubectl describe pod nginx-pod
Enter fullscreen mode Exit fullscreen mode

Find:

Node:
Labels:
Status:
IP:
Containers:
Events:
Enter fullscreen mode Exit fullscreen mode

Important

kubectl describe is one of the most important troubleshooting commands.

When something is wrong, always look at:

Events
Enter fullscreen mode Exit fullscreen mode

near the bottom.

Now check logs:

kubectl logs nginx-pod
Enter fullscreen mode Exit fullscreen mode

PART 4 β€” Delete the Standalone Pod

Run:

kubectl delete pod nginx-pod
Enter fullscreen mode Exit fullscreen mode

Check:

kubectl get pods
Enter fullscreen mode Exit fullscreen mode

Question

Did the Pod come back?

Answer

No.

Why?

Because we created a standalone Pod.

There is no higher-level workload controller responsible for maintaining that Pod.

This demonstrates an important production concept:

Standalone Pod

DELETE POD
    ↓
Pod disappears
    ↓
Nothing recreates it
Enter fullscreen mode Exit fullscreen mode

This is one reason production applications are normally managed through higher-level workload resources such as Deployments rather than manually creating individual Pods.


PART 5 β€” Create a Deployment

Now create:

nano deployment.yaml
Enter fullscreen mode Exit fullscreen mode

Add:

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.27
          ports:
            - containerPort: 80
Enter fullscreen mode Exit fullscreen mode

Apply:

kubectl apply -f deployment.yaml
Enter fullscreen mode Exit fullscreen mode

Check:

kubectl get deployments
Enter fullscreen mode Exit fullscreen mode

Then:

kubectl get rs
Enter fullscreen mode Exit fullscreen mode

Then:

kubectl get pods
Enter fullscreen mode Exit fullscreen mode

PART 6 β€” Understand What Kubernetes Created

We created only:

Deployment
Enter fullscreen mode Exit fullscreen mode

But Kubernetes created:

Deployment
     ↓
ReplicaSet
     ↓
Pods
Enter fullscreen mode Exit fullscreen mode

Run:

kubectl get deployment
Enter fullscreen mode Exit fullscreen mode

Then:

kubectl get rs
Enter fullscreen mode Exit fullscreen mode

Then:

kubectl get pods
Enter fullscreen mode Exit fullscreen mode

Question

Did we manually create the ReplicaSet?

Answer

No.

The Deployment created and manages the ReplicaSet.

Question

Did we manually create the individual Pods?

Answer

No.

The ReplicaSet maintains the required Pod replicas.

Conceptually:

Deployment
     β”‚
     β”‚ manages
     ↓
ReplicaSet
     β”‚
     β”‚ maintains
     ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Pod #1  β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Pod #2  β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Pod #3  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
Enter fullscreen mode Exit fullscreen mode

PART 7 β€” Desired State

Look inside deployment.yaml:

replicas: 3
Enter fullscreen mode Exit fullscreen mode

This tells Kubernetes:

DESIRED STATE = 3 Pods
Enter fullscreen mode Exit fullscreen mode

Check:

kubectl get deployment nginx-deployment
Enter fullscreen mode Exit fullscreen mode

You may see something similar to:

NAME               READY   UP-TO-DATE   AVAILABLE
nginx-deployment   3/3     3            3
Enter fullscreen mode Exit fullscreen mode

Kubernetes continuously tries to make:

ACTUAL STATE
     =
DESIRED STATE
Enter fullscreen mode Exit fullscreen mode

This process is called reconciliation.


PART 8 β€” Test Kubernetes Self-Healing

Get Pods:

kubectl get pods
Enter fullscreen mode Exit fullscreen mode

Copy one Deployment Pod name.

Example:

nginx-deployment-7c79c4bf97-abcd1
Enter fullscreen mode Exit fullscreen mode

Delete it:

kubectl delete pod nginx-deployment-7c79c4bf97-abcd1
Enter fullscreen mode Exit fullscreen mode

Immediately run:

kubectl get pods
Enter fullscreen mode Exit fullscreen mode

Better:

kubectl get pods -w
Enter fullscreen mode Exit fullscreen mode

Watch carefully.

You should see a replacement Pod.

Press:

CTRL+C
Enter fullscreen mode Exit fullscreen mode

to stop watching.

What happened?

Before:

Desired = 3
Actual  = 3
Enter fullscreen mode Exit fullscreen mode

We deleted one:

Desired = 3
Actual  = 2
Enter fullscreen mode Exit fullscreen mode

Kubernetes detects the difference.

The ReplicaSet works to restore:

Desired = 3
Actual  = 3
Enter fullscreen mode Exit fullscreen mode

Interview Question

Why did the Pod come back?

Answer

Because the Deployment's ReplicaSet maintains the desired number of replicas. When one Pod disappeared, the ReplicaSet created a replacement.


PART 9 β€” Scale the Deployment

Currently:

replicas: 3
Enter fullscreen mode Exit fullscreen mode

Scale to 6:

kubectl scale deployment nginx-deployment --replicas=6
Enter fullscreen mode Exit fullscreen mode

Check:

kubectl get deployment
Enter fullscreen mode Exit fullscreen mode

Then:

kubectl get pods
Enter fullscreen mode Exit fullscreen mode

Question

How many Pods?

Answer:

6
Enter fullscreen mode Exit fullscreen mode

Now:

kubectl get rs
Enter fullscreen mode Exit fullscreen mode

The ReplicaSet should show the desired/current replica counts.

Now scale down:

kubectl scale deployment nginx-deployment --replicas=2
Enter fullscreen mode Exit fullscreen mode

Watch:

kubectl get pods -w
Enter fullscreen mode Exit fullscreen mode

Kubernetes terminates extra Pods.

Stop with:

CTRL+C
Enter fullscreen mode Exit fullscreen mode

PART 10 β€” Labels and Selectors

Run:

kubectl get pods --show-labels
Enter fullscreen mode Exit fullscreen mode

You should see labels including:

app=nginx
Enter fullscreen mode Exit fullscreen mode

Now:

kubectl get pods -l app=nginx
Enter fullscreen mode Exit fullscreen mode

Why are labels important?

Labels allow Kubernetes resources to identify/select other resources.

Our Deployment contains:

selector:
  matchLabels:
    app: nginx
Enter fullscreen mode Exit fullscreen mode

and the Pod template contains:

labels:
  app: nginx
Enter fullscreen mode Exit fullscreen mode

These must match for this Deployment.

Think:

Deployment selector
        ↓
    app=nginx
        ↓
   Matching Pods
Enter fullscreen mode Exit fullscreen mode

PART 11 β€” Deployment Update

Check the current image:

kubectl get deployment nginx-deployment \
  -o jsonpath='{.spec.template.spec.containers[0].image}'
Enter fullscreen mode Exit fullscreen mode

Now update Nginx:

kubectl set image deployment/nginx-deployment \
  nginx=nginx:1.28
Enter fullscreen mode Exit fullscreen mode

Watch:

kubectl get pods -w
Enter fullscreen mode Exit fullscreen mode

Stop with:

CTRL+C
Enter fullscreen mode Exit fullscreen mode

Check rollout:

kubectl rollout status deployment/nginx-deployment
Enter fullscreen mode Exit fullscreen mode

Check history:

kubectl rollout history deployment/nginx-deployment
Enter fullscreen mode Exit fullscreen mode

What happened?

Kubernetes performed a rollout.

A Deployment allows us to update an application while Kubernetes manages replacement of Pods according to its rollout strategy.


PART 12 β€” Rollback

Suppose our new application version has a problem.

Rollback:

kubectl rollout undo deployment/nginx-deployment
Enter fullscreen mode Exit fullscreen mode

Check:

kubectl rollout status deployment/nginx-deployment
Enter fullscreen mode Exit fullscreen mode

Then:

kubectl get pods
Enter fullscreen mode Exit fullscreen mode

Interview Question

How do you rollback a Deployment?

Answer:

kubectl rollout undo deployment/<deployment-name>
Enter fullscreen mode Exit fullscreen mode

PART 13 β€” Deployment vs StatefulSet

Now we move to StatefulSet.

Deployment Pods might look like:

nginx-deployment-76f8b987d8-x8j2p
nginx-deployment-76f8b987d8-82ksa
nginx-deployment-76f8b987d8-p91ka
Enter fullscreen mode Exit fullscreen mode

The exact generated suffixes can change.

StatefulSet Pods look like:

web-0
web-1
web-2
Enter fullscreen mode Exit fullscreen mode

StatefulSet gives Pods stable ordinal identities.

Concept:

DEPLOYMENT

Pod A
Pod B
Pod C

Pods are generally interchangeable.
Enter fullscreen mode Exit fullscreen mode

Compared with:

STATEFULSET

web-0
web-1
web-2

Each Pod has a stable identity.
Enter fullscreen mode Exit fullscreen mode

PART 14 β€” Create a StorageClass

First check existing StorageClasses:

kubectl get storageclass
Enter fullscreen mode Exit fullscreen mode

If your cluster already has a default StorageClass, record its name:

kubectl get storageclass
Enter fullscreen mode Exit fullscreen mode

Example on an AWS EKS cluster might be:

gp2
Enter fullscreen mode Exit fullscreen mode

or:

gp3
Enter fullscreen mode Exit fullscreen mode

depending on the cluster configuration.

Do not blindly create a new StorageClass if your cluster already has the correct one.

Set the StorageClass name you actually have:

export STORAGE_CLASS=gp2
Enter fullscreen mode Exit fullscreen mode

Replace gp2 if your cluster uses a different StorageClass.

Verify:

kubectl get storageclass "$STORAGE_CLASS"
Enter fullscreen mode Exit fullscreen mode

PART 15 β€” Create a StatefulSet

Create:

nano statefulset.yaml
Enter fullscreen mode Exit fullscreen mode

Add the following.

Replace gp2 with your cluster's StorageClass if necessary.

apiVersion: v1
kind: Service
metadata:
  name: nginx-headless
spec:
  clusterIP: None
  selector:
    app: nginx-stateful
  ports:
    - port: 80
      targetPort: 80
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: nginx-stateful
spec:
  serviceName: nginx-headless
  replicas: 3

  selector:
    matchLabels:
      app: nginx-stateful

  template:
    metadata:
      labels:
        app: nginx-stateful

    spec:
      containers:
        - name: nginx
          image: nginx:1.27

          ports:
            - containerPort: 80

          volumeMounts:
            - name: nginx-data
              mountPath: /usr/share/nginx/html

  volumeClaimTemplates:
    - metadata:
        name: nginx-data

      spec:
        accessModes:
          - ReadWriteOnce

        storageClassName: gp2

        resources:
          requests:
            storage: 1Gi
Enter fullscreen mode Exit fullscreen mode

Apply:

kubectl apply -f statefulset.yaml
Enter fullscreen mode Exit fullscreen mode

Watch:

kubectl get pods -w
Enter fullscreen mode Exit fullscreen mode

You should eventually see:

nginx-stateful-0
nginx-stateful-1
nginx-stateful-2
Enter fullscreen mode Exit fullscreen mode

PART 16 β€” Observe StatefulSet Identity

Run:

kubectl get statefulset
Enter fullscreen mode Exit fullscreen mode

Then:

kubectl get pods
Enter fullscreen mode Exit fullscreen mode

Notice:

nginx-stateful-0
nginx-stateful-1
nginx-stateful-2
Enter fullscreen mode Exit fullscreen mode

Compare:

DEPLOYMENT

nginx-deployment-xxxxx-abc12
nginx-deployment-xxxxx-def34
Enter fullscreen mode Exit fullscreen mode

with:

STATEFULSET

nginx-stateful-0
nginx-stateful-1
nginx-stateful-2
Enter fullscreen mode Exit fullscreen mode

This stable identity is one of the most important StatefulSet concepts.


PART 17 β€” PVC and PV

Run:

kubectl get pvc
Enter fullscreen mode Exit fullscreen mode

You may see:

nginx-data-nginx-stateful-0
nginx-data-nginx-stateful-1
nginx-data-nginx-stateful-2
Enter fullscreen mode Exit fullscreen mode

Check:

kubectl get pv
Enter fullscreen mode Exit fullscreen mode

Now:

kubectl get storageclass
Enter fullscreen mode Exit fullscreen mode

Understand the relationship:

StatefulSet
     ↓
nginx-stateful-0
     ↓
PVC
     ↓
PV
     ↓
Storage
Enter fullscreen mode Exit fullscreen mode

PVC

PersistentVolumeClaim.

The application requests storage.

PV

PersistentVolume.

Represents persistent storage available/bound for Kubernetes use.

StorageClass

Describes a class of storage and, with dynamic provisioning, tells Kubernetes which provisioner and parameters to use to create storage.


PART 18 β€” Write Data

Let's demonstrate why persistent storage matters.

Run:

kubectl exec nginx-stateful-0 -- \
  sh -c 'echo "Hello from JumpToTech StatefulSet" > /usr/share/nginx/html/index.html'
Enter fullscreen mode Exit fullscreen mode

Check:

kubectl exec nginx-stateful-0 -- \
  cat /usr/share/nginx/html/index.html
Enter fullscreen mode Exit fullscreen mode

Expected:

Hello from JumpToTech StatefulSet
Enter fullscreen mode Exit fullscreen mode

PART 19 β€” Delete the StatefulSet Pod

Delete:

kubectl delete pod nginx-stateful-0
Enter fullscreen mode Exit fullscreen mode

Watch:

kubectl get pods -w
Enter fullscreen mode Exit fullscreen mode

You should see:

nginx-stateful-0
Enter fullscreen mode Exit fullscreen mode

created again.

Notice the name.

It is still:

nginx-stateful-0
Enter fullscreen mode Exit fullscreen mode

not a random new identity.

Once it is Running, check the file:

kubectl exec nginx-stateful-0 -- \
  cat /usr/share/nginx/html/index.html
Enter fullscreen mode Exit fullscreen mode

If storage was correctly provisioned and reattached, you should still see:

Hello from JumpToTech StatefulSet
Enter fullscreen mode Exit fullscreen mode

This demonstrates two different concepts

Stable identity
+
Persistent storage
Enter fullscreen mode Exit fullscreen mode

Do not confuse them.

StatefulSet gives the Pod stable identity.

PVC/PV provide persistent storage.


PART 20 β€” Compare Deployment and StatefulSet

Feature Deployment StatefulSet
Common use Stateless apps Stateful apps
Pod identity Interchangeable/generated Stable ordinal identity
Example Web/API Databases/clustered stateful systems
Typical names app-xxxxx-xxxxx app-0, app-1
Scaling Designed for interchangeable replicas Can use ordered behavior
Storage Can use persistent storage Commonly paired with per-Pod PVCs
Rollout Deployment strategy StatefulSet strategy

Important:

A StatefulSet does not automatically make a database production-ready.

The database itself must still be configured correctly for replication, backups, failover, security, and recovery.


PART 21 β€” BREAK THE APPLICATION

Now we intentionally create problems.

This is the most important section.

A DevOps engineer does not only deploy applications.

A DevOps engineer must be able to troubleshoot them.


TROUBLESHOOTING LAB 1 β€” Wrong Image

Run:

kubectl set image deployment/nginx-deployment \
  nginx=nginx:this-image-does-not-exist
Enter fullscreen mode Exit fullscreen mode

Wait:

kubectl get pods
Enter fullscreen mode Exit fullscreen mode

You may see:

ErrImagePull
Enter fullscreen mode Exit fullscreen mode

followed by:

ImagePullBackOff
Enter fullscreen mode Exit fullscreen mode

What do you do?

First:

kubectl describe pod <problem-pod-name>
Enter fullscreen mode Exit fullscreen mode

Go to:

Events
Enter fullscreen mode Exit fullscreen mode

You should find information about the image pull failure.

Question

Is Kubernetes broken?

Answer

No.

The requested container image/tag cannot be successfully pulled.

Fix:

kubectl set image deployment/nginx-deployment \
  nginx=nginx:1.27
Enter fullscreen mode Exit fullscreen mode

Check:

kubectl rollout status deployment/nginx-deployment
Enter fullscreen mode Exit fullscreen mode

TROUBLESHOOTING LAB 2 β€” CrashLoopBackOff

Create:

nano broken-pod.yaml
Enter fullscreen mode Exit fullscreen mode

Add:

apiVersion: v1
kind: Pod

metadata:
  name: crash-demo

spec:
  containers:
    - name: crash
      image: busybox:1.36
      command:
        - sh
        - -c
        - echo "Application starting"; sleep 3; exit 1
Enter fullscreen mode Exit fullscreen mode

Apply:

kubectl apply -f broken-pod.yaml
Enter fullscreen mode Exit fullscreen mode

Watch:

kubectl get pods -w
Enter fullscreen mode Exit fullscreen mode

Eventually the container will repeatedly restart and may show:

CrashLoopBackOff
Enter fullscreen mode Exit fullscreen mode

Stop watching:

CTRL+C
Enter fullscreen mode Exit fullscreen mode

Now troubleshoot:

kubectl describe pod crash-demo
Enter fullscreen mode Exit fullscreen mode

Then:

kubectl logs crash-demo
Enter fullscreen mode Exit fullscreen mode

And:

kubectl logs crash-demo --previous
Enter fullscreen mode Exit fullscreen mode

Important troubleshooting pattern

Something is wrong
        ↓
kubectl get pods
        ↓
kubectl describe pod
        ↓
Check Events
        ↓
kubectl logs
        ↓
kubectl logs --previous
Enter fullscreen mode Exit fullscreen mode

TROUBLESHOOTING LAB 3 β€” Pending PVC

Do this as a demonstration rather than leaving broken resources in the cluster.

Create:

nano bad-pvc.yaml
Enter fullscreen mode Exit fullscreen mode

Add:

apiVersion: v1
kind: PersistentVolumeClaim

metadata:
  name: broken-pvc

spec:
  accessModes:
    - ReadWriteOnce

  storageClassName: storage-class-does-not-exist

  resources:
    requests:
      storage: 1Gi
Enter fullscreen mode Exit fullscreen mode

Apply:

kubectl apply -f bad-pvc.yaml
Enter fullscreen mode Exit fullscreen mode

Check:

kubectl get pvc
Enter fullscreen mode Exit fullscreen mode

You should see it remain:

Pending
Enter fullscreen mode Exit fullscreen mode

Investigate:

kubectl describe pvc broken-pvc
Enter fullscreen mode Exit fullscreen mode

Then:

kubectl get storageclass
Enter fullscreen mode Exit fullscreen mode

Lesson

If you see:

Pod Pending
Enter fullscreen mode Exit fullscreen mode

and that Pod needs a PVC, check:

kubectl get pvc
kubectl describe pvc <pvc-name>
kubectl get storageclass
Enter fullscreen mode Exit fullscreen mode

Delete the intentionally broken claim:

kubectl delete pvc broken-pvc
Enter fullscreen mode Exit fullscreen mode

PART 22 β€” The Kubernetes Troubleshooting Mindset

Do not randomly delete things.

Follow a process.

Step 1

Check:

kubectl get pods
Enter fullscreen mode Exit fullscreen mode

Step 2

Get more information:

kubectl get pods -o wide
Enter fullscreen mode Exit fullscreen mode

Step 3

Describe the problematic resource:

kubectl describe pod <pod-name>
Enter fullscreen mode Exit fullscreen mode

Step 4

Read:

Events
Enter fullscreen mode Exit fullscreen mode

Step 5

Check application logs:

kubectl logs <pod-name>
Enter fullscreen mode Exit fullscreen mode

For a previously crashed container:

kubectl logs <pod-name> --previous
Enter fullscreen mode Exit fullscreen mode

Step 6

If storage is involved:

kubectl get pvc
kubectl get pv
kubectl get storageclass
kubectl describe pvc <pvc-name>
Enter fullscreen mode Exit fullscreen mode

Step 7

If Deployment is involved:

kubectl get deployment
kubectl get rs
kubectl rollout status deployment/<name>
kubectl rollout history deployment/<name>
Enter fullscreen mode Exit fullscreen mode

PART 23 β€” Final Architecture

You should now understand this:

USER
 β”‚
 β”‚ kubectl apply
 ↓
API SERVER
 β”‚
 ↓
Desired state stored/processed
 β”‚
 ↓
CONTROLLERS
 β”‚
 ↓
Deployment
 β”‚
 ↓
ReplicaSet
 β”‚
 ↓
Pods
 β”‚
 ↓
SCHEDULER
 β”‚
 β”‚ chooses Node
 ↓
WORKER NODE
 β”‚
 ↓
kubelet
 β”‚
 ↓
Container Runtime
 β”‚
 ↓
Container Running
Enter fullscreen mode Exit fullscreen mode

For a StatefulSet:

StatefulSet
     β”‚
     β”œβ”€β”€ nginx-stateful-0
     β”‚         β”‚
     β”‚         └── PVC β†’ PV β†’ Storage
     β”‚
     β”œβ”€β”€ nginx-stateful-1
     β”‚         β”‚
     β”‚         └── PVC β†’ PV β†’ Storage
     β”‚
     └── nginx-stateful-2
               β”‚
               └── PVC β†’ PV β†’ Storage
Enter fullscreen mode Exit fullscreen mode

PART 24 β€” Student Challenge

Do this section without instructor help.

Challenge 1

Create a Deployment named:

student-web
Enter fullscreen mode Exit fullscreen mode

Requirements:

Image: nginx:1.27
Replicas: 4
Label: app=student-web
Container port: 80
Enter fullscreen mode Exit fullscreen mode

Verify:

kubectl get deployment
kubectl get rs
kubectl get pods
Enter fullscreen mode Exit fullscreen mode

Challenge 2

Delete one Pod.

Prove Kubernetes recreates it.


Challenge 3

Scale:

4 β†’ 7
Enter fullscreen mode Exit fullscreen mode

Then:

7 β†’ 2
Enter fullscreen mode Exit fullscreen mode

Challenge 4

Update Nginx to:

nginx:1.28
Enter fullscreen mode Exit fullscreen mode

Watch the rollout.


Challenge 5

Break the image intentionally.

Use:

nginx:does-not-exist
Enter fullscreen mode Exit fullscreen mode

Troubleshoot it.

Then repair it.


Challenge 6

Explain:

Deployment
    ↓
ReplicaSet
    ↓
Pod
    ↓
Container
Enter fullscreen mode Exit fullscreen mode

Challenge 7

Explain the difference between:

Deployment
Enter fullscreen mode Exit fullscreen mode

and:

StatefulSet
Enter fullscreen mode Exit fullscreen mode

without looking at your notes.


FINAL INTERVIEW QUESTIONS

1. What is a Pod?

A Pod is Kubernetes' smallest deployable unit and contains one or more containers.

2. What is a Deployment?

A Deployment manages stateless application workloads and declaratively manages ReplicaSets and application updates.

3. What is a ReplicaSet?

A ReplicaSet maintains the desired number of matching Pod replicas.

4. What happens when a Deployment Pod dies?

Its ReplicaSet works to create a replacement so the desired replica count is restored.

5. What is StatefulSet?

A workload controller designed for applications that need stable Pod identities and often stable per-Pod storage.

6. Deployment vs StatefulSet?

Deployment replicas are generally interchangeable.

StatefulSet Pods have stable ordinal identities such as:

mysql-0
mysql-1
mysql-2
Enter fullscreen mode Exit fullscreen mode

7. What does Scheduler do?

It chooses an appropriate Node for an unscheduled Pod.

8. What does kubelet do?

It runs on each Worker Node and works with the container runtime to ensure assigned Pods are running.

9. What does API Server do?

It exposes the Kubernetes API and is the central entry point for API operations.

10. What is etcd?

It is the distributed key-value store used by Kubernetes to store cluster state.

11. What is PV?

PersistentVolume β€” a Kubernetes resource representing persistent storage.

12. What is PVC?

PersistentVolumeClaim β€” a request for persistent storage.

13. What does PVC Bound mean?

The claim has been successfully bound to a PersistentVolume.

14. What does Pending mean?

The resource cannot yet proceed to its required running/bound state. You need to investigate why.

15. What is ImagePullBackOff?

Kubernetes cannot successfully pull the requested container image and is backing off between retry attempts.

16. What is CrashLoopBackOff?

A container repeatedly starts, fails, and Kubernetes delays subsequent restart attempts.

17. First command when a Pod has a problem?

Start with:

kubectl get pods
Enter fullscreen mode Exit fullscreen mode

Then investigate:

kubectl describe pod <pod-name>
Enter fullscreen mode Exit fullscreen mode

and:

kubectl logs <pod-name>
Enter fullscreen mode Exit fullscreen mode

18. Where do you look in kubectl describe?

Especially:

Events
Enter fullscreen mode Exit fullscreen mode

19. How do you see which Node runs a Pod?

kubectl get pods -o wide
Enter fullscreen mode Exit fullscreen mode

20. Explain what happens after kubectl apply -f deployment.yaml.

A strong answer:

kubectl sends an API request to the Kubernetes API Server.

The requested desired state is persisted in the cluster.

The Deployment controller observes the Deployment and manages the appropriate ReplicaSet.

The ReplicaSet works to create the required Pods.

The Scheduler assigns unscheduled Pods to suitable Nodes.

The kubelet on each selected Worker Node observes the assigned Pod and works with the container runtime to start the required containers.

Kubernetes controllers continuously reconcile actual state with desired state.


CLEANUP

Delete the lab resources:

kubectl delete -f deployment.yaml
kubectl delete -f statefulset.yaml
kubectl delete -f broken-pod.yaml
kubectl delete pod nginx-pod --ignore-not-found
kubectl delete pvc broken-pvc --ignore-not-found
kubectl delete deployment student-web --ignore-not-found
Enter fullscreen mode Exit fullscreen mode

Check:

kubectl get pods
kubectl get deployment
kubectl get statefulset
kubectl get pvc
Enter fullscreen mode Exit fullscreen mode

What You Must Remember

CONTROL PLANE
     ↓
Manages the cluster

WORKER NODE
     ↓
Runs workloads

POD
     ↓
Runs container(s)

DEPLOYMENT
     ↓
Manages ReplicaSets and stateless application rollout

REPLICASET
     ↓
Maintains Pod replicas

STATEFULSET
     ↓
Stable Pod identity

PVC
     ↓
Requests storage

PV
     ↓
Represents persistent storage
Enter fullscreen mode Exit fullscreen mode

And the most important Kubernetes idea:

        DESIRED STATE
              ↓
       Kubernetes checks
              ↓
         ACTUAL STATE
              ↓
      Something is wrong?
              ↓
        RECONCILIATION
              ↓
   Move actual state toward
       the desired state
Enter fullscreen mode Exit fullscreen mode

Top comments (0)