Pods Exercise-01

MrDevSecOps
3 min readFeb 14, 2022

--

i) Create a Pod YAML with Environment Variables.

apiVersion: v1
kind: Pod
metadata:
name: myapp-pod
labels:
run: myapp-pod
env: dev
spec:
containers:
- image: nginx
name: nginx-container
ports:
- containerPort: 80
env:
- name: FIRST_POD
value: "Nginx pod"

ii) Deploy Pod YAML file

$ kubectl apply -f <FILENAME.YAML> or 
$ kubectl create -f <FILENAME.YAML>

iii) Get the running pod

$ kubectl get pods
$ kubectl get pods <POD-NAME>

iv) Print wide output of the running Pod

$ kubectl get pods -o wide 

v) Print Pods in particular NameSpace (pod are deployed in default namespace)

$ kubectl get pods -n <NAME-SPACE>

vi) Print Pods in all NameSpace

$ kubectl get pods -A

vii) Print the pod output in YAML/JSON format

$ kubectl get pods <POD-NAME> -o yaml  
$ kubectl get pods <POD-NAME> -o json

viii) Print the pod labels

$ kubectl get pods --show-labels

ix) Print Pods with a specific label

$ kubectl get pods -l run=myapp-pod

x) Print the details description of pods

$ kubectl describe pods <POD-NAME>

xi) Edit the configuration of the running pod, here we will change the nginx image version from latest to 1.21.6

$ kubectl edit pods <POD-NAME>

In the above example, we first grep the existing version, change the version by the above edit command and grep it again.

xii) Check the logs of the pod

$ kubectl logs <POD-NAME>
$ kubectl logs <POD-NAME> -n <NAME-SPACE>

xii) Running operations directly on the YAML file

$ kubectl get –f [FILE-NAME.yaml]
$ kubectl describe –f [FILE-NAME.yaml]
$ kubectl edit –f [FILE-NAME.yaml]
$ kubectl delete –f [FILE-NAME.yaml]
$ kubectl apply –f [FILE-NAME.yaml]
$ kubectl describe –f [FILE-NAME.yaml]
$ kubectl edit –f [FILE-NAME.yaml]
$ kubectl delete  -f myapp-pod.yaml
$ kubectl apply -f myapp-pod.yaml

xiii) Delete the running pod

$ kubectl delete pods <POD-NAME>

Also check, Kubernetes Tutorials

--

--

MrDevSecOps

Integrating security into the software development lifecycle.