Kubectl Services
Expose pods stably with ClusterIP, NodePort, and LoadBalancer.
- kubectl service
- expose deployment
- clusterip
- port-forward
- endpoints
Kubectl Services
Expose pods stably with ClusterIP, NodePort, and LoadBalancer.
Commands
| Command | What it does |
|---|---|
kubectl get svc | List services and their IPs/ports |
kubectl expose deploy api --port=80 --target-port=8080 | Create a ClusterIP service |
kubectl get endpoints api | Which pod IPs back the service |
kubectl port-forward svc/api 8080:80 | Local access without exposing |
kubectl describe svc api | Selector, ports, and events |
Example
kubectl expose deploy api --port=80 --target-port=8080
kubectl get endpoints api
kubectl port-forward svc/api 8080:80
FAQ
No endpoints — what broke?
The service selector matches zero pods: compare kubectl get pods -l <selector> against svc describe output.
ClusterIP vs LoadBalancer?
ClusterIP is internal-only; LoadBalancer provisions a cloud LB (and costs money) for public traffic.
常見問題
No endpoints — what broke?
The service selector matches zero pods: compare kubectl get pods -l <selector> against svc describe output.
ClusterIP vs LoadBalancer?
ClusterIP is internal-only; LoadBalancer provisions a cloud LB (and costs money) for public traffic.
Kubernetes
Kubectl Config and Context
Point kubectl at the right cluster and switch contexts safely.
Kubectl Pods
Inspect pods, describe failures, and get a shell inside.
Kubectl Deployments
Create, update, and inspect Deployments that own your pods.
Kubectl Ingress
Route external HTTP traffic to services by host and path.