# Experiment 10 – Container and Kubernetes Monitoring

Objective: Monitor a containerized application running in a prepared Minikube environment, identify pod failures or resource-pressure conditions, and verify corrective actions.

## Viva Questions and Answers

1\. What is containerization?

Containerization is a method of packaging an application along with its dependencies into an isolated, lightweight unit called a container. It ensures the application runs consistently across different environments.

2\. What is Docker?

Docker is a platform used to build, package, and run applications inside containers. It uses images as templates to create containers.

3\. What is Kubernetes?

Kubernetes is an open-source container orchestration platform. It automates container deployment, scaling, management, and recovery.

4\. What is Minikube?

Minikube is a tool that runs a local Kubernetes cluster, usually on a single machine. It is commonly used for learning and testing Kubernetes.

5\. What is a Kubernetes cluster?

A Kubernetes cluster is a collection of nodes that run containerized applications. It consists of:

- Control Plane: Manages the cluster and makes scheduling decisions.
- Worker Nodes: Run application workloads inside pods.

6\. What is a Node?

A node is a machine (physical or virtual) that runs containerized applications. It provides CPU, memory, and other resources required by pods.

7\. What is a Pod?

A Pod is the smallest deployable unit in Kubernetes. It contains one or more containers that share network resources and can share storage.

8\. What is a Deployment?

A Deployment manages application replicas and ensures the desired number of pods are running. It also supports rolling updates and rollback.

9\. Which `kubectl` commands are used to monitor Kubernetes resources?

`kubectl` is the command-line tool used to communicate with a Kubernetes cluster.

```
kubectl get nodes
kubectl get pods
kubectl get deployments
kubectl get pods -A
```

These commands show the status of nodes, pods, deployments, and pods across all namespaces.

10\. How do you retrieve logs from a pod?

Use:

```
kubectl logs <pod-name>
```

For a pod with multiple containers:

```
kubectl logs <pod-name> -c <container-name>
```

Logs help identify application errors, crashes, and other failures.

11\. How do you check resource utilization of pods and nodes?

Use:

```
kubectl top pods
kubectl top nodes
```

These commands display CPU and memory utilization. They require an available metrics component, commonly Metrics Server.

12\. What are common Kubernetes pod states?

- Pending: Pod has not yet been scheduled or started.
- Running: Pod is running on a node.
- Succeeded: Pod completed successfully.
- Failed: Pod terminated unsuccessfully.
- CrashLoopBackOff: Container repeatedly crashes and Kubernetes delays restarting it.

13\. What is CrashLoopBackOff and how do you troubleshoot it?

It occurs when a container repeatedly starts and crashes. We can investigate using:

```
kubectl describe pod <pod-name>
kubectl logs <pod-name>
kubectl logs <pod-name> --previous
```

We should check application errors, configuration, missing dependencies, and resource limitations.

14\. What is resource pressure in Kubernetes?

Resource pressure occurs when a node or pod has insufficient CPU, memory, or storage resources. For example, high memory consumption can cause a container to be terminated with an `OOMKilled` reason.

15\. How do you perform and verify corrective action in Kubernetes?

First, identify the cause using pod status, logs, events, and resource metrics. Then apply an approved correction, such as fixing configuration or restarting a deployment.

Example:

```
kubectl rollout restart deployment <deployment-name>
kubectl get pods
kubectl rollout status deployment <deployment-name>
```

The final commands help verify that the pods are recreated and the deployment becomes available.

## Last-Minute Revision

| Term / Command         | Meaning                                  |
| ---------------------- | ---------------------------------------- |
| Docker                 | Builds and runs containers               |
| Kubernetes             | Container orchestration                  |
| Minikube               | Local Kubernetes cluster                 |
| kubectl                | Kubernetes command-line tool             |
| Cluster                | Collection of nodes                      |
| Node                   | Machine running workloads                |
| Pod                    | Smallest deployable Kubernetes unit      |
| Deployment             | Manages pod replicas and updates         |
| `kubectl get pods`     | Lists pods                               |
| `kubectl describe pod` | Shows detailed pod information           |
| `kubectl logs`         | Retrieves pod logs                       |
| `kubectl top pods`     | Shows pod CPU and memory                 |
| Pending                | Not yet running                          |
| Running                | Currently running                        |
| CrashLoopBackOff       | Container repeatedly crashes             |
| OOMKilled              | Container terminated due to memory limit |

## Important for Practical Viva

Focus especially on:

1. Difference between Docker, Kubernetes, and Minikube.
2. Difference between Node, Pod, and Deployment.
3. Commands to check nodes, pods, and deployments.
4. Retrieving pod logs and understanding error messages.
5. Checking CPU and memory using `kubectl top`.
6. Troubleshooting `CrashLoopBackOff`, `Pending`, and `OOMKilled`.
7. Applying a corrective action and verifying recovery.

Based on Experiment 10 of your CS414 lab question bank.&#x20;

CS414_ITIMM_Lab_ESE.pdf
