Pods Exercise-01

i) Create a Pod YAML with Environment Variables.

apiVersion: v1
kind: Pod
name: myapp-pod
run: myapp-pod
env: dev
- image: nginx
name: nginx-container
- containerPort: 80
- 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




DevOps Engineer

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

VR Dev Blog 5 (Week 6)

Median of 2 Sorted Arrays — O(log n)

How we hire engineers to build kid-safe technology

What is Kubernetes(K8E) made up of and what it does?

Top 10 Uses of Python in Business

Setting up Airflow on Azure & connecting to MS SQL Server


Major Challenges Faced in Developing Mobile Apps for Smart Devices

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store


DevOps Engineer

More from Medium

Pods YAML Walkthrough

Kubernetes Security Series - Part 1

How is security managed in Kubernetes clusters?