Forrest logo
back to the kubectl tool

kubernetes:warp:61f04

Forward one or more local ports to a pod.
$ kubectl port-forward pod/${pod_name} ${local_port}:${pod_port}
try on your machine

This command is used to forward traffic from a specific port on your local machine to a port on a Kubernetes pod.

Here is the breakdown:

  • kubectl port-forward is the command to forward network traffic.
  • pod/${pod_name} specifies the pod to which you want to forward traffic. Replace ${pod_name} with the name of the specific pod.
  • ${local_port}:${pod_port} determines the ports to use for forwarding. ${local_port} specifies the port on your local machine, while ${pod_port} indicates the port within the pod. Replace these variables with the desired port numbers.

For example, if you have a pod named "my-pod" running in your Kubernetes cluster, and you want to forward local port 8080 to port 80 within the pod, the command would be:

kubectl port-forward pod/my-pod 8080:80

This would start forwarding traffic from your local machine's port 8080 to port 80 of the "my-pod" pod. Any requests made to your local machine's port 8080 would be forwarded to port 80 of the specified pod.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the kubectl tool