This is a simple thing that I've discover recently, it's not a revolution or something really hidden, but I think it's cool to share it!
So to forward a service port in Kubernetes, you just have to do
kubectl port-forward element to expose [local port:]pod/service/deploy... port
examples
# Expose port 80 of the service on the local port 80
kubectl port-forward svc/example-service 80
# Expose port 80 of the pod on the local port 36000
kubectl port-forward pod/pod-test 36000:80
# Expose port 27017 of the deployment on a random free local port
kubectl port-forward deployment/mongo :27017
Links
- Kubernetes tutorial about it: https://kubernetes.io/docs/tasks/access-application-cluster/port-forward-access-application-cluster/
- Kubectl documentation about port-forward : https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#port-forward
I hope it will help you!
Top comments (0)