Sub topic 7
Deploying and Inspecting an Application
This chapter assumes you have a working EKS cluster with at least one node group, as built in "Creating Your First Cluster". It also assumes kubectl points at that cluster and that you know what a pod, Deployment and Service are. Check the connection first:
kubectl config current-context
kubectl get nodesAll nodes should show Ready. If the command times out or returns an authorization error, fix that first. Access problems are covered in "Who Can Talk to the Cluster".
What You Will Deploy
You will deploy a two-replica nginx Deployment and a ClusterIP Service in front of it. Then you will inspect each layer to see how the objects relate. The same inspection steps work for any workload on EKS.
The Manifest
Save this as web.yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
name: web
spec:
replicas: 2
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
spec:
containers:
- name: web
image: nginx:stable
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: web
spec:
selector:
app: web
ports:
- port: 80
targetPort: 80Three details connect the objects:
spec.selector.matchLabelsin the Deployment must match the labels in the pod template. If they differ, the API server rejects the Deployment.- The Service
selectormust match the pod labels. A mismatch is accepted silently and the Service gets no backends. targetPortmust be a port the container actually listens on.containerPortis documentation only and does not open or close anything.
Because no type is set, the Service is ClusterIP. It gets a virtual IP that works only inside the cluster.
Applying and Watching the Rollout
kubectl apply -f web.yaml
kubectl rollout status deployment/web
kubectl get deployment,replicaset,pod,service -l app=webkubectl apply is declarative. Running it again with an edited file computes the difference and updates only what changed. rollout status blocks until the new pods are ready or the rollout fails, so it works well in scripts and CI.
The Service has no app=web label of its own, so -l app=web hides it from that listing. Run kubectl get service web separately to see it.
Deployments do not manage pods directly. The Deployment owns a ReplicaSet, and the ReplicaSet owns the pods. Pod names reflect this, for example web-7d9c6b5f4-x2k8q. The middle segment is a hash of the pod template. When you change the template, a new ReplicaSet with a new hash appears.
Inspecting Where Pods Landed
kubectl get pods -l app=web -o wideThe -o wide output adds the pod IP and the node name. On EKS, the Amazon VPC CNI gives each pod a real VPC IP address from the node's subnet. You can confirm it:
kubectl get pods -l app=web -o wide
kubectl get nodes -o wideCompare the pod IPs with the subnet CIDR ranges in your VPC. They fall inside them. This is also why pod density is limited per node. Each instance type supports a fixed number of network interfaces and IPs per interface, which caps the pods it can run. A pod that stays Pending on a small instance type may be hitting this cap rather than a CPU or memory limit.
You can check how many pods a node accepts:
kubectl get node <node-name> -o jsonpath='{.status.allocatable.pods}'The Four Inspection Commands
Most troubleshooting uses four commands, in roughly this order.
| Command | Answers the question |
|---|---|
| `kubectl get` | What exists and what state is it in? |
| `kubectl describe` | Why is it in that state? (Shows events.) |
| `kubectl logs` | What did the application print? |
| `kubectl exec` | What does the world look like from inside the container? |
describe
kubectl describe pod -l app=web
kubectl describe deployment webRead the Events section at the bottom first. It records scheduling decisions, image pulls, probe failures and kills. Events expire after about an hour, so capture them soon after a failure.
You can also list recent events for the namespace in time order:
kubectl get events --sort-by=.lastTimestamplogs
kubectl logs deployment/web
kubectl logs -l app=web --tail=20
kubectl logs <pod-name> --previouslogs deployment/web picks one pod, so it shows only part of the picture when there are several replicas. Use the label form for all of them. --previous shows the logs of the last terminated container, which you need for a pod in CrashLoopBackOff, because the current container has just restarted and may have printed nothing yet.
exec and port-forward
kubectl exec -it deployment/web -- sh
kubectl port-forward service/web 8080:80Then in a second terminal:
curl -i http://localhost:8080/port-forward tunnels through the API server to the Service, so it works with no load balancer and no node access. It is for testing, not for serving traffic. It also connects to a single pod behind the Service, so it does not exercise load balancing.
To test the Service name from inside the cluster, run a short-lived pod:
kubectl run tmp --rm -it --image=busybox:stable --restart=Never -- wget -qO- http://webThis checks cluster DNS (web resolves to the Service IP) and the Service-to-pod path together.
Checking That the Service Has Backends
If the Service responds with connection errors, look at its endpoints:
kubectl get endpointslices -l kubernetes.io/service-name=web
kubectl get endpoints webYou should see two pod IPs on port 80. An empty list means one of three things: the selector does not match any pod labels, the pods are not Ready, or no pods exist. Pods that fail their readiness probe are removed from the endpoints, which is the intended behavior and a common source of "the Service works sometimes."
Common Failure States
| Pod status | Usual cause on EKS | First check |
|---|---|---|
| `Pending` | No node has enough CPU or memory, or the node is out of pod IP slots | `kubectl describe pod`, look for `FailedScheduling` |
| `ImagePullBackOff` | Wrong image name or tag, private registry without credentials, or nodes with no route to the registry | Events section; check node subnet routing |
| `CrashLoopBackOff` | The process exits at startup | `kubectl logs --previous` |
| `Running` but not Ready | Readiness probe failing | `describe` for probe failure events |
| `CreateContainerConfigError` | Missing ConfigMap or Secret that the pod references | Events section |
Pulling from a private Amazon ECR repository needs no pull secret when the node IAM role has ECR read permissions, which the managed node group role does by default. Nodes in private subnets also need a NAT gateway or VPC endpoints to reach public registries.
Updating, Scaling and Rolling Back
Change the image to trigger a rolling update:
kubectl set image deployment/web web=nginx:1.27
kubectl rollout status deployment/web
kubectl rollout history deployment/webBy default, the Deployment strategy allows 25 percent of pods to be unavailable and 25 percent surge above the desired count. The old ReplicaSet scales down as the new one scales up. If the new pods never become Ready, the rollout stalls and the old pods keep serving. That is the safety net.
To revert:
kubectl rollout undo deployment/webScale manually with:
kubectl scale deployment/web --replicas=4Prefer editing replicas in the manifest and applying it. Otherwise the file and the cluster disagree, and the next apply quietly reverts your change. Automatic scaling is covered in "Scaling Pods and Nodes".
Production Habits to Add
The example manifest is minimal. Before running real workloads, add these fields to the container spec:
resources.requestsfor CPU and memory. The scheduler places pods using requests, and autoscalers depend on them.resources.limitsfor memory, to stop one container from starving others on the node.readinessProbeso traffic reaches only pods that can serve it.livenessProbe, used carefully, so a hung process gets restarted.
Cleanup
kubectl delete -f web.yamlDeleting the Deployment removes its ReplicaSet and pods. Keep the cluster, since later chapters build on it.
Exercise
You apply the web manifest and kubectl get pods shows two Running pods, but kubectl get endpoints web shows <none>. Name two likely causes and the command you would use to confirm each.
Show answer
First, the Service selector does not match the pod labels. Compare them with kubectl get service web -o yaml and kubectl get pods --show-labels. Second, the pods are Running but not Ready, because the readiness probe is failing, so they are removed from the endpoints. Confirm with kubectl get pods, where the READY column shows 0/1, and kubectl describe pod for probe failure events.
Exercise
A new image tag causes pods in a rolling update to enter CrashLoopBackOff. Which command shows why the container is failing, and which command returns the Deployment to the previous version?
Show answer
Use kubectl logs <pod-name> --previous to read the output of the crashed container. Use kubectl rollout undo deployment/web to restore the previous ReplicaSet.