Deploy a workload using the CLI

MKE supports deploying your Kubernetes objects on the command line using kubectl.

Deploy an NGINX server

  1. Download and configure the client bundle.

  2. Create a file called deployment.yaml that contains the following content:

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: nginx-deployment
    spec:
      selector:
        matchLabels:
          app: nginx
      replicas: 2
      template:
        metadata:
          labels:
            app: nginx
        spec:
          containers:
          - name: nginx
            image: nginx:1.7.9
            ports:
            - containerPort: 80
          nodeSelector:
            kubernetes.io/os: linux
    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: nginx
      labels:
        app: nginx
    spec:
      type: NodePort
      ports:
        - port: 80
          nodePort: 32768
      selector:
        app: nginx
    
  3. Deploy the NGINX server:

    kubectl apply -f deployment.yaml
    
  4. Use the describe deployment option to review the deployment:

    kubectl describe deployment nginx-deployment
    

Update the deployment

Update an existing deployment by applying an updated YAML file.

  1. Increase the number of replicas to 4:

    kubectl scale --replicas=4 deployment/nginx-deployment
    
  2. Update the NGINX version to 1.8:

    kubectl set image deployment/nginx-deployment nginx=nginx:1.8
    
  3. Deploy the updated NGINX server:

    kubectl apply -f update.yaml
    
  4. Verify that the deployment was scaled up successfully by listing the deployments in the cluster:

    kubectl get deployments
    

    Expected output:

    NAME                   DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
    nginx-deployment       4         4         4            4           2d
    
  5. Verify that the pods are running the updated image:

    kubectl describe deployment nginx-deployment | grep -i image
    

    Expected output:

    Image:        nginx:1.8
    

See also