Your first Pod

Run something, break it, look inside it.

Beginner20 min · lesson 3 of 21
Lesson files
The scripts, test data and local test servers this lesson uses, exactly as they ran on the lab machine (2 files, 1 KB): firstpod.tar.gz. The lab VM shares no folders with your computer, so fetch them inside the VM: cd ~/lab && curl -fsSLO https://secopslog.com/lab-files/k8s-fund/firstpod.tar.gz && tar -xzf firstpod.tar.gz, which creates ~/lab/firstpod/. SHA-256: 457c117690981c02523fc70bf052beba11a33794a3458fa9d335f6f7af88c378

Give Kubernetes a Pod whose image does not exist and kubectl still answers pod/web created, with a success exit code. With docker run the pull error would have landed in your terminal at once. Here kubectl apply only hands the request to the cluster, the real work happens later on some node, and any failure is recorded in the cluster, not printed for you.

So the first Pod in this course breaks on purpose. You find out why from the cluster's own records, fix it, and then look inside the running container.

A Pod from a file

A Pod wraps one or more containers. This file asks for a Pod named web with one nginx container. Look closely at the image tag, because it contains a deliberate typo:

pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: web
labels:
app: web
spec:
containers:
- name: nginx
image: nginx:1.30.60-alpine
ports:
- containerPort: 80

apiVersion and kind say what sort of object this is, metadata.name names it, and spec.containers lists the containers, much like the arguments to docker run. The tag should be 1.30.6-alpine. It says 1.30.60-alpine, which does not exist.

ubuntu@secopslog-k8s:~/lab/firstpod · Kubernetes 1.37
$ kubectl apply -f pod.yaml && kubectl get pod web
pod/web created NAME READY STATUS RESTARTS AGE web 0/1 ContainerCreating 0 0s

The Pod exists and is ContainerCreating: it already has a node, and that node is busy getting the image. Run kubectl get pod web again every few seconds. Within about 20 seconds the status changes:

ubuntu@secopslog-k8s:~/lab/firstpod · Kubernetes 1.37
$ kubectl get pod web
NAME READY STATUS RESTARTS AGE web 0/1 ImagePullBackOff 0 17s

ImagePullBackOff means the pull failed and Kubernetes is waiting before it tries again. RESTARTS stays at 0 because the container never started.

Read the events

Every Pod collects events: short messages from the scheduler and the kubelet about what they did. kubectl describe prints them at the end of its output. Here sed cuts that output down to the Events part only:

ubuntu@secopslog-k8s:~/lab/firstpod · Kubernetes 1.37
$ kubectl describe pod web | sed -n '/^Events:/,$p'
Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal Scheduled 18s default-scheduler Successfully assigned default/web to lab-worker2 Warning Failed 15s kubelet spec.containers{nginx}: Failed to pull image "nginx:1.30.60-alpine": rpc error: code = NotFound desc = failed to pull and unpack image "docker.io/library/nginx:1.30.60-alpine": failed to resolve reference "docker.io/library/nginx:1.30.60-alpine": docker.io/library/nginx:1.30.60-alpine: not found Warning Failed 15s kubelet spec.containers{nginx}: Error: ErrImagePull Normal BackOff 15s kubelet spec.containers{nginx}: Back-off pulling image "nginx:1.30.60-alpine" Warning Failed 15s kubelet spec.containers{nginx}: Error: ImagePullBackOff Normal Pulling 2s (x2 over 18s) kubelet spec.containers{nginx}: Pulling image "nginx:1.30.60-alpine"

Read them from top to bottom. The scheduler placed the Pod on a worker (Scheduled). The kubelet on that worker tried to pull the image (Pulling). Docker Hub answered not found, and the kubelet reported ErrImagePull. It then waits before trying again, which is the BackOff event and the ImagePullBackOff status. (x2 over 18s) means the same event happened twice in 18 seconds. The wait grows with each failure, up to five minutes, so a Pod with a bad tag never fixes itself.

kubectl events --for pod/web prints the same events on their own, which is handier when the describe output is long:

