Skip to content

Latest commit

 

History

History
93 lines (62 loc) · 2.42 KB

23-Practice-Test-Imperative-Commands.md

File metadata and controls

93 lines (62 loc) · 2.42 KB

Practice Test - Imperative Commands

Solutions for Practice Test - Imperative Commands

  • Run the command kubectl run nginx-pod --image=nginx:alpine.

    $ kubectl run nginx-pod --image=nginx:alpine
    
  • Run the command kubectl run redis --image=redis:alpine -l tier=db.

    $ kubectl run redis --image=redis:alpine -l tier=db
    
  • Run the command kubectl expose pod redis --port=6379 --name redis-service.

    $ kubectl expose pod redis --port=6379 --name redis-service
    
  • Run the command kubectl create deployment webapp --image=kodekloud/webapp-color. Then scale the webapp to 3 using command kubectl scale deployment/webapp --replicas=3.

    $ kubectl create deployment webapp --image=kodekloud/webapp-color
    $ kubectl scale deployment/webapp --replicas=3
    
  • Run the command kubectl run custom-nginx --image=nginx --port=8080.

    $ kubectl run custom-nginx --image=nginx --port=8080
    
  • Run the command kubectl create ns dev-ns.

    $ kubectl create ns dev-ns
    
  • Run the command to create a deployment.

    Step 1: Create the deployment YAML file
    $ kubectl create deployment redis-deploy --image redis --namespace=dev-ns --dry-run=client -o yaml > deploy.yaml
    $ kubectl create -f deploy.yaml
    
    Step 2: Edit the YAML file and add update the replicas to 2.
    
    Step 3: Run kubectl apply -f deploy.yaml to create the deployment in the dev-ns namespace.
    $ kubectl apply -f deploy.yaml
    
    You can also use kubectl scale deployment or kubectl edit deployment to change the number of replicas once the object has been created.
    $ kubectl edit deployment redis-deploy
    $ kubectl scale deployment/redis-deploy --replicas=2 --namespace=dev-ns
    
    In v1.19, kubectl create deployment supports "--replicas" flag to increase the count number.
    $ kubectl create deployment redis-deploy --image=redis --namespace=dev-ns --replicas=2 
    
  • First create a YAML file for both the pod and service like this: kubectl run httpd --image=httpd:alpine --port=80 --expose.

    $ kubectl run httpd --image=httpd:alpine --port=80 --expose