Managing Kubernetes Pods: Creation, Deletion, Updates, and Label Operations
This guide explains how to create, delete, update, and label Kubernetes pods using YAML definitions and kubectl commands, covering pod architecture, networking, and practical examples such as port‑forwarding and label management.
Main Content
Pod management (create, delete, update)
Using labels for pod management
Introduction
In daily work we usually deploy applications at the pod level rather than running containers directly on a PaaS platform. A pod can contain one or more containers, and all containers in a pod share the same host, never spanning nodes.
Why do we need pods? Pods solve the problem of managing many containers. Docker and Kubernetes expect each process to run in its own container; running multiple processes in a single container is undesirable, just like improper micro‑service granularity. However, assigning each process its own container creates a new challenge—how to manage all those containers?
Pods bundle containers together and treat them as a single unit. Containers in the same pod share the same network and UTS namespaces, hostname, and IP address, and pods within the same cluster can communicate directly.
For efficient resource utilization and scaling, multi‑tier applications are typically deployed in separate pods.
Creating a Pod with YAML
metadata: name, namespace, annotations, labels
spec: container specifications, volumes
status: runtime information
apiVersion: v1
kind: pod
metadata:
name: devop-service
labels:
app: devops-service
env: dev
spce:
nodeSelector:
compute: "true"
containers:
- image: devops/devops-service:v1.0
name: devops-service
ports:
- containerPort: 8080
protocol: TCPThe above YAML defines a simple pod named devops-service that runs a container from the image devops/devops-service:v1.0 on TCP port 8080. Two labels ( app=devops-service and env=dev ) are added for grouping, and the pod is scheduled onto nodes with the label compute=true .
kubectl create -f devops-service.yamlThis command creates the pod instance. You can then check its status:
kubectl get podTo view logs, use the -c option to specify a container when a pod has multiple containers:
kubectl logs -f devops-service
kubectl logs -f devops-service -c app1Port‑forward the service to the local machine for debugging:
kubectl port-forward devops-service 8888:8080Show the pod's labels:
kubectl get pod --show-labelsAdd a new label build=true (the --overwrite flag can replace existing labels):
kubectl label pod devops-service build=trueFinally, delete the pod when the experiment is finished:
kubectl delete pod devops-serviceSummary
Through this exercise you can perform basic pod operations such as creation, inspection, labeling, port‑forwarding, and deletion.
DevOps Cloud Academy
Exploring industry DevOps practices and technical expertise.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.