Day 28 of 90 Days of DevOps Challenge: Exploring Namespaces, Pods, and Services in Action!

Vaishnavi DVaishnavi D
3 min read

After grasping the Kubernetes architecture and different types of cluster setups yesterday, I decided to get hands-on and dive into the actual working of Kubernetes resources, particularly Namespaces, Pods, and Services.

Today was all about creating real YAML manifests and seeing my applications run inside a cluster (I'm using Minikube for now). Here’s what I learned and practiced:

Namespaces – Logical Isolation in a Cluster

In a single cluster you might run multiple teams workloads or a dev, staging, and prod environment side by side. Namespaces give each workload its own logical “room”, so resources don’t collide.

Example Structure:

frontend-app-pods  →  frontend-app-ns  
backend-app-pods   →  backend-app-ns  
database-pods      →  database-ns

Creating a namespace:

kubectl create namespace frontend-app-ns  # Create a namespace
kubectl get all -n frontend-app-ns        # List everything in just that namespace

This makes management easier especially when deploying multiple apps.

Anatomy of a K8s Manifest (YAML)

Almost everything in Kubernetes is configured using YAML files, also called manifests.

General Structure:

apiVersion: <version>
kind: <resource>
metadata:
  name: <name>
spec:
  ...  # resource-specific config

To apply a manifest:

kubectl apply -f <filename>.yaml

NOTE: apply is idempotent (safe to run again); create will fail if the object already exists.

My First K8s Pod – Creating a Java Web App Pod

Here’s the YAML I wrote and applied to create a pod:

# javawebapp-pod.yaml
apiVersion: v1
kind: Pod
metadata:
  name: javawebapp-pod
  labels:
    app: javawebapp
spec:
  containers:
    - name: javawebapp-container
      image: zerotoroot/javawebapp
      ports:
        - containerPort: 8080

Commands I used:

kubectl apply -f javawebapp-pod.yaml
kubectl get pods -o wide
kubectl describe pod javawebapp-pod
kubectl logs javawebapp-pod

NOTE: Kubernetes can automatically replace a crashed pod, which I tested by manually deleting it. True self-healing in action!

Exposing the Pod with a Service

Pods are temporary and their IPs keep changing, so I learned that to consistently access a pod, we need a Service.

Types of Services:

  • ClusterIP: Default, internal-only communication.

  • NodePort: Exposes on a fixed port of each worker node.

  • LoadBalancer: Uses a cloud provider's LB for external access.

Example Service YAML:

apiVersion: v1
kind: Service
metadata:
  name: javawebapp-svc
spec:
  type: LoadBalancer       # cloud LB (AWS ELB, GCP LB, etc.)
  selector:
    app: javawebapp        # finds the right Pods via labels

  ports:
    - port: 80             # Service Port
      targetPort: 8080     # Pod's containerport

Command:

kubectl apply -f javawebapp-service.yaml
kubectl get service

Once deployed, access the app through the LoadBalancer DNS URL. On Minikube, I used:

minikube service javawebapp-svc

Combining Pod & Service in One Manifest

For small demos it’s convenient to concat resources with --- separators:

# javawebapp-all.yaml
apiVersion: v1
kind: Pod
metadata:
  name: javawebapp-pod
  labels:
    app: javawebapp
spec:
  containers:
    - name: javawebapp-container
      image: zerotoroot/javawebapp
      ports:
        - containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
  name: javawebapp-svc
spec:
  type: LoadBalancer
  selector:
    app: javawebapp
  ports:
    - port: 80
      targetPort: 8080

To apply and clean up:

kubectl apply -f javawebapp-combined.yaml
kubectl get pods,svc
kubectl delete all --all

Final Thoughts

Namespaces helped me organize and isolate different workloads within the cluster. YAML manifests showed how Kubernetes simplifies deployments using a declarative approach. I learned that Pods are the smallest units in K8s and can self-heal if they crash. Services provide stable access to these Pods, even when they restart or scale. Lastly, LoadBalancer Services are crucial for exposing applications externally in production environments. Overall, today’s hands-on practice made these core concepts much clearer.

If you're following along or trying this too, let’s connect and learn together

0
Subscribe to my newsletter

Read articles from Vaishnavi D directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Vaishnavi D
Vaishnavi D