Creating a Deployment

This recipe will take you through instructions to create a Deployment using a manifest file that keeps a set of pods running. Deployments are used to declare how many replicas of a pod should be running. A Deployment can be scaled up and down; we will see more on that topic later in Chapter 7, Scaling and Upgrading Applications.

Let's perform the following steps:

  1. Change directory to src/chapter2/yaml/, where the example files for this recipe are located:
$ cd src/chapter2/yaml/

  1. Review the Deployment manifest:
$ cat deployment-nginx.yaml
apiVersion: apps/v1
kind: deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 2
selector:
matchLabels:
app: nginx
# actual file is longer, shortened to show structure of the file only
YAML is white space sensitive. Review the example file to understand the structure of the file. You will see that YAML files do not use tabs instead of a space character.
If in doubt, use a linter for your YAML files. 
  1. Create a Deployment by applying the YAML manifest:
$ kubectl apply -f deployment-nginx.yaml

After you run the preceding command, the container image mentioned in the YAML manifest will be pulled from the container registry and the application will be scheduled in your Kubernetes cluster as defined in the Deployment manifest. Now you should be able to verify the Deployment by following the next recipe.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.82.21