Menu
Coddy logo textTech

Deployments From Manifests

Part of the Introduction to Kubernetes section of Coddy's Terminal journey. Lesson 13 of 45.

Deployments are usually written as manifests too. The kind is Deployment from the apps/v1 API, and the spec has three parts: how many replicas, a selector that says which Pods belong to it, and a template for the Pods it creates:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: web
spec:
  replicas: 1
  selector:
    matchLabels:
      app: web
  template:
    metadata:
      labels:
        app: web
    spec:
      containers:
        - name: web
          image: nginx

The template is a Pod manifest without apiVersion and kind. Its labels must match the selector, otherwise Kubernetes rejects the file: that is how the Deployment recognises its own Pods.

kubectl apply is declarative: apply the file once and the Deployment is created; apply it again unchanged and kubectl says unchanged. Edit the file, say replicas: 3, and apply again: the answer is configured, and the cluster moves to the new state.

kubectl apply -f deployment.yaml
challenge icon

Challenge

Easy

A manifest named deployment.yaml describes a web Deployment with one replica. Apply it. Then open the file from the file tree, change replicas to 3, save it, and apply it again. Finally show the web Deployment to confirm 3/3 replicas are ready.

Try it yourself

Terminal
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Introduction to Kubernetes

Practice on your own: Terminal playground