Learning Kubernetes From Scratch (Part 3) – Services
By Newt / February 16, 2026 / No Comments / Uncategorized
π Kubernetes Services Explained π¦
In this section, weβll break down how Kubernetes Services work by exposing our existing nginx pod internally and externally. Youβll see how ClusterIP and NodePort services behave, how they select pods, and how traffic flows through the cluster. Letβs dive in! π³βοΈ
1. Initial Setup π
First, we verified that our nginx pod was running and confirmed its labels:
kubectl get pods --show-labels
Observed output:
- Pod name: nginx-pod
- Status: Running π’
- Labels:
app=web,tier=frontendπ·οΈ
2. Creating Kubernetes Services π§©
We created two different service types to expose the same pod in different ways.
A. ClusterIP Service (Internal Access) π
Create the file 01-clusterip-service.yaml:
apiVersion: v1
kind: Service
metadata:
name: nginx-service-internal
spec:
type: ClusterIP
selector:
app: web
tier: frontend
ports:
- protocol: TCP
port: 80
targetPort: 80
B. NodePort Service (External Access) π
Create the file 02-nodeport-service.yaml:
apiVersion: v1
kind: Service
metadata:
name: nginx-service-external
spec:
type: NodePort
selector:
app: web
tier: frontend
ports:
- protocol: TCP
port: 80
targetPort: 80
nodePort: 30080
3. Deploying the Services π
We applied both service definitions to the cluster:
kubectl apply -f exercises/1-basics/services/01-clusterip-service.yaml
kubectl apply -f exercises/1-basics/services/02-nodeport-service.yaml
4. Verifying Services π
Next, we checked that the services were created successfully:
kubectl get services
Observed output:
- nginx-service-internal (ClusterIP): 88.888.888.888:80 π
- nginx-service-external (NodePort): 88.888.888.888:30080 π
- kubernetes (default): 88.88.8.8:443 βοΈ
5. Accessing the Application π
# Get Minikube IP π§
minikube ip
Output:
- Minikube IP: 192.168.49.2
# Open NodePort service using Minikube πͺ
minikube service nginx-service-external
This automatically opened the service in the browser and created a tunnel.
Access Points Created π
- Internal Access (ClusterIP):
- Accessible only inside the cluster
- IP: 88.888.888.123
- Port: 80
- External Access (NodePort):
- URL:
http://192.168.49.2:30080 - Minikube tunnel:
http://127.0.0.1:54155
- URL:
6. Key Concepts Covered π§
- Service Types:
- ClusterIP β internal cluster communication π
- NodePort β external access π
- Service Selection:
- Uses pod labels:
app=web,tier=frontend
- Uses pod labels:
- Port Mapping:
- Service port: 80
- Target port: 80 (container port)
- Node port: 30080
This setup allows the nginx pod to be:
- Internally accessible via ClusterIP π
- Externally accessible via NodePort π
- Discoverable by other pods using service DNS π
Whatβs Next? βοΈ
In the next part, weβll move on to Deployments and see how Kubernetes helps us manage replicas, updates, and scaling automatically. Letβs keep going! π
