The following is an example of a Deployment. It creates a ReplicaSet to bring up three nginx Pods:
apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment labels: app: nginx spec: replicas: 3 selector: matchLabels: app: nginx
In this example:
- A Deployment named nginx-deployment is created, indicated by the
- The Deployment creates three replicated Pods, indicated by the replicas field.
- The selector field defines how the Deployment finds which Pods to manage. In this case, we simply select on one label defined in the Pod template (app: nginx).
- The Deployment opens port 80 for use by the Pods.
The following pod template’s specification indicates that the Pods run one container, nginx, which runs the nginx Docker Hub image at version 1.7.9.
template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:1.7.9 ports: - containerPort: 80
The template field contains the following instructions:
- The Pods are labeled app:
- Create one container and name it nginx.
- Run the nginx image at version
- Open port
80so that the container can send and accept traffic.
To create this Deployment, run the following command:
kubectl create -f nginx-deployment.yaml