Running a container in one Pod is a start, but a web application may need several copies and a replacement when one disappears. A Kubernetes Deployment manages that group of Pods. You declare how many replicas you want; Kubernetes works to keep that number running across the cluster. section 8.1.3 section 8.3.3 section 8.6
A Deployment is commonly written as a YAML manifest. Its Pod template specifies the container image and Pod configuration. Its selector must match labels on those Pods, while replicas sets the desired count. The Deployment uses apiVersion apps/v1. section 8.3.3
Listing 8.6 K8s YAML manifest for an NGINX Deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
replicas: 15
selector:
matchLabels:
app: my-nginx
template:
metadata:
labels:
app: my-nginx
spec:
containers:
- name: nginx
image: nginx:latest
The NGINX manifest ties these pieces together: replicas requests 15 Pods, matchLabels selects app: my-nginx, and the Pod template carries that same label and an nginx image. section 8.3.3
To try the manifest and inspect what it creates:
- Save it as my-first-deployment.yaml, then run kubectl apply -f my-first-deployment.yaml. section 8.3.3
- Run kubectl get deployments to check the Deployment, and kubectl get pods --selector app=my-nginx to find its labeled Pods. section 8.3.3
- Delete one managed Pod and list Pods again. Its replacement has a new name as the Deployment works back toward the requested replica count. section 8.4
Because managed Pods are interchangeable and their names change, use labels to find a particular Pod or address the Deployment for commands such as logs and exec. A Service exposes the Pods; when replicas scale up, it can balance traffic among Pods ready to receive it. For stateless production applications, pair Deployment manifests with ConfigMaps for environment variables and a load-balancing Service for external traffic. StatefulSets are the alternative described for scaling stateful Pods with attached volumes. section 8.4 section 8.3.3 section 8.5 section 8.6









