Troubleshoot a Website That Is Not Accessible
Scenario
The Northwind Books online catalog runs in the bookshop namespace of a Kubernetes cluster.
After the last deployment, the Pods are running, but the website does not open.
Task
Find out why the website is not accessible and fix it. Make sure that the Deployment describes the application correctly. Keep the existing health checks.
When you are done, check the website:
curl http://cplane-01:30333
Fix the problem with changes to the Deployment and the Service only. Leave all other objects as they are.
The environment may need up to 1 minute to set up.
Hint 1: When a Pod is ready
A Pod that runs is not always ready.
The kubelet runs the container's readiness probe, and the Pod receives traffic from a Service only after the probe passes.
kubectl describe pod shows the probe and the events of its failures.
Keep the probe, and make it check the port nginx serves.
Documentation
Hint 2: What the container listens on
The Deployment manifest does not decide the port nginx listens on. The application's own configuration does. Look at the files mounted into the nginx container. Every object that sends a request to nginx must use this port.
Documentation
Hint 3: Where the traffic goes
A Service sends traffic only to the ready Pods listed in its endpoints.
Check whether bookshop-service has any endpoints.
If it has none, compare how the Service selects Pods with the labels the Pods actually carry.
Then check which port the endpoints point to.
Documentation
Hint 4: What the Deployment tells others
People and tools read the ports that a container declares in the Pod template.
kubectl describe prints them, and kubectl expose copies them into a new Service.
Compare the declared port with the port you found in Hint 2.
Documentation
âš’ Test Cases
Three faults break the website.
The readiness probe checks port 80, while nginx listens on port 3333, so the Pods never become ready.
The Service selector does not match the Pod labels.
The Service also forwards traffic to port 80.
The fourth fix is good production practice: the Deployment must declare containerPort: 3333.
Understanding the challenge
The path of a request
curl http://cplane-01:30333 passes five stops before it reaches nginx.
Each stop reads a different field, and this challenge breaks three of them:
curl http://cplane-01:30333
│
â–¼
[1] NodePort 30333 on cplane-01 Service bookshop-service, type NodePort OK
│ kube-proxy on the node catches the connection
â–¼
[2] Service selector: app=bookstore the Pods carry app=bookshop BROKEN
│ the selector picks the Pods, and their IPs become the endpoints
â–¼
[3] Readiness probe: port 80 only ready Pods receive traffic BROKEN
│ kube-proxy sends traffic only to ready endpoints
â–¼
[4] Endpoint: Pod IP + targetPort 80 for example 10.42.2.2:80 BROKEN
│ the packet goes to this port inside the Pod
â–¼
[5] nginx: listen 3333 from the nginx-config ConfigMap OK
Next to this path, the Deployment declares containerPort: 80.
No packet reads this field, so it does not break the request.
It is still wrong, and the last part of this section explains why it is worth changing.
What each stop does
- The NodePort. A Service of type
NodePortopens the same port (here30333) on every node of the cluster. A request to any node on that port goes to the Service. kube-proxy runs on every node and turns each Service into packet forwarding rules (iptables or nftables). These rules replace the destination of the request with the address of one of the Service's endpoints. The kernel of the node rewrites the packet and sends it on to the Pod, which may run on another node. - The selector. A Service does not list its Pods by name.
It has a
selector, which is a set of labels. The EndpointSlice controller looks for Pods that carry all of these labels and writes their IP addresses into EndpointSlice objects. If no Pod matches the selector, the EndpointSlices stay empty, and the Service has nowhere to send traffic. - The readiness probe. The EndpointSlice controller marks each address as ready or not ready, based on the Pod's readiness.
The kubelet decides the readiness with the container's readiness probe, here an HTTP request to
/on port80. kube-proxy sends traffic only to the ready addresses. A probe that checks the wrong port never passes, so the Pod runs but never gets traffic. - The targetPort. The endpoint address is the Pod IP plus the
targetPortof the Service. Kubernetes does not check whether anything listens on that port. It only forwards the traffic there. - The application. The process in the container decides which port it listens on.
For nginx, this is the
listendirective innginx.conf, and here that file comes from thenginx-configConfigMap. If nothing listens on thetargetPort, the Pod's kernel rejects the connection.
What you see while you fix it
This solution starts from the symptom you see first and follows it inward.
curl prints the same error until all three faults are fixed:
- Before any fix: the Pods show
0/1in theREADYcolumn, and the events show that the readiness probe fails. - After the Deployment fix: the Pods show
1/1, but the Service still has no endpoints. - After the selector fix: the endpoints appear and are ready, but they point to port
80. - After the targetPort fix: the traffic reaches nginx on port
3333, and the page loads.
This order is also a good debugging order for any Service: check the Pods first, then the endpoints, then the port the application really listens on.
The port fields
The port fields of a Service and a Pod are easy to mix up:
nodePort(Service): the port opened on every node, reachable from outside the cluster.port(Service): the port of the Service's ClusterIP, used inside the cluster (bookshop-service:80).targetPort(Service): the port in the Pod that the traffic goes to. This one must match the application.readinessProbe.httpGet.port(Pod template): the port the kubelet checks. This one must match the application too.containerPort(Pod template): the port the container declares it uses.
Why the Deployment's containerPort is worth changing
containerPort is a declaration in the Pod spec. It does not control the network:
- It does not open a port. nginx listens on
3333because of its config, whatever the Deployment says. - It does not close a port either. The API reference says: "Not specifying a port here DOES NOT prevent that port from being exposed."
- Nothing on the path of the request reads it when the Service and the probe use numeric ports, as they do here.
So the wrong value does not break the traffic. It still matters, because tools, named ports, and people read it. Step 5 explains each case.
Changing only containerPort does not fix the website.
The field is not on the path of the request.
The Service's targetPort and the readiness probe's port are the fields that must match the port nginx listens on.
All commands in this solution run on dev-machine.
The output in these steps comes from a real run. Your Pod names, IP addresses, and ages will be different.
Step 1: Reproduce the problem
curl http://cplane-01:30333
curl: (7) Failed to connect to cplane-01 port 30333 after 0 ms: Couldn't connect to server
The connection fails right away, so the request does not reach any web server.
Step 2: Check the Pods
kubectl get pods -n bookshop
NAME READY STATUS RESTARTS AGE
bookshop-web-5c88d5cfb8-4z5db 0/1 Running 0 10s
bookshop-web-5c88d5cfb8-j7zz4 0/1 Running 0 10s
Both Pods are stuck at 0/1 with the Running status.
The container runs, but Kubernetes does not consider it ready to receive traffic.
A Service sends traffic only to ready Pods, so this alone is enough to break the website.
Step 3: Check the events of a Pod
kubectl describe pod -n bookshop bookshop-web-5c88d5cfb8-4z5db
The output below is shortened to the relevant lines:
Port: 80/TCP
State: Running
Ready: False
Readiness: http-get http://:80/ delay=0s timeout=1s period=5s successThreshold=1 failureThreshold=3
...
Conditions:
Type Status
Ready False
ContainersReady False
...
Events:
Warning Unhealthy 2s (x3 over 4s) kubelet spec.containers{nginx}: Readiness probe failed: Get "http://10.42.2.2:80/": dial tcp 10.42.2.2:80: connect: connection refused
The readiness probe fails.
The kubelet sends GET / to port 80 every 5 seconds, and the connection is refused every time.
Nothing listens on port 80 in the Pod, so the probe never passes, and the Pod never becomes ready.
The next question is which port nginx really listens on.
Step 4: Find the port nginx listens on
The containerPort in the Deployment is only information for people and tools.
It does not change the port the application listens on.
Look at the volumes of the Deployment to see which configuration nginx reads:
kubectl describe deployment bookshop-web -n bookshop
The output below is shortened to the Pod template:
Pod Template:
Labels: app=bookshop
Containers:
nginx:
Image: nginx:1.30.7-alpine
Port: 80/TCP
Host Port: 0/TCP
Readiness: http-get http://:80/ delay=0s timeout=1s period=5s successThreshold=1 failureThreshold=3
Environment: <none>
Mounts:
/etc/nginx/nginx.conf from nginx-config-volume (rw,path="nginx.conf")
/usr/share/nginx/html from html-volume (rw)
Volumes:
nginx-config-volume:
Type: ConfigMap (a volume populated by a ConfigMap)
Name: nginx-config
Optional: false
html-volume:
Type: ConfigMap (a volume populated by a ConfigMap)
Name: bookshop-html
Optional: false
The nginx-config ConfigMap replaces the default nginx.conf:
kubectl get configmap nginx-config -n bookshop -o yaml
The output below is shortened. The kind and metadata parts are left out:
apiVersion: v1
data:
nginx.conf: |
# Managed by the platform team. Do not edit.
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
server {
listen 3333;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html;
}
}
}
immutable: true
nginx listens on port 3333.
The readiness probe, the declared container port, and the Service all still assume port 80.
You can confirm it from inside a Pod. netstat lists the ports with a listening socket:
kubectl exec deploy/bookshop-web -n bookshop -- netstat -tln
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:3333 0.0.0.0:* LISTEN
Only port 3333 is open. Nothing listens on port 80.
The Deployment mounts this ConfigMap with subPath: nginx.conf.
A subPath mount places one key of the ConfigMap at one file path, here /etc/nginx/nginx.conf, and the rest of /etc/nginx stays as the image ships it.
In the nginx:alpine images, the default server that listens on port 80 is defined in /etc/nginx/conf.d/default.conf.
The image's own nginx.conf includes that file, but the custom one does not.
So nginx starts with only the server block from the ConfigMap, which listens on port 3333.
The ConfigMap is marked immutable: true, and the API server rejects every change to its data:
kubectl patch configmap nginx-config -n bookshop -p '{"data":{"nginx.conf":"test"}}'
The ConfigMap "nginx-config" is invalid: data: Forbidden: field is immutable when `immutable` is set
Teams use immutable ConfigMaps to protect shared configuration from accidental edits, and because the kubelet does not need to watch them for changes. Deleting the ConfigMap and creating a new one with another port is not part of the fix. The task allows changes only in the Deployment and the Service, and the checks reject a replaced ConfigMap. So the Deployment and the Service have to follow the port nginx listens on.
Step 5: Fix the readiness probe and the containerPort
The Deployment disagrees with nginx in two places:
- The readiness probe checks port
80, so the Pods never become ready. This one breaks the website. - The container declares
containerPort: 80. This one does not break the traffic.
The probe must check 3333, the port nginx serves.
Keep the probe: it is good production practice, and the fourth check needs it.
Without a probe, the kubelet marks a Pod ready as soon as its container starts, even if nginx is still starting or fails to load its config.
The Deployment should declare 3333 too, because other parts of the cluster trust this value:
- Tools build objects from it.
kubectl exposecopiescontainerPortinto a new Service. With80, every Service built this way sends traffic to a port where nothing listens. - Named ports resolve through it. A Service
targetPort, a probeport, or a NetworkPolicy port can use a port name, for examplehttp. Kubernetes finds the number incontainerPort. With80, the name points to a port where nothing listens. - People read it.
kubectl describeshowsPort: 80/TCP. The next person who debugs the app trusts that value and repeats the mistake.
Change both in the same edit, so that the Deployment needs only one rollout:
kubectl edit deployment bookshop-web -n bookshop
ports:
- containerPort: 3333
protocol: TCP
readinessProbe:
failureThreshold: 3
httpGet:
path: /
port: 3333
scheme: HTTP
periodSeconds: 5
successThreshold: 1
timeoutSeconds: 1
The editor shows the default values of the probe too (failureThreshold, scheme, successThreshold, timeoutSeconds). Leave them as they are, and save the file.
The probe sends GET / to port 3333 every 5 seconds.
Any status from 200 to 399 counts as a success.
A tcpSocket probe on port 3333 also passes the check, but the HTTP probe tests more: nginx must also find and serve the page.
kubectl expose creates a Service from a Deployment and takes the ports from containerPort.
The --dry-run=client -o yaml flags only print the Service without creating it:
kubectl expose deployment bookshop-web -n bookshop --name=bookshop-test --dry-run=client -o yaml
With containerPort: 80, the printed Service has port: 80 and targetPort: 80, so it sends traffic to a port where nothing listens.
After this fix, the same command prints port: 3333 and targetPort: 3333.
Step 6: Wait for the rollout and test again
Any change to the Pod template starts a rollout. The ports and the probes of a running Pod cannot be changed anyway, so the Deployment replaces the Pods one by one:
kubectl rollout status deployment/bookshop-web -n bookshop
Waiting for deployment "bookshop-web" rollout to finish: 0 out of 2 new replicas have been updated...
Waiting for deployment "bookshop-web" rollout to finish: 1 out of 2 new replicas have been updated...
Waiting for deployment "bookshop-web" rollout to finish: 1 out of 2 new replicas have been updated...
Waiting for deployment "bookshop-web" rollout to finish: 1 out of 2 new replicas have been updated...
Waiting for deployment "bookshop-web" rollout to finish: 1 old replicas are pending termination...
Waiting for deployment "bookshop-web" rollout to finish: 1 old replicas are pending termination...
Waiting for deployment "bookshop-web" rollout to finish: 1 old replicas are pending termination...
Waiting for deployment "bookshop-web" rollout to finish: 1 old replicas are pending termination...
deployment "bookshop-web" successfully rolled out
kubectl get pods -n bookshop
NAME READY STATUS RESTARTS AGE
bookshop-web-54456559b8-66tkp 1/1 Running 0 28s
bookshop-web-54456559b8-7nd7w 1/1 Running 0 35s
The new Pods pass the probe on port 3333 and show 1/1.
Test the website again:
curl http://cplane-01:30333
curl: (7) Failed to connect to cplane-01 port 30333 after 0 ms: Couldn't connect to server
curl still fails. The Pods are ready now, so the next place to check is the Service.
Step 7: Check the Service endpoints
A Service sends traffic only to the Pods in its endpoints:
kubectl get endpointslices -n bookshop
NAME ADDRESSTYPE PORTS ENDPOINTS AGE
bookshop-service-g8fvr IPv4 <unset> <unset> 93s
The Service has no endpoints at all, even though both Pods are ready. An empty EndpointSlice means that the Service selector matches no Pod.
kubectl get endpoints shows the same information in the older Endpoints format.
Since Kubernetes 1.33, the Endpoints API is deprecated, and kube-proxy has read EndpointSlices for a long time already.
An EndpointSlice is named after its Service plus a random suffix, and it carries the kubernetes.io/service-name label.
Step 8: Compare the selector with the Pod labels
kubectl get svc bookshop-service -n bookshop -o wide
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
bookshop-service NodePort 10.43.17.4 <none> 80:30333/TCP 93s app=bookstore
kubectl get pods -n bookshop --show-labels
NAME READY STATUS RESTARTS AGE LABELS
bookshop-web-54456559b8-66tkp 1/1 Running 0 28s app=bookshop,pod-template-hash=54456559b8
bookshop-web-54456559b8-7nd7w 1/1 Running 0 35s app=bookshop,pod-template-hash=54456559b8
The Service selects app=bookstore, but the Pods carry app=bookshop.
A selector matches a Pod only when every label in the selector is present on the Pod with the same value.
The Pod may have more labels (here pod-template-hash), and they do not matter.
You can test a selector by hand:
kubectl get pods -n bookshop -l app=bookstore
No resources found in bookshop namespace.
Step 9: Fix the selector
kubectl edit svc bookshop-service -n bookshop
Change the selector to the label the Pods carry:
selector:
app: bookshop
The endpoints appear:
kubectl get endpointslices -n bookshop
NAME ADDRESSTYPE PORTS ENDPOINTS AGE
bookshop-service-g8fvr IPv4 80 10.42.1.4,10.42.2.4 95s
This table does not show whether the endpoints are ready.
kubectl describe prints the conditions of each address:
kubectl describe endpointslice -n bookshop -l kubernetes.io/service-name=bookshop-service
The output below is shortened to the endpoints:
Endpoints:
- Addresses: 10.42.1.4
Conditions:
Ready: true
Hostname: <unset>
TargetRef: Pod/bookshop-web-54456559b8-7nd7w
NodeName: node-01
Zone: <unset>
- Addresses: 10.42.2.4
Conditions:
Ready: true
Hostname: <unset>
TargetRef: Pod/bookshop-web-54456559b8-66tkp
NodeName: node-02
Zone: <unset>
Both endpoints are ready, because the probe fix from Step 5 works. Test the website again:
curl http://cplane-01:30333
curl: (7) Failed to connect to cplane-01 port 30333 after 0 ms: Couldn't connect to server
curl still fails.
Look at the PORTS column of the EndpointSlice again: the traffic goes to port 80 in each Pod.
Step 4 showed that nginx listens on port 3333, so the Pod's kernel rejects the connection.
Step 10: Fix the Service targetPort
kubectl edit svc bookshop-service -n bookshop
Change targetPort from 80 to 3333. The editor lists the fields in alphabetical order:
ports:
- nodePort: 30333
port: 80
protocol: TCP
targetPort: 3333
A Service change takes effect without a restart.
The EndpointSlice now lists port 3333:
kubectl get endpointslices -n bookshop
NAME ADDRESSTYPE PORTS ENDPOINTS AGE
bookshop-service-g8fvr IPv4 3333 10.42.1.4,10.42.2.4 116s
A named port works too.
For example, you can name the container port in the Deployment (containerPort: 3333, name: http), and set targetPort: http in the Service and port: http in the probe.
Kubernetes then looks up the port number in each Pod.
If the application moves to another port later, you only change the number in one place.
Step 11: Verify the result
Check the Service from end to end:
kubectl describe svc bookshop-service -n bookshop
The output below is shortened to the relevant lines:
Selector: app=bookshop
Port: <unset> 80/TCP
TargetPort: 3333/TCP
NodePort: <unset> 30333/TCP
Endpoints: 10.42.1.4:3333,10.42.2.4:3333
- The selector matches the labels of the
bookshop-webPods. - The
targetPortis3333, the port nginx listens on. - Both Pods are ready endpoints, each on port
3333. TheEndpointsline lists only ready addresses.
Check the Deployment:
kubectl describe deployment bookshop-web -n bookshop
The output below is shortened to the container:
nginx:
Image: nginx:1.30.7-alpine
Port: 3333/TCP
Host Port: 0/TCP
Readiness: http-get http://:3333/ delay=0s timeout=1s period=5s successThreshold=1 failureThreshold=3
The Deployment declares port 3333, and the readiness probe checks nginx on that port.
Finally, send a request to the NodePort:
curl -I http://cplane-01:30333
HTTP/1.1 200 OK
Server: nginx/1.30.7
Date: Fri, 27 Nov 2026 14:46:50 GMT
Content-Type: text/html
Content-Length: 16380
Last-Modified: Fri, 27 Nov 2026 14:45:59 GMT
Connection: keep-alive
ETag: "6b0997a7-3ffc"
Accept-Ranges: bytes
nginx answers with 200 OK, and the website is accessible.