0
0
Kubernetesdevops~30 mins

kubectl exec for container access in Kubernetes - Mini Project: Build & Apply

Choose your learning style9 modes available
Using kubectl exec to Access Containers
📖 Scenario: You are managing a Kubernetes cluster with a running pod. Sometimes you need to access the container inside the pod to check logs, run commands, or debug issues.This project will teach you how to use kubectl exec to access a container inside a pod.
🎯 Goal: Learn how to use kubectl exec to run commands inside a container in a Kubernetes pod.
📋 What You'll Learn
A Kubernetes cluster with kubectl configured
A pod named myapp-pod running with a container named myapp-container
Basic command line knowledge
💡 Why This Matters
🌍 Real World
Accessing containers inside pods is a common task for debugging, inspecting logs, or running maintenance commands in Kubernetes environments.
💼 Career
Knowing how to use <code>kubectl exec</code> is essential for Kubernetes administrators, DevOps engineers, and developers working with containerized applications.
Progress0 / 4 steps
1
Create a pod manifest file
Create a file named myapp-pod.yaml with a pod definition that has the pod name myapp-pod and a container named myapp-container using the image nginx.
Kubernetes
Need a hint?

Use the apiVersion as v1, kind as Pod, and specify metadata.name and spec.containers with the correct names and image.

2
Apply the pod manifest to create the pod
Use the command kubectl apply -f myapp-pod.yaml to create the pod named myapp-pod in the cluster.
Kubernetes
Need a hint?

Use kubectl apply -f myapp-pod.yaml to create the pod from the manifest file.

3
Use kubectl exec to run a command inside the container
Use kubectl exec with the pod name myapp-pod and container name myapp-container to run the command ls /usr/share/nginx/html inside the container.
Kubernetes
Need a hint?

Use kubectl exec <pod-name> -c <container-name> -- <command> format to run commands inside a container.

4
Access an interactive shell inside the container
Use kubectl exec with the pod name myapp-pod and container name myapp-container to start an interactive bash shell inside the container. Use the -it flags and the command /bin/bash.
Kubernetes
Need a hint?

Use kubectl exec -it <pod-name> -c <container-name> -- /bin/bash to open an interactive shell.