Room 06
YOUR FIRST POD
The Pod Workshop
- Welcome to the pod factory floor. Pods are the smallest deployable unit in Kubernetes.
- Create pods both imperatively and declaratively to prove your skills.
📜 Mission Briefing
- Create a pod named
hello-k8susing thenginx:alpineimage: - Verify the pod is Running:
kubectl get pods. - Now create a pod from the YAML file
pod-challenge.yamlin this room. - The YAML pod has an environment variable
SECRET_WORD- exec into the pod and read it. - The password is the value of
SECRET_WORD.
Key Commands
| Command | Purpose |
|---|---|
kubectl run NAME --image=IMAGE |
Create a pod imperatively |
kubectl apply -f FILE.yaml |
Create from YAML manifest |
kubectl get pods |
List all pods |
kubectl get pod NAME -o yaml |
View pod YAML |
kubectl describe pod NAME |
Detailed pod info |
kubectl logs NAME |
View pod logs |
kubectl exec -it NAME -- /bin/sh |
Shell into pod |
kubectl delete pod NAME |
Delete a pod |
kubectl run NAME --image=IMG --dry-run=client -o yaml |
Generate YAML |
How Pods Work
# pod.yaml - A basic pod specification
apiVersion: v1
kind: Pod
metadata:
name: my-pod
labels:
app: my-app
version: "1.0"
spec:
containers:
- name: main
image: nginx:alpine
ports:
- containerPort: 80
env:
- name: APP_ENV
value: "production"
resources:
requests:
memory: "64Mi"
cpu: "250m"
limits:
memory: "128Mi"
cpu: "500m"
# Create a pod imperatively
kubectl run my-nginx --image=nginx:alpine --port=80
# Generate YAML without creating (dry-run)
kubectl run my-nginx --image=nginx:alpine --dry-run=client -o yaml > pod.yaml
# Apply a YAML manifest
kubectl apply -f pod.yaml
# Check pod status
kubectl get pods -o wide
# View pod logs
kubectl logs my-nginx
kubectl logs my-nginx -f # follow logs
kubectl logs my-nginx --previous # logs from crashed container
# Execute a command inside a pod
kubectl exec my-nginx -- ls /usr/share/nginx/html
kubectl exec -it my-nginx -- /bin/sh # interactive shell
# Port-forward to access pod locally
kubectl port-forward my-nginx 8080:80
Hints
Hint 2
Exec into the pod and read the environment variable: