...

/

How to Create a Deployment

How to Create a Deployment

Learn how we can create a Kubernetes Deployment using a YAML file.

We'll cover the following...

Declaratively create a Deployment

To create a Deployment, we’ll use the deploy.yml file shown in the following snippet. It defines a single-container Pod wrapped in a Deployment. It’s annotated and snipped to draw attention to the parts we’ll focus on.

Press + to interact
kind: Deployment
apiVersion: apps/v1
metadata:
name: hello-deploy <<==== Deployment name (must be valid DNS name)
spec:
replicas: 10 <<==== Number of Pod replicas to deploy & manage
selector:
matchLabels:
app: hello-world
revisionHistoryLimit: 5
progressDeadlineSeconds: 300
minReadySeconds: 10
strategy: <<==== This block defines rolling update settings
type: RollingUpdate
rollingUpdate:
maxUnavailable: 1
maxSurge: 1
template: <<==== Below here is the Pod template
metadata:
labels:
app: hello-world
spec:
containers:
- name: hello-pod
image: nigelpoulton/k8sbook:1.0
ports:
- containerPort: 8080

There’s a lot going on in the file, so let’s explain the most important bits.

The first two lines, i.e., line 1 and line 2, tell Kubernetes to create a Deployment object based on the version of the Deployment resource defined in the apps/v1 API.

    ...