I have multiple k8s cluster in private network which I can access only through a jumpbox/bastion host.
For example below are my k8s clusters:
k8s-c3 with endpoint ip 192.168.220.3
k8s-c4 with endpoint ip 192.168.220.4
k8s-c5 with endpoint ip 192.168.220.5
What I have been able to do is:
Create a ssh tunnel to 1 endpoint at a time eg: ssh -i /root/.ssh/id_rsa -4 -fNT -L 6443:192.168.220.3:6443 user@1.2.3.4
and use kubectl command from my local machine.
What I want to do is: Create a ssh tunnel to my bastion host for port 6443 for all the 3 destinations mentioned above and use kubectl config use-context to switch and connect to different clusters from my local machine.
Is this possible? If so how? If not possible using ssh what other alternatives do I have? Would really appreciate sample code example.
Thanks
The ssh tunnel allows to open more than one tunnel in the same command, to multiple machines. The gotcha here is that you would have to use different ports, and change in the kubectl config file the ports you are tunneling.
The command would have multiple -L
:
-L 6443:192.168.220.3:6443 -L 6444:192.168.220.4:6443 -L 6445:192.168.220.5:6443
And each cluster
entry in the .kube/config
file should have the server with the correct port (6443, 6444 or 6445).
I'm sorry that I cannot test this right now, but in theory, that's how I would do.