Port Forwarding
To connect to a pod, you can
- use services (using
kubectl expose pod <podName>to expose the pod's IP), OR - connect to the pod directly using port forwarding (e.g. for testing/debugging).
Forwarding a local network port
To port a local network port to a port in the pod:
# kubectl port-forward <podName> <localPort>:<podPort>
kubectl port-forward kubia-manual 8888:8080
# Forwarding from 127.0.0.1:8888 -> 8080
# Forwarding from [::1]:8888 -> 8080
You can then connect to the pod:
curl localhost:8888
# You've hit kubia-manual
References
- Kubernetes in Action (Marko Lukša) — Chapter 3. Pods: running containers in Kubernetes