Skip to content

Latest commit

 

History

History
134 lines (89 loc) · 2.82 KB

2. Pods.md

File metadata and controls

134 lines (89 loc) · 2.82 KB

Pods

A Pod represents a set of running containers on your cluster - it's the smallest and simplest Kubernetes object.

Using Command Line

  1. Create new Pod called 'webserver' running nginx image using command line

    kubectl run webserver --image=nginx --restart=Never 
    
  2. Get the status, IP of the pod 'webserver'

    kubectl get pod webserver -o wide 
    

    Now use describe to get detailed description of the pod , including related resources such as events or controllers

    kubectl describe pod webserver  
    
  3. Delete pod 'webserver'

    kubectl delete pod webserver
    
  4. List all the pods in current namespace

    kubectl get pod 
    
  5. Create new Pod called 'faultywebserver' running nnginx image using command line

    kubectl run faultywebserver --image=nnginx --restart=Never 
    
  6. Get the status, IP of the pod 'faultywebserver'

    kubectl get pod faultywebserver -o wide 
    

    Use describe command to identify the issue

    kubectl describe pod faultywebserver 
    
  7. Now fix the pod and verify it runs correctly

    kubectl edit pod faultywebserver
    
    • edit file and change the following image: nnginx to be image: nginx

    • save and close the file

    • verify that changes worked

      kubectl get pod faultywebserver -o wide 
      
  8. Delete all Pods in current namespace

    kubectl delete po --all
    

Creating Pods using YAML

  1. Create new Namespace called 'mynamespace'

    kubectl create namespace mynamespace
    
  2. Create new Pod called 'webserver' described using YAML into mynamespace

    Notice we used --dry-run flag

    •   kubectl run webserver --image=nginx --restart=Never --dry-run -o yaml > nginx-pod.yaml
      
    • View the file using VS Code (or any editor of choice)

    • Now create pod using YAML file

      kubectl apply -f nginx-pod.yaml -n mynamespace
      
  3. Get the status, IP of the pod 'webserver'

    kubectl get pod webserver -o wide -n mynamespace 
    
  4. change the image nginx in 'webserver' pod to use tag 1.16.0

    • edit the image field to include tag e.g. nginx:1.16.0 in the nginx-pod.yaml
    • Save the file
    • kubectl apply -f nginx-pod.yaml -n mynamespace

Pod Logs and Execs

  1. Get 'webserver' pod logs

    kubectl logs webserver -n mynamespace 
    
  2. Run list all the files within container nginx running on 'webserver' pod

    kubectl exec webserver -n mynamespace -- ls
    
  3. Delete Namespace mynamespace

    kubectl delete namespace mynamespace
    

Delete all resources in the current namespace

kubectl delete all --all