インターネットアクセスなしでクラスタ外のポッドにSSH経由で接続するにはどうすればよいですか? (K8S)

インターネットアクセスなしでクラスタ外のポッドにSSH経由で接続するにはどうすればよいですか? (K8S)

K8Sクラスター(2つのノードと1つのマスターノード)を作成しましたが、クラスターはインターネットにアクセスできず、テストマシンのみがインターネットにアクセスできます。

クラスタ外でUbuntu-OpenSSHポッドにSSHで接続し、ポート転送を実行したいと思います。

kubectl port-forward pod/ubuntu-ssh 30180:22

openssh-serverがPodでリッスンする30180コンテナポートはどこにありますか?22

ただし、クラスタIPに接続しようとするとエラーが発生します。

$  ssh [email protected] -p 30180
ssh: connect to host 192.X.X.X port 30180: Connection refused

ただし、localhostを使用してこれを行うと正常に動作します。

$ ssh root@localhost -p 30180
root@localhost's password:
Welcome to Ubuntu 20.04.4 LTS (GNU/Linux 5.15.0-25-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

This system has been minimized by removing packages and content that are
not required on a system that users do not log into.

To restore this content, you can run the 'unminimize' command.
Last login: Fri Jul  1 12:39:19 2022 from 127.0.0.1
root@ubuntu-ssh:~#

localhostの代わりにIPアドレスを使用してPodに接続するのに役立つ人はいますか?よろしくお願いします!

より多くの背景情報を見るには、次のチュートリアルに従ってください。 https://sanda-dev.medium.com/ssh-into-kubernetes-pod-without-public-ip-access-fbb9da7f7b26

ベストアンサー1

出力を見ると、次のkubectl port-forward --helpような内容が表示されます。

Options:
      --address=[localhost]: Addresses to listen on (comma separated). Only accepts IP addresses or
localhost as a value. When localhost is supplied, kubectl will try to bind on both 127.0.0.1 and ::1
and will fail if neither of these addresses are available to bind.

デフォルトでは、開いているポートはkubectl port-forwardのみバインドされているため、localhostローカルシステムで開始された接続でのみ機能します。コマンドを実行しているコンピュータの外部に公開するには、port-forward次を追加します。

kubectl port-forward --address=0.0.0.0 ...

これは0.0.0.0「すべてのアドレス」を意味するため、使用可能なすべてのインターフェイスで接続に使用できます。

おすすめ記事