Deploy Your First App to Kubernetes, Hands-On
Your kind cluster from lesson 17 is running, but so far it holds only system pods. In this lesson you deploy your first app to Kubernetes: three nginx pods behind a Service. You open the app from your laptop, then delete a pod to watch the cluster repair itself, and scale up.
Set up the stall: a Deployment with three replicas
Here is the whole lab at a glance: each box shows a command and the output that proves it worked.
First make sure kubectl points at your kind cluster: kubectl config current-context must print kind-lab. If it prints another name, run kubectl config use-context kind-lab.
The lab folder holds two manifests: YAML files that describe objects you want to exist. deployment.yaml is lesson 10's Deployment plus one addition, the container's port:
apiVersion: apps/v1
kind: Deployment
metadata:
name: web
spec:
replicas: 3
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
spec:
containers:
- name: web
image: nginx:1.27-alpine
ports:
- containerPort: 80
As in lesson 10, replicas: 3 asks for three identical pods, the template stamps the label app: web on each, and the selector counts pods carrying it. The pinned tag keeps your output matching this page. containerPort: 80 records where nginx listens; it does not open anything by itself.
Put up the signboard: a ClusterIP Service
Pods are replaced with new IP addresses, so callers need the stable name a Service gives them (lesson 11). service.yaml sends port 80 of the Service web to port 80 of every ready pod labelled app: web:
apiVersion: v1
kind: Service
metadata:
name: web
spec:
type: ClusterIP
selector:
app: web
ports:
- port: 80
targetPort: 80
type: ClusterIP is the default, written out for clarity: the Service gets a virtual IP that works only inside the cluster. In the diagram, notice that names never link these objects; only the label does.
Now create both objects. kubectl apply sends each file to the API server, which stores it as desired state, and you can repeat -f for several files:
kubectl apply -f deployment.yaml -f service.yaml
You should see one line per object: deployment.apps/web created, then service/web created. created means stored, not yet running. Applying again prints unchanged and does no harm. error: the path "deployment.yaml" does not exist means you are in the wrong folder.
Inspect what is running
One kubectl get can list several kinds of object, separated by commas, and deploy and svc are short names. After half a minute or so, kubectl get deploy,pods,svc should print this; your hashes, suffixes, IPs and ages will differ:
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/web 3/3 3 3 40s
NAME READY STATUS RESTARTS AGE
pod/web-6d4b8c7f9d-2xkqn 1/1 Running 0 40s
pod/web-6d4b8c7f9d-9tq4m 1/1 Running 0 40s
pod/web-6d4b8c7f9d-ldv8h 1/1 Running 0 40s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 15m
service/web ClusterIP 10.96.120.15 <none> 80/TCP 40s
3/3 and three 1/1 Running pods mean the stall is open; the kubernetes Service is the API server's own. ContainerCreating means the image is still downloading. ImagePullBackOff means it cannot be pulled: check the tag and your connection. For detail, kubectl describe prints an object's settings and its events, the cluster's record of what happened to it. Use a pod name from your own list:
kubectl describe pod web-6d4b8c7f9d-2xkqn
You should see something like this, heavily trimmed. The events tell the pod's story: the scheduler placed it on your node, then the kubelet pulled the image and started the container:
Name: web-6d4b8c7f9d-2xkqn
Labels: app=web
pod-template-hash=6d4b8c7f9d
Controlled By: ReplicaSet/web-6d4b8c7f9d
...
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 50s default-scheduler Successfully assigned default/web-6d4b8c7f9d-2xkqn to lab-control-plane
Normal Pulled 44s kubelet Successfully pulled image "nginx:1.27-alpine" in 5.8s (5.8s including waiting). Image size: 20991234 bytes.
Normal Created 44s kubelet Container created
Normal Started 44s kubelet Container started
Another pod's events may say the image was already present on machine instead. Controlled By names the owning ReplicaSet, and a NotFound error means a mistyped name. Finally, kubectl logs web-6d4b8c7f9d-2xkqn prints everything the container printed; for nginx, that is its logs. You should see its start-up lines, trimmed here:
/docker-entrypoint.sh: Configuration complete; ready for start up
2026/11/28 10:14:03 [notice] 1#1: nginx/1.27.5
2026/11/28 10:14:03 [notice] 1#1: start worker processes
The first line is the image's start-up script; the others come from nginx. Each later request adds an access line to the log of the pod that served it.
Reach the app from your laptop
The ClusterIP works only inside the cluster, and the kind node is a container, so your browser cannot reach either. kubectl port-forward opens a tunnel instead: it listens on a port on your laptop and carries each connection to a pod. Run it and leave it running:
kubectl port-forward svc/web 8080:80
8080:80 means local port 8080 to Service port 80. kubectl uses the Service only to choose one of its pods and turn port 80 into that pod's container port. You should see:
Forwarding from 127.0.0.1:8080 -> 80
Forwarding from [::1]:8080 -> 80
It listens on localhost only, so nobody else on your network can connect. In the diagram, notice that the traffic never touches the ClusterIP: it travels through the API server and the kubelet straight into the chosen pod.
Now open http://localhost:8080 in a browser, or ask for the page with curl in a second terminal (-s hides its progress meter):
curl -s localhost:8080
You should see the top of nginx's welcome page (trimmed), while the port-forward terminal prints Handling connection for 8080:
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
Run kubectl logs on each pod again: only the chosen one has a new "GET / HTTP/1.1" 200 line, from 127.0.0.1, because the tunnel ends inside that pod. address already in use means another program has port 8080, so use 8081:80. unable to forward port because pod is not running means you were early: wait for Running.
Self-healing, scaling and clean-up
Press Ctrl+C to stop port-forward first. It is tied to the pod it chose: if that pod goes, the session ends with lost connection to pod. Now delete one pod, using a name from your own list, and look again:
kubectl delete pod web-6d4b8c7f9d-2xkqn
kubectl get pods
You should see pod "web-6d4b8c7f9d-2xkqn" deleted from default namespace, then three pods again, one with a new name and an age of seconds. The ReplicaSet counted two where three were wanted and made a replacement, and the Service's list of pods updated itself.
Scaling changes the desired number itself. This tells the Deployment to keep five pods:
kubectl scale deployment/web --replicas=5
It prints deployment.apps/web scaled, and kubectl get pods soon lists five Running pods, all behind the same Service. The file still says 3, so applying it again scales back. To clean up, delete everything the two files created:
kubectl delete -f deployment.yaml -f service.yaml
You should see deployment.apps "web" deleted from default namespace and the same for service "web". Deleting the Deployment removes its ReplicaSet and pods too, so kubectl get pods soon finds no resources. Keep the cluster for the next lesson.
Check yourself
A teammate runs curl http://10.96.120.15, the Service's ClusterIP, on their laptop, and it never answers. Why, and what works instead?
A ClusterIP is virtual and exists only in the cluster nodes' rules, so nothing outside the cluster can reach it. From the laptop, use port-forward and localhost:8080.
While port-forward runs, you delete a pod and port-forward stops with lost connection to pod. Is the Service broken?
No. Port-forward tunnels to the one pod it picked at the start. The ReplicaSet has already replaced it and the Service still selects the others, so run port-forward again.
You misspell the Service's selector as app: Web. kubectl apply succeeds. What breaks, and why no error?
Labels are case-sensitive, so the Service selects no pods and in-cluster callers get no answer. A selector that matches nothing is still valid, so the API accepts it; lesson 11's kubectl get endpointslices shows no pod IPs.