Skip to content

Latest commit

 

History

History
127 lines (94 loc) · 2.86 KB

File metadata and controls

127 lines (94 loc) · 2.86 KB

Deployment

Deployment
Imperative commands for deployment
Tips and Tricks

For simulated Practice problems visit KillerCoda.
  1. create a deployment with nginx:1.18.0 image with 2 replicas, in the default namespace, expose port 80 on the containers.

    Solution

    #generate yaml file
    k create deploy nginx --image=nginx:1.18.0 --replicas=2 --dry-run=client -o yaml > deploy.yaml
    
    #update pod.yaml
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      creationTimestamp: null
      labels:
        app: nginx
      name: nginx
    spec:
      replicas: 2
      selector:
        matchLabels:
          app: nginx
      strategy: {}
      template:
        metadata:
          creationTimestamp: null
          labels:
            app: nginx
        spec:
          containers:
          - image: nginx:1.18.0
            name: nginx
            ports:
              - containerPort: 80
            resources: {}
    status: {}
    
    
    # create deployment
    k create -f deploy.yaml

  2. update the nginx deployment to use image nginx:1.19.8.

    Solution

    #update the deployment
    k edit deploy nginx 
    # then edit the container image
    
    OR
    
    # set new image on the deployment
    k set image deploy nginx nginx=nginx:1.19.8

  3. Rollback image nginx:1.19.8 update to nginx:1.18.0 on the nginx deployment.

    Solution

    #update the deployment
    k rollout undo deploy nginx
    # then edit the container image
    
    OR
    
    # set new image on the deployment
    k set image deploy nginx nginx=nginx:1.18.0

  4. Update replicas on nginx deployment to 5.

    Solution

    #update the replicas
    k scale deploy nginx --replicas=5
    
    OR
    
    # edit the deploy & set the replicas
    k edit deploy nginx 

  5. Set horizontal autoscaling on the nginx deployment to have min of 5 pods and max of 10 pods.

    Solution

    #update the replicas
    k autoscale deploy nginx --min=5 --max=10
    
    # check the horizontal auto scaler
    k get hpa nginx