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

Accessing a Kubernetes pod via port-forwarding to interact with MongoDB and Kafka results in an error with the fork call. #156

Open
Montana opened this issue Feb 28, 2024 · 0 comments

Comments

@Montana
Copy link

Montana commented Feb 28, 2024

Hi all,

My current MongoDB and Kafka environments are hosted within Kubernetes pods. To interact with these applications, we first need to authenticate with the Kubernetes cluster and then establish a port-forwarding session.

To achieve this, I'm using two separate commands in our local terminal environment (note: the following values have been altered for security purposes):

In Terminal 1, we set up the connection to the database by executing kubeConnection.sh.

I have defined environment variables for the database port, endpoint, and the name of the application service. I then use kubectl to run a temporary pod using a specific Docker image, which listens on the designated port and forwards TCP connections to the MongoDB endpoint:

export DEV_DB_PORT=27017
export DEV_DB_ENDPOINT=db.endpoint
export DEV_APP_SERVICE_NAME=docdb-access
kubectl run ${DEV_APP_SERVICE_NAME} --image=dockerurl/docker/data-platforms/common/socat:latest -it --tty --rm --expose=true --port=${DEV_DB_PORT} tcp-listen:${DEV_DB_PORT},fork,reuseaddr tcp connect:${DEV_DB_ENDPOINT}:${DEV_DB_PORT}

In Terminal 2, I establish the port-forwarding session with kubePortForward.sh. Utilizing the same environment variables for consistency, I've forwarded the local port to the service port in the Kubernetes cluster, allowing direct access to the database through the local machine:

export DEV_DB_PORT=27017
export DEV_DB_ENDPOINT=db.endpoint
export DEV_APP_SERVICE_NAME=docdb-access
kubectl port-forward service/${DEV_APP_SERVICE_NAME} ${DEV_DB_PORT}:${DEV_DB_PORT}

Thank you all,
Michael Mendy

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

No branches or pull requests

1 participant