The reason for this is basically the following:
I need to go out for the public IP of my Kubernetes cluster to debug an external website and I want to do it from my local machine (using the browser in fact). Therefore, I will be able to navigate from my local using crossing traffic through a pod, using Openssh-Server as SOCKSV5 Server.
REMEMBER: DEBUGING OR TESTING PURPOSE!!!
The official image of this SSH server is from linuxserver.io
Build your own image. The Dockerfile has a slight change from the official image. Enable TCP forward.
FROM docker.io/linuxserver/openssh-server:latest
# latest is not a good practice, but this is for testing purpose
RUN sed -i 's/AllowTcpForwarding no/AllowTcpForwarding yes/g' /etc/ssh/sshd_config
Inside the script build.sh change the docker hub username/repository (or custom repository).
#!/usr/bin/env bash
# I'm using buildx since I'm using Kubernetes nodes with amd64 but my personal laptop it's arm64
docker buildx build --platform linux/amd64 \
--no-cache \
--pull \
-t docker.io/containerscrew/socks-k8s:latest .
docker push docker.io/containerscrew/socks-k8s:latest
Change containerscrew/socks-k8s and put your own user.
Execute the script:
./build.sh
kubectl apply -f pod.yml
Take a look in the pod.yml and change what you need
kubectl port-forward pod/socks-pod 2222:2222 -n default
ssh -D8080 admin@localhost -p 2222
Password is admin (the password can be changed in pod.yml)
Also you can execute the following command to run in background
ssh -qNfC -D8080 admin@localhost -p 2222
First:
curl ifconfig.me
Then:
curl -x socks5h://127.0.0.1:8080 ifconfig.me
To be able to tunnel connections in your browser, you need to install a plugin such as Socks5 Proxy. Configure it to make requests to 127.0.0.1:8080.