liveBook · Manning

Kubernetes Deployment

As explained in Road to Kubernetes

A Kubernetes Deployment is a Kubernetes workload resource that declaratively manages replicated application Pods and their updates.

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

How Road to Kubernetes covers it

How deep it goes
Works through manifest fields, apply and inspection commands, replica replacement, and production use without detailing Kubernetes control-plane internals.
Examples
Uses a 15-replica NGINX YAML manifest, kubectl checks, and a Pod-deletion test.
What it assumes
Builds on manual and container deployment while defining clusters, nodes, containers, and Pods before using Deployments.
What you can do after
Build it from scratch with an apps/v1 YAML manifest, then operate and inspect its Pods using kubectl.
How it connects
Connects Deployments to Pods, label selectors, Services, ConfigMaps, StatefulSets, and Pod rollouts.

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 Road to Kubernetes. The section links point to the parts of the book it draws on.