Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix port forwarding in k8s environments #51

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jgilfoil
Copy link

@jgilfoil jgilfoil commented Mar 1, 2024

Problem Statement
In Kubernetes environments, the hostname command will return something like pod-bcf579d67-c9plq instead of just pod. And since you can't know the pod name ahead of time, the value being matched for in /config/nat.conf will be just 'pod' and will fail to match, causing the NAT_ENTRY variable to be empty and enter the dhclient if statement instead of setting the static ip logic. This means port forwarding won't work.

Description of the change

This change checks for the presence of the KUBERNETES_SERVICE_HOST environment variable to determine if the client_init.sh script is being run in k8s. If it is, it strips off the pod name after the first dash, so you'll get just the deployment name, which you can then set in pod-gateway chart values publicPorts.hostname and it will match.

If the env variable isn't present, then it proceeds with the full value from hostname.

Benefits

Port forwarding in Kubernetes will now work properly.

Possible drawbacks

The only limitation with this is if the deployment name has a dash in it, under those circumstances the pod name would be cut off too early. You could probably work around this by cutting off the hostname in the pod-gateway chart.

I've tested this in my own cluster in kubernetes and it worked, the static ip was properly set to 10 per my config and the traffic is getting forwarded to my pod. https://github.com/jgilfoil/home-cluster/pull/121/files

I did not test this change in a regular docker environment.

In kuberentes environment the hostname command will retrun something like pod-bcf579d67-c9plq instead of just pod. And since you can't know the pod name ahead of time, the value being matched for in /config/nat.conf will be just 'pod' and will fail to match, causing the NAT_ENTRY variable to be entry and enter the dhclient loop instead of setting the static ip. This means port forwarding won't work.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant