When deploying applications on Kubernetes, exposing services to external traffic is a critical requirement. MicroK8s, the lightweight Kubernetes distribution, offers three primary methods: NodePort, LoadBalancer (via MetalLB), and Ingress. This article explains each method's use cases, implementation, and tradeoffs.
- Exposes services on static ports (30000-32767) across all cluster nodes
- Direct node IP access without DNS requirements
microk8s kubectl expose deployment nginx --type=NodePort --port=80| Feature | Details |
|---|---|
| Access Pattern | http://:<30000-32767> |
| Networking Layer | L4 (TCP/UDP) |
| Setup Complexity | Minimal |
Best for: Local development and quick testing
- LoadBalancer (MetalLB): Production-Grade Exposure What is LoadBalancer? Assigns dedicated external IPs from a configured pool
Requires MetalLB addon for bare-metal environments
microk8s enable metallb
microk8s kubectl expose deployment nginx --type=LoadBalancer --port=80| Feature | Details |
|---|---|
| Access Pattern | http:// |
| Networking Layer | L4 (TCP/UDP) |
| Setup Complexity | Moderate |
| Best for: Production environments with static IP requirements |
- Ingress: Advanced Routing and Load Balancing What is Ingress?
- Manages external access to services via HTTP/S
- Provides advanced routing, SSL termination, and load balancing
- Requires an Ingress controller (e.g., NGINX, Traefik)
microk8s enable ingressSample Ingress Resource
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: nginx-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- host: example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: nginx
port:
number: 80microk8s kubectl apply -f ingress.yaml
| Feature | Details |
|---|---|
| Access Pattern | http:/// |
| Networking Layer | L7 (HTTP/S) |
| Setup Complexity | High |
| Criteria | NodePort | LoadBalancer | Ingress |
|---|---|---|---|
| IP Usage | Node IPs | Dedicated IP | Shared IP |
| Access Method | Node IP + Port | Dedicated IP | Host/path-based |
| Health Checks | None | None | Built-in |
| Ports | 30000-32767 | Standard ports | Standard ports |
| TLS | Manual config | Manual config | Built-in support |
| Routing | None | None | Host/path-based |
Cost Free Free (MetalLB) Free