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.

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
  name: nginx-deployment
    app: nginx
  replicas: 3
      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.

        app: nginx
      - name: nginx
        image: nginx:1.7.9
        - 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