Cloud Native 5 min read

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.

DevOps Cloud Academy
DevOps Cloud Academy
DevOps Cloud Academy
Managing Kubernetes Pods: Creation, Deletion, Updates, and Label Operations

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: TCP

The 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.yaml

This command creates the pod instance. You can then check its status:

kubectl get pod

To 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 app1

Port‑forward the service to the local machine for debugging:

kubectl port-forward devops-service 8888:8080

Show the pod's labels:

kubectl get pod --show-labels

Add a new label build=true (the --overwrite flag can replace existing labels):

kubectl label pod devops-service build=true

Finally, delete the pod when the experiment is finished:

kubectl delete pod devops-service

Summary

Through this exercise you can perform basic pod operations such as creation, inspection, labeling, port‑forwarding, and deletion.

cloud-nativeKubernetesyamlPodkubectlLabel
DevOps Cloud Academy
Written by

DevOps Cloud Academy

Exploring industry DevOps practices and technical expertise.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.