A Pod represents a set of running containers on your cluster - it's the smallest and simplest Kubernetes object.
-
Create new Pod called 'webserver' running nginx image using command line
kubectl run webserver --image=nginx --restart=Never
-
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
-
Delete pod 'webserver'
kubectl delete pod webserver
-
List all the pods in current namespace
kubectl get pod
-
Create new Pod called 'faultywebserver' running nnginx image using command line
kubectl run faultywebserver --image=nnginx --restart=Never
-
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
-
Now fix the pod and verify it runs correctly
kubectl edit pod faultywebserver
-
edit file and change the following
image: nnginx
to beimage: nginx
-
save and close the file
-
verify that changes worked
kubectl get pod faultywebserver -o wide
-
-
Delete all Pods in current namespace
kubectl delete po --all
-
Create new Namespace called 'mynamespace'
kubectl create namespace mynamespace
-
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
-
-
Get the status, IP of the pod 'webserver'
kubectl get pod webserver -o wide -n mynamespace
-
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
-
Get 'webserver' pod logs
kubectl logs webserver -n mynamespace
-
Run list all the files within container nginx running on 'webserver' pod
kubectl exec webserver -n mynamespace -- ls
-
Delete Namespace mynamespace
kubectl delete namespace mynamespace
kubectl delete all --all