Sub topic 7
Deploying and Inspecting an Application
This chapter assumes you have a running EKS cluster with nodes, a working kubeconfig (from the previous chapters), and basic familiarity with kubectl and YAML. You will deploy a small web application, then learn how to check that it is healthy.
What You Are Deploying
The manifest below defines two objects in one file, separated by ---. A Deployment keeps two nginx pods running. A Service gives those pods one stable internal address.
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: 80The Service has no type, so it defaults to ClusterIP. It is reachable only from inside the cluster. A later chapter exposes it through a load balancer.
The Service finds pods by label. Its selector (app: web) must match the pod template's labels. If they differ, the Service has no endpoints and traffic goes nowhere.
Apply and Watch the Rollout
Save the manifest as web.yaml, then apply it and wait for the rollout to finish.
kubectl apply -f web.yaml
kubectl rollout status deployment/web
kubectl get pods -l app=web -o wide
kubectl get service web
kubectl get endpoints webrollout status blocks until all replicas are ready, or reports a failure. The -o wide flag adds the pod IP and the node each pod landed on. With the Amazon VPC CNI, that IP comes from your VPC subnet. The endpoints command lists the pod IPs behind the Service. An empty list means the selector matches nothing, or no pod is ready.
Inspecting a Problem
When something is wrong, work from the outside in:
kubectl get podsshows the status.kubectl describe pod <name>shows events, such as scheduling and image pulls.kubectl logs <name>shows what the container printed.
You can also test the Service from inside the cluster with a temporary pod:
kubectl run tmp --rm -it --image=busybox:stable --restart=Never -- wget -qO- http://webCommon Errors
| Status | Usual cause on EKS | What to check |
|---|---|---|
| `Pending` | No node has enough free CPU or memory, or the node group is at `maxSize` | `describe pod`, look for `FailedScheduling` |
| `ImagePullBackOff` | Wrong image name or tag, a private registry without credentials, or no route to the registry | `describe pod` events |
| `CrashLoopBackOff` | The container starts and exits | `kubectl logs --previous <name>` |
| Empty endpoints | Selector and labels do not match, or readiness probe failing | `kubectl get endpoints web` |
A pod can also stay Pending when a node's subnet runs out of IP addresses, because each pod takes a VPC IP.
Clean Up
kubectl delete -f web.yamlExercise
You apply the manifest and both pods show Running, but kubectl get endpoints web returns <none>. What is the most likely cause, and how do you confirm it?
Show answer
The Service selector does not match the pod labels, or the pods are not passing their readiness checks. Compare kubectl get service web -o yaml (the selector) with kubectl get pods --show-labels. Fix the label or selector mismatch and apply again.