(K8s) Kubernetes lab 102 Pods with kubectl Commands

Step 0 : Create docker hub account. https://hub.docker.com

Step 1 : Open Play with Kubernetes login with your docker hub account.

Step 2 : Click on start

Step 3 : It will start a 4 hr session, click on + ADD NEW INSTANCE

Step 4 : Click in terminal and run steps from lab 101 to build cluster

Step 5 : kubectl run web --image=nginx

  • this command will create pod with image nginx and name web

Step 6 : kubectl delete pod web

  • this command will delete pod with name web

Step 7 : kubectl run web --image=nginx --port=80

  • this command will create nginx pod and expose container with port 80

Step 8 : kubectl expose pod web --port 80 --name=nginx-svc --type=NodePort --target-port=80

  • this command will create nodeport service for pod web

Step 9 : kubectl get all

  • this command will display all objects in default namespace

  • take note port for service/nginx-svc

  • it should look like 80:30157/TCP

  • port will be different for you

Step 10 : copy URL below memory, open new tab and paste url with :<portnumber>

  • use port number from step 9

  • you should see nginx welcome page

Step 11 : kubectl create service nodeport nginx-svc1 --tcp=80:80 --node-port=30001

  • this command will create a service or type Nodeport

  • node port will 30001

Step 12 : kubectl label pod web app=nginx-svc1

  • this command will add label to pod web

  • label key will be app

  • label value will be nginx-svc1

Step 13 : copy URL below memory, open new tab and paste url with :30001

  • you should see nginx welcome page

Step 14 : kubectl run web --image=nginx --dry-run=client -o yaml

  • you can run any command we discussed in this lab with --dry-run=client

  • this will validate command and will not make any changes

  • appending -o yaml will print output in yaml format

Step 15 : kubectl get pods -o wide

  • this command will print list of all pods with their host node information

Step 16 : kubectl delete pod web

  • this command will delete pod with name web