Room 17
NODEPORT & LOADBALANCER
The Gateway
- ClusterIP only works inside the cluster. To let the outside world in, you need NodePort or LoadBalancer.
- Expose a service and access it from outside the cluster.
📜 Mission Briefing
- Apply
nodeport-svc.yaml- exposes an nginx deployment on a NodePort. - Find the assigned NodePort:
kubectl get svc gateway-svc. - Access the service using the node IP and NodePort.
- The service returns a page with a hidden password in an HTML comment.
- Use
curlto fetch the page and grep for the password. - The password is
nodeport3.
Key Commands
| Command | Purpose |
|---|---|
kubectl get svc -o wide |
Services with type and ports |
kubectl get nodes -o wide |
Node IPs |
kubectl describe svc NAME |
Service details including NodePort |
curl NODE_IP:NODE_PORT |
Access NodePort service |
NodePort & LoadBalancer
# NodePort: Exposes on all nodes at a static port (30000-32767)
apiVersion: v1
kind: Service
metadata:
name: nodeport-svc
spec:
type: NodePort
selector:
app: my-app
ports:
- port: 80 # Service port (internal)
targetPort: 8080 # Container port
nodePort: 30080 # Static node port (optional, auto-assigned if omitted)
---
# LoadBalancer: Provisions external LB (in cloud environments)
apiVersion: v1
kind: Service
metadata:
name: lb-svc
spec:
type: LoadBalancer
selector:
app: my-app
ports:
- port: 80
targetPort: 8080
# NodePort flow: External → NodeIP:NodePort → Service → Pod:TargetPort
# Find NodePort
kubectl get svc nodeport-svc
# NAME TYPE CLUSTER-IP PORT(S) AGE
# nodeport-svc NodePort 10.96.x.x 80:30080/TCP 1m
# Get node IP
kubectl get nodes -o wide
# Or for Kind:
docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' escape-room-control-plane
# Access the service
curl http://<node-ip>:30080
# In Kind, use port mappings in kind-config.yaml for LoadBalancer:
# extraPortMappings:
# - containerPort: 30080
# hostPort: 30080
Hints
Hint 2
For Kind, get the node container IP:
Hint 3
The password is nodeport3.