Select Page

Here is some yaml for an nginx deployment:

apiVersion: apps/v1beta2
kind: Deployment
  name: nginx-deployment
      app: nginx
  replicas: 2 
        app: nginx
      - name: nginx
        image: nginx:1.7.9
        - containerPort: 80
  1. Create the deployment.
  2. Which nodes are the pods running on? How can you tell?
  3. Update the deployment to use the 1.8 version of the nginx container and roll it out.
  4. Update the deployment to use the 1.9.1 version of the nginx container and roll it out.
  5. Roll back the deployment to the 1.8 version of the container.
  6. Remove the deployment
  1. Create the yaml file and name it something. I chose nginx-deployment.yaml. Create the deployment object by calling:
    kubectl create -f nginx-deployment.yaml
  2. There are many ways to get this, here’s one example that gives you the results in one step and uses a label selector:
    kubectl get pods -l app=nginx -o wide
  3. There are many ways. Here are two:
    This will work just fine but is not the preferredmethodbecausenowtheyaml is inconsistent with what you’ve got running in the cluster. Anyonecomingacrossyouryaml will assume it’s what is up and running and it isn’t.

    kubectl set image deployment nginx-deployment nginx=nginx:1.8

    Updatethelineintheyaml to the 1.8 version of the image, and apply the changes with

    kubectl apply -f nginx-deployment.yaml
  4. Same as above. Don’t forget you can watch the status of the rollout with the command
    kubectl rollout status deployment nginx-deployment
  5. kubectl rollout undo deployment nginx-deployment

    will undo the previous rollout, or if you want to go to a specific point in history, you can view the history and roll back to a specific state with:

    kubectl rollout history deployment nginx-deployment
    kubectl rollout undo deployment nginx-deployment --to-revision=x
  6. kubectl delete -f nginx-deployment.yaml