Difficulty: Beginner
Estimated Time: 10-15 minutes

In this scenario, you'll learn how to use Kubectl to create and launch Deployments. We will launch deployments by writing yaml definitions.

YAML definitions define the Kubernetes Objects that become scheduled for deployment.

Don’t stop now! The next scenario will only take about 10 minutes to complete.

Kubernetes Deployment

Step 1 of 7

Step 1 - Creating a Deployment

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 .metadata.name field.
  • 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: nginx
  • Create one container and name it nginx.
  • Run the nginx image at version 1.7.9.
  • Open port 80 so that the container can send and accept traffic.

To create this Deployment, run the following command: kubectl create -f nginx-deployment.yaml