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: DeploymentapiVersion: apps/v1metadata:name: hello-deploy <<==== Deployment name (must be valid DNS name)spec:replicas: 10 <<==== Number of Pod replicas to deploy & manageselector:matchLabels:app: hello-worldrevisionHistoryLimit: 5progressDeadlineSeconds: 300minReadySeconds: 10strategy: <<==== This block defines rolling update settingstype: RollingUpdaterollingUpdate:maxUnavailable: 1maxSurge: 1template: <<==== Below here is the Pod templatemetadata:labels:app: hello-worldspec:containers:- name: hello-podimage: nigelpoulton/k8sbook:1.0ports:- 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.