Life's random bits By b1thunt3r (aka Ishan Jain)…
Debug Kubernetes services with port-forward

Debug Kubernetes services with port-forward

Ishan jain
When ingress isn't working properly, port-forward to rescue.

There have been times when a deployment to kubernetes fails, rendering ingress unusable. To fix it, you need to access service behind the ingress. kubectl provides port forwarding functionality to be able to connect to services behind ingress.

kubectl port-forward <kind>/<kind_name> -n <namespace> <host_port>:<container_port>

Where:

  • kind: resource kind. i.e. pod, service, etc
  • kind_name: name of the kind
  • namespace: name of the namespace
  • host_port: port on your local machine
  • container_port: port in the container

For example, following command will forward https port in my-service in my-namespace to 8443 on local machine.

kubectl port-forward service/my-service -n my-namespace 8443:https

Resources

kubectl port-forward | Kubernets