Skip to content

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

  1. Create a pod named hello-k8s using the nginx:alpine image:
    kubectl run hello-k8s --image=nginx:alpine
    
  2. Verify the pod is Running: kubectl get pods.
  3. Now create a pod from the YAML file pod-challenge.yaml in this room.
  4. The YAML pod has an environment variable SECRET_WORD - exec into the pod and read it.
  5. 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 1

Apply the challenge YAML:

kubectl apply -f pod-challenge.yaml

Hint 2

Exec into the pod and read the environment variable:

kubectl exec -it challenge-pod -- env | grep SECRET_WORD

Hint 3

Or extract it directly:

kubectl exec challenge-pod -- printenv SECRET_WORD


🔓 Unlock Room 07

openssl enc -aes-256-cbc -d -a -pbkdf2 \
        -in ../room_07/README             \
        -out ../room_07/README.txt        \
        -pass pass:PASSWORD
cat ../room_07/README.txt