kubernetes project #1
Source: Dev.to
Overview
Run a single containerized web app in Kubernetes and access it from your browser:
Flow: Browser → Service → Pod → Container
This exercise demonstrates:
- What a Pod is
- Why Kubernetes exists
- How traffic reaches a container
- How Kubernetes networking differs from Docker
Understanding this will clarify many other Kubernetes concepts.
Prerequisites
- Minikube (local Kubernetes) installed
kubectlinstalled- Docker installed
Start Minikube:
minikube start
Verify the node is ready:
kubectl get nodes
Expected output
NAME STATUS ROLES AGE VERSION
minikube Ready control-plane ... ...
Kubernetes always runs workloads on nodes, so a node must be available.
Create a Pod
Create a file named pod.yaml:
apiVersion: v1
kind: Pod
metadata:
name: hello-pod
labels:
app: hello
spec:
containers:
- name: hello-container
image: nginx
ports:
- containerPort: 80
Apply the manifest:
kubectl apply -f pod.yaml
Check that the Pod is running:
kubectl get pods
Describe the Pod to see details such as the assigned IP, container status, and events:
kubectl describe pod hello-pod
Key points
- A Pod is the smallest unit Kubernetes runs (it can contain one or more containers).
- Pods receive a unique IP address, but that IP is not stable.
Expose the Pod with a Service
Create a file named service.yaml:
apiVersion: v1
kind: Service
metadata:
name: hello-service
spec:
type: NodePort
selector:
app: hello
ports:
- port: 80
targetPort: 80
nodePort: 30007
Apply the Service:
kubectl apply -f service.yaml
Verify the Service:
kubectl get svc
The Service provides a stable endpoint (NodePort) that forwards traffic to the Pod, regardless of the Pod’s changing IP.
Access the Application
Retrieve Minikube’s IP address:
minikube ip
Open a browser and navigate to:
http://<minikube-ip>:30007
You should see the default Nginx welcome page:
Welcome to nginx!
This confirms that the web app is running in Kubernetes and reachable from outside the cluster.
Cleanup
Delete the Pod:
kubectl delete pod hello-pod
Confirm it’s gone:
kubectl get pods
The Pod disappears, illustrating why Pods alone are not production‑ready—they do not self‑heal when they fail.
Core Concepts Recap
| Concept | Description |
|---|---|
| Pod | Smallest unit of deployment; may contain one or more containers. |
| Service | Provides stable networking (IP/Port) to access Pods. |
| NodePort | Exposes a Service on a static port on each node, enabling external access. |
| Labels | Key/value pairs used by Services (and other controllers) to select Pods. |
| Deployment | Manages replica sets; ensures Pods are recreated automatically when they die. |
Understanding Pods, Services, and Labels sets the foundation for using Deployments, which handle pod lifecycle and scaling in production environments.