ubuntu@secopslog-k8s:~/lab/firstpod · Kubernetes 1.37
$ kubectl events --for pod/web
LAST SEEN TYPE REASON OBJECT MESSAGE 19s Normal Scheduled Pod/web Successfully assigned default/web to lab-worker2 16s Normal BackOff Pod/web Back-off pulling image "nginx:1.30.60-alpine" 16s Warning Failed Pod/web Error: ImagePullBackOff 3s (x2 over 19s) Normal Pulling Pod/web Pulling image "nginx:1.30.60-alpine" 0s (x2 over 16s) Warning Failed Pod/web Failed to pull image "nginx:1.30.60-alpine": rpc error: code = NotFound desc = failed to pull and unpack image "docker.io/library/nginx:1.30.60-alpine": failed to resolve reference "docker.io/library/nginx:1.30.60-alpine": docker.io/library/nginx:1.30.60-alpine: not found 0s (x2 over 16s) Warning Failed Pod/web Error: ErrImagePull

Note the exact message. not found here means the repository exists but has no such tag. A misspelled repository name, or a private one you cannot read, usually shows an authorization error instead.

Fix it

Fix the tag in the file and apply it again. A Pod lets you change its image while it exists, so the same Pod is updated in place. kubectl wait --for=condition=Ready then blocks until the Pod reports Ready, or until the timeout, and -o wide adds the IP and node columns:

ubuntu@secopslog-k8s:~/lab/firstpod · Kubernetes 1.37
$ sed -i 's/nginx:1.30.60-alpine/nginx:1.30.6-alpine/' pod.yaml && grep image: pod.yaml
image: nginx:1.30.6-alpine
$ kubectl apply -f pod.yaml && kubectl wait --for=condition=Ready pod/web --timeout=180s
pod/web configured pod/web condition met
$ kubectl get pod web -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES web 1/1 Running 0 55s 10.244.1.2 lab-worker2 <none> <none>
$ kubectl events --for pod/web
LAST SEEN TYPE REASON OBJECT MESSAGE 56s Normal Scheduled Pod/web Successfully assigned default/web to lab-worker2 53s Normal BackOff Pod/web Back-off pulling image "nginx:1.30.60-alpine" 53s Warning Failed Pod/web Error: ImagePullBackOff 40s (x2 over 56s) Normal Pulling Pod/web Pulling image "nginx:1.30.60-alpine" 37s (x2 over 53s) Warning Failed Pod/web Failed to pull image "nginx:1.30.60-alpine": rpc error: code = NotFound desc = failed to pull and unpack image "docker.io/library/nginx:1.30.60-alpine": failed to resolve reference "docker.io/library/nginx:1.30.60-alpine": docker.io/library/nginx:1.30.60-alpine: not found 37s (x2 over 53s) Warning Failed Pod/web Error: ErrImagePull 36s Normal Pulling Pod/web Pulling image "nginx:1.30.6-alpine" 1s Normal Pulled Pod/web Successfully pulled image "nginx:1.30.6-alpine" in 35.422s (35.422s including waiting). Image size: 25987805 bytes. 1s Normal Created Pod/web Container created 1s Normal Started Pod/web Container started

pod/web configured means the existing Pod was changed, not replaced. It is now 1/1 Running. In the events the old failures stay in the history, and at the bottom comes the new sequence: Pulling the right tag, Pulled with how long the download took, then Created and Started. The image came from Docker Hub here. If it is already on the node, you see already present on machine instead of Pulling.

Look inside

Three commands cover most of what you need once a Pod runs. logs shows what the container wrote to its output, the same as docker logs:

ubuntu@secopslog-k8s:~/lab/firstpod · Kubernetes 1.37
$ kubectl logs web
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/ /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh 10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf 10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf /docker-entrypoint.sh: Sourcing /docker-entrypoint.d/15-local-resolvers.envsh /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh /docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh /docker-entrypoint.sh: Configuration complete; ready for start up 2026/11/11 08:41:56 [notice] 1#1: using the "epoll" event method 2026/11/11 08:41:56 [notice] 1#1: nginx/1.30.6 2026/11/11 08:41:56 [notice] 1#1: built by gcc 15.2.0 (Alpine 15.2.0) 2026/11/11 08:41:56 [notice] 1#1: OS: Linux 7.0.0-38-generic 2026/11/11 08:41:56 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 2147483584:2147483584 2026/11/11 08:41:56 [notice] 1#1: start worker processes 2026/11/11 08:41:56 [notice] 1#1: start worker process 35 2026/11/11 08:41:56 [notice] 1#1: start worker process 36 2026/11/11 08:41:56 [notice] 1#1: start worker process 37 2026/11/11 08:41:56 [notice] 1#1: start worker process 38

These are nginx's start-up lines, ending with the worker processes it started. exec runs a command inside the container, like docker exec. Everything after -- is the command:

