Kubernetes is one of the most in-demand tools in DevOps, and understanding Pods is the first step toward mastering it. Today, I’ll walk you through everything I learned about Pods, including creating them using the CLI, generating YAML/JSON manifests, applying labels, debugging, and deleting Pods.
ALSO READ:
- Complete Install Kubernetes with Kind (Kubernetes IN Docker) on RHEL 9 / CentOS Stream 9
- Complete 3-Step Guide to Successfully Set Up Prometheus, Node Exporter, and Grafana on Linux Server
- Effortless Way to Automatically Archive Log Files Older Than 30 Days in Linux with Bash Script
Click here to go to the GitHub repos link
Kubernetes Creating a Pod Using
# You can create a simple Pod directly from the CLI
kubectl run nginx-pod --image=nginx:latestCheck if the Pod is running
kubectl get pods
kubectl get pods -o wideUnderstanding Pod Details
# To view full details
kubectl describe pod nginx-podYou can see:
- Pod creation time
- Node it is running on
- Image ID
- Container state (Running / Waiting / Terminated)
- Restart count
- Events (pulling, created, started)
- Volumes and service accounts
Generate YAML/JSON
# yaml Output
kubectl run mypod --image=nginx:latest --dry-run=client -o yaml
# Save the manifest yaml
kubectl run mypod --image=nginx:latest --dry-run=client -o yaml > nginx-pod.yaml
# JSON Output
kubectl run mypod --image=nginx:latest --dry-run=client -o json
# Save the manifest in json
kubectl run mypod --image=nginx:latest --dry-run=client -o json > nginx-pod.jsonCreating a Pod Using a YAML Manifest
apiVersion: v1
kind: Pod
metadata:
name: nginx-pod
labels:
env: dev
type: frontend
version: 1.0.0
spec:
containers:
- name: nginx-pod
image: nginx:latest
ports:
- containerPort: 80
Apply it
kubectl apply -f simple-pod.yml
# Check pod labels
kubectl get pods --show-labels
Deleting Pods
# To delete the pod
kubectl delete pod nginx-pod
Example screenshots:
[root@tech-k8s-1 test]# kubectl apply -f simple-pod.yml
pod/nginx-pod created
[root@tech-k8s-1 test]# kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-pod 1/1 Running 1 (74m ago) 77m
[root@tech-k8s-1 test]# kubectl get pods --show-labels
NAME READY STATUS RESTARTS AGE LABELS
nginx-pod 1/1 Running 1 (74m ago) 77m env=dev,type=frontend,version=1.0.0