Cheat notes · Module 01 · Run a workload
One app, three objects: Deployment, Service, Ingress
A five-minute review for when you have done this module and want it back in your head. Open the full module for the steps and the lab, or the full text to print.
The idea
A Deployment keeps N identical pods running through a ReplicaSet per version; a Service finds Ready pods by label and gives them one name; an Ingress routes a hostname to a Service, through an ingress controller. Labels are the only glue, and nothing checks them.
Remember
- One ReplicaSet per pod template version. A rollout scales the new one up and the old one down; the old one stays at 0 for a rollback.
- Service selector: matches pod labels; the matching Ready pods are its endpoints (
EndpointSlice). targetPort: httpnames the container port, so the Service follows the pod if the number changes.- An Ingress is only data until the ingress controller with its
ingressClassNamereads it. Traefik runs on the control-plane node. - Always set
metadata.namespacein the file, or it lands wherever your context points. - **
*.localtest.mepoints at 127.0.0.1;** kind maps port 8090 to Traefik's NodePort 30080.
Pitfalls
- A Service selector that matches no pod: every object is green, the site answers
503. Look at the endpoints. - A Deployment's selector cannot be changed after creation. Relabel by adding the new label to the template first, then switching the Service.
kubectl applynever deletes what you removed from your files.
Commands
kubectl -n NS rollout status deployment/NAME | Wait for a rollout |
kubectl -n NS get deployment,replicaset,pod -o wide | The whole chain, with nodes |
kubectl -n NS get endpointslices -l kubernetes.io/service-name=SVC | Which pods the Service sends to |
kubectl -n NS port-forward service/SVC 9898:80 | A private tunnel, for you only |
kubectl diff -f FOLDER | What an apply would change |
apps/checkout/service.yaml
apiVersion: v1
kind: Service
metadata:
name: checkout
namespace: checkout-dev
spec:
selector:
app.kubernetes.io/name: checkout
ports:
- name: http
port: 80
targetPort: http
Test yourself
Answer in your head first, then open the answer.
You change the image and apply. What does Kubernetes create?
A new ReplicaSet for the new pod template, scaled up while the old one is scaled down.
A Service has no endpoints but its pods are Running and Ready. Most likely cause?
Its selector does not match the pods' labels.
Who makes an Ingress do something?
The ingress controller that matches its ingressClassName.
Why does the site answer 503 instead of 404 when a Service has no pods?
Traefik is configured with allowEmptyServices: the route exists, it has nowhere to send the request.
Where module 01 leaves you: checkout runs in checkout-dev with 2 pods on image 6.17.0, and answers at http://checkout.localtest.me:8090. Your repo holds cluster/traefik.yaml and three files in apps/checkout/.