ubuntu@secopslog-k8s:~/lab/firstpod · Kubernetes 1.37
$ kubectl exec web -- nginx -v
nginx version: nginx/1.30.6
$ kubectl exec web -- sh -c 'hostname; ls /usr/share/nginx/html'
web 50x.html index.html

The hostname inside the container is the Pod name, web, and nginx serves its pages from /usr/share/nginx/html.

The Pod's IP address only works inside the cluster. To reach it from your machine while testing, kubectl port-forward opens a local port and tunnels it to the Pod. It keeps running until you stop it. You can run it in a second terminal, or start it in the background with & as below, where kill $! stops the last background command:

ubuntu@secopslog-k8s:~/lab/firstpod · Kubernetes 1.37
$ kubectl port-forward pod/web 8080:80 & sleep 3 curl -s localhost:8080 | grep "<title>" kill $!
Forwarding from 127.0.0.1:8080 -> 80 Forwarding from [::1]:8080 -> 80 Handling connection for 8080 <title>Welcome to nginx!</title>
$ kubectl logs web --tail=1
127.0.0.1 - - [11/Nov/2026:08:42:00 +0000] "GET / HTTP/1.1" 200 896 "-" "curl/8.18.0" "-"

port-forward reports that it listens on 127.0.0.1:8080, then Handling connection once curl connects, and curl gets nginx's welcome page. In nginx's access log the request seems to come from 127.0.0.1, because port-forward delivers it from inside the Pod. A browser on localhost:8080 works just as well while the tunnel is open.

Delete it

ubuntu@secopslog-k8s:~/lab/firstpod · Kubernetes 1.37
$ kubectl delete pod web && kubectl get pods
pod "web" deleted from default namespace No resources found in default namespace.

A Pod you created yourself is gone once you delete it. Nothing brings it back, which is the difference from the Deployment in lesson 1.

Hands-on

Find out how long a change made inside a container lasts. pod.yaml now has the right tag.

1. Create the Pod and wait for it: kubectl apply -f pod.yaml && kubectl wait --for=condition=Ready pod/web --timeout=120s

2. Replace the start page: kubectl exec web -- sh -c 'echo hello from inside the Pod > /usr/share/nginx/html/index.html'

3. Fetch the page: kubectl port-forward pod/web 8080:80 &, then curl -s localhost:8080, then kill $!

4. Replace the Pod: kubectl delete pod web && kubectl apply -f pod.yaml && kubectl wait --for=condition=Ready pod/web --timeout=120s

5. Fetch the page again with the same three commands as in step 3

6. Clean up: kubectl delete -f pod.yaml, then kubectl get pods

What you should see: step 1 ends with pod/web condition met, and step 2 prints nothing. In step 3 curl prints hello from inside the Pod. Step 4 shows the old Pod deleted and a new one created and ready. In step 5 curl gets the default page again, with the title Welcome to nginx!: your change is gone, because a new Pod starts from the image. Lesson 17, Volumes, shows how to keep files. Step 6 ends with No resources found in default namespace.

Remember

A success message from kubectl apply only means the cluster stored your request. When a Pod does not run, its events say why, and once it runs, logs, exec and port-forward let you look inside.

Quick check
01You apply a Pod and kubectl prints pod/web created, but kubectl get pod web later shows ImagePullBackOff. What did the success message tell you?
Incorrect — No pull had happened yet. The image tag did not even exist.
Incorrect — The API server does not contact registries. The kubelet found out about the tag later.
Incorrect — Starting happens after apply returns. The Pod was still not running right afterwards.
Correct — Pulling and starting happen later on a node, and their failures show up as events.
02A Pod's events show Failed to pull image ... not found. What is the most likely cause?
Incorrect — A full disk gives a different error. not found came from the registry, about the name.
Correct — 1.30.60-alpine instead of 1.30.6-alpine gave exactly this message in the lab.
Incorrect — The container never started. RESTARTS stayed at 0 and there was no Started event.
Incorrect — The Scheduled event shows a node was found before the pull failed.
03You change a file inside a running Pod with kubectl exec, then delete the Pod and apply the same YAML again. What happens to your change?
Incorrect — A name is not storage. The hands-on curl showed the default page again.
Incorrect — Nothing is copied. The new container starts from the image.
Correct — The hands-on showed Welcome to nginx! after the Pod was recreated.
Incorrect — Node does not matter. Container files do not outlive the container.

Related