Skip to content

Instantly share code, notes, and snippets.

@thinhdanggroup
Created March 13, 2022 04:04
Show Gist options
  • Save thinhdanggroup/df49fbd53b779b7c6157f508bc13a179 to your computer and use it in GitHub Desktop.
Save thinhdanggroup/df49fbd53b779b7c6157f508bc13a179 to your computer and use it in GitHub Desktop.
Access another pod over SSH tunnel in K8s
  1. Install devspace to access k8s easily
    brew install devspace
  2. accessable-pod is a pod that you can access over ssh
    devspace -n <accessable-pod> enter -- bash -c "echo $(cat ~/.ssh/id_rsa.pub) >> ~/.ssh/authorized_keys"
  3. copy local key to
    cat << EOF >> ~/.ssh/config
    Host ssh-server
        Hostname 127.0.0.1
        User root
        Port 2300
        ProxyCommand devspace -n sre enter -- nc localhost 2300
        IdentitiesOnly yes
    EOF
  4. open tunnel, <targer_id>:<target_port> is ip and port that you want to connect
    ssh ssh-server -vvv -L8000: <targer_id>:<target_port>
  5. test connection
    telnet localhost 8000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment