[Kubernetes] – Using port-forward to expose applications for debugging purposes

1_fe7IqPpDckaVjjysqq8jhg

The command kubectl port-forwardallow us to expose a port.

When it should be used? 

It is the ideal solution for when would like to expose a service remotely and has not there an ingress set up to expose the resource. For example, a backend or database application which should receive requests just from a front-end solution.

Example of Usage

$kubectl port-forward : 

NOTE: The container port can be found in the pod or deployment resources. You can use, for example, the command $ kubectl describe to check it. Also, you can get the spec by using the following command.

kubectl get pods <pod-name> --template='{{(index (index .spec.containers 0).ports 0).containerPort}}{{"\n"}}'

Then, after that, you will be able to have access to the container in the pod by the exposed port. For example, would be possible to ping it ($ ping http://127.0.0.1:port-to-exposed).

NOTE: See here a full example to understand how it works better. Also, feel free to check related post by searching for the Kubernetes tag in this website.

Sponsored by:

Logo-horizontalCP Logo Big - vertical invert (1)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s