liveBook · Manning

Kubernetes Deployment

As explained in Acing the Certified Kubernetes Administrator Exam, Second Edition

A Deployment is a Kubernetes API resource that declaratively manages the desired state of replicated application workloads.

Need more than one pod for a stateless application? A Deployment manages replicated pods through a ReplicaSet. The ReplicaSet maintains the requested number of pods, while the Deployment provides a place to change the workload and roll out a new version. This makes replacement and scaling practical when pods are ephemeral. section 5.1 section 5.1.2

A Deployment is a Kubernetes API object, not a pod. Its YAML places the pod definition under `spec.template`, inside the Deployment's own `spec`. To compare the two shapes, generate files with `kubectl run nginx --image nginx --dry-run=client -o yaml > pod.yaml` and `kubectl create deploy nginx --image nginx --dry-run=client -o yaml > deploy.yaml`. section 1.4 section 5.1.2

Create, scale, and update a workload

Run `kubectl create deploy apache --image httpd:2.4.65 --replicas 3`, then check `kubectl get deploy` for three ready replicas. Run `kubectl scale deploy apache --replicas 5` and check `kubectl get po` for five pods. Change the image with `kubectl set image deploy apache httpd=httpd:alpine`; use `kubectl get deploy`, `kubectl get rs`, and `kubectl get po` to inspect the resulting Deployment, ReplicaSets, and pods. An image change creates a new ReplicaSet for the new pods. section 5.1.1 section 5.1.2

Figure 5.5 When the Deployment image is changed, a new ReplicaSet is created with a new set of pod replicas.
figure

Use the figure to trace the operational consequence of an image change: a new ReplicaSet and a new set of pod replicas. section 5.1.2

A Deployment's rolling-update strategy controls how many replicas may be added or unavailable during an update. If the application needs a stable endpoint, expose the Deployment with a Service; do not confuse healthy Deployment replicas with working Service access. When access fails, compare the Service's port and selector with the application's port and pod labels. section 5.1.2 section 8.3.2

For practice, scale the CoreDNS Deployment in `kube-system` and verify the pod count with `kubectl -n kube-system get po`. Scaling it to zero terminates its pods and leaves cluster hostname resolution unavailable. If a newly created Deployment instead produces an unhealthy pod, inspect that pod's logs: a MySQL example reports a missing required password setting, then runs after the Deployment is corrected. section 6.2.3 section 8.1

How Acing the Certified Kubernetes Administrator Exam, Second Edition covers it

How deep it goes
Works through kubectl operations and Deployment YAML structure, then traces ReplicaSets and rolling updates without descending into controller internals.
Examples
Uses an Apache replica-and-image change, CoreDNS scaling, and a MySQL pod-log repair.
What it assumes
Assumes access to a Kubernetes cluster and kubectl while explaining how Deployments relate to ReplicaSets and pods.
What you can do after
Operate/configure it with kubectl to scale pods, update images, verify ReplicaSets, and investigate unhealthy pods.
How it connects
Connects Deployments to pods, ReplicaSets, rolling updates, Services, and CoreDNS.

Also explained in

Compare how 10 books explain Kubernetes Deployment →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Acing the Certified Kubernetes Administrator Exam, Second Edition. The section links point to the parts of the book it draws on.