DEV Community

Aisalkyn Aidarova
Aisalkyn Aidarova

Posted on

kubernetes project #1

“Run ONE Web App in Kubernetes and Access It”

If someone understands this project, Kubernetes will finally click.


What you will build

You will run one containerized web app in Kubernetes and access it from your browser.

Image

Image

Image

Browser → Service → Pod → Container
Enter fullscreen mode Exit fullscreen mode

here we see:

  • What a Pod is
  • Why Kubernetes exists
  • How traffic reaches a container
  • Why Kubernetes networking is different from Docker

If this is not clear → nothing else will be clear.


PROJECT GOAL

✔ Run an app in Kubernetes
✔ Expose it
✔ Open it in a browser
✔ Understand each step


REQUIREMENTS

  • Minikube (local Kubernetes)
  • kubectl
  • Docker installed

STEP 1 — Start Kubernetes (Minikube)

minikube start
Enter fullscreen mode Exit fullscreen mode

Verify:

kubectl get nodes
Enter fullscreen mode Exit fullscreen mode

Expected:

NAME       STATUS   ROLES    AGE   VERSION
minikube   Ready    control-plane   ...
Enter fullscreen mode Exit fullscreen mode

Why:

Kubernetes always runs workloads on nodes.


STEP 2 — Create a Pod (Smallest Kubernetes unit)

Create file: pod.yaml

apiVersion: v1
kind: Pod
metadata:
  name: hello-pod
  labels:
    app: hello
spec:
  containers:
  - name: hello-container
    image: nginx
    ports:
    - containerPort: 80
Enter fullscreen mode Exit fullscreen mode

Apply it:

kubectl apply -f pod.yaml
Enter fullscreen mode Exit fullscreen mode

Check:

kubectl get pods
Enter fullscreen mode Exit fullscreen mode

Why:

A Pod is the smallest thing Kubernetes runs — not a container.


STEP 3 — Verify Pod is Running

kubectl describe pod hello-pod
Enter fullscreen mode Exit fullscreen mode

Key things to notice:

  • Pod IP
  • Container status
  • Events

Explain to students:

Kubernetes assigned an IP, started the container, and is monitoring it.


STEP 4 — Create a Service (Expose the Pod)

Create file: service.yaml

apiVersion: v1
kind: Service
metadata:
  name: hello-service
spec:
  type: NodePort
  selector:
    app: hello
  ports:
  - port: 80
    targetPort: 80
    nodePort: 30007
Enter fullscreen mode Exit fullscreen mode

Apply:

kubectl apply -f service.yaml
Enter fullscreen mode Exit fullscreen mode

Check:

kubectl get svc
Enter fullscreen mode Exit fullscreen mode

Why:

Pod IPs are not stable.
Services provide stable access.


STEP 5 — Access from Browser

Run:

minikube ip
Enter fullscreen mode Exit fullscreen mode

Open browser:

http://<MINIKUBE_IP>:30007
Enter fullscreen mode Exit fullscreen mode

You should see:

Welcome to nginx!
Enter fullscreen mode Exit fullscreen mode

This is Kubernetes working.


STEP 6 — Prove Kubernetes Self-Healing (Key Concept)

Delete the Pod:

kubectl delete pod hello-pod
Enter fullscreen mode Exit fullscreen mode

Check:

kubectl get pods
Enter fullscreen mode Exit fullscreen mode

Result:
❌ Pod is gone
❌ Service has nothing to route to

Explain:

This is why Pods alone are NOT production-ready.


WHAT YOU LEARNED (This is huge)

Concept You now understand
Pod Smallest unit
Service Stable networking
NodePort External access
Labels How Services find Pods
Why Deployments exist Pods die

VERY IMPORTANT REALIZATION

Kubernetes did not recreate the Pod
That’s why we need Deployments next

Top comments (0)