Portforward

Port Forwarding

Port forwarding is a subcommand of kubectl, which allows you to forward local ports to a specific Pod using the kubectl port-forward command.

Pod Port Forwarding

Local ports can be forwarded to a port on a specified Pod.

# Listen on ports 5000 and 6000 locally, forwarding data to/from ports 5000 and 6000 in the pod
kubectl port-forward mypod 5000 6000

# Listen on port 8888 locally, forwarding to 5000 in the pod
kubectl port-forward mypod 8888:5000

# Listen on a random port locally, forwarding to 5000 in the pod
kubectl port-forward mypod :5000

# Listen on a random port locally, forwarding to 5000 in the pod
kubectl port-forward mypod 0:5000

Service Port Forwarding

You can also forward local ports to the ports of services, replication controllers, or deployments.


Tunneling into Kubernetes: Port Forwarding

Port forwarding is a handy tool from the toolbox of kubectl, which quickly creates a communication tunnel from your local machine to any pod within Kubernetes.

Making Connections to Pods

Local ports can be effortlessly connected to a specific Pod's port to allow for immediate data flow in both directions.

Linking Up with Services

You're not limited to pods! Cast a line from your local port to the ports designated for services, replication controllers, or entire deployments and get direct access to your Kubernetes resources.

最后更新于