0
0
Kubernetesdevops~30 mins

Executing commands in Pods in Kubernetes - Mini Project: Build & Apply

Choose your learning style9 modes available
Executing Commands in Kubernetes Pods
📖 Scenario: You are managing a Kubernetes cluster. Sometimes you need to run commands inside a running Pod to check its status or debug issues.
🎯 Goal: Learn how to execute commands inside a Kubernetes Pod using kubectl exec.
📋 What You'll Learn
Create a Pod manifest with a specific name and image
Add a label to the Pod for easy selection
Use kubectl exec to run a command inside the Pod
Display the output of the command executed inside the Pod
💡 Why This Matters
🌍 Real World
Running commands inside Pods helps troubleshoot and inspect running applications without needing to redeploy or restart them.
💼 Career
Kubernetes administrators and DevOps engineers often use <code>kubectl exec</code> to debug issues and verify application states inside containers.
Progress0 / 4 steps
1
Create a Pod manifest
Create a YAML file named mypod.yaml that defines a Pod with the name mypod using the image busybox. The Pod should run the command sleep 3600 to keep it alive.
Kubernetes
Need a hint?

Use apiVersion: v1, kind: Pod, and specify metadata.name as mypod. Under spec.containers, set the container name, image, and command.

2
Add a label to the Pod
Add a label app: testpod under metadata.labels in the mypod.yaml file.
Kubernetes
Need a hint?

Under metadata, add a labels section with app: testpod.

3
Execute a command inside the Pod
Use the command kubectl exec mypod -- ls / to list the root directory inside the Pod.
Kubernetes
Need a hint?

Use kubectl exec followed by the Pod name mypod, then -- and the command ls /.

4
Display the output of the command
Run the command kubectl exec mypod -- ls / in your terminal and write the output exactly as it appears.
Kubernetes
Need a hint?

Run the command in your terminal and copy the exact output listing the root directories inside the Pod.