LoginSignup
8
4

More than 3 years have passed since last update.

kubectl port-forward 、僕はもう疲れたよ

Last updated at Posted at 2019-11-24

kubectl port-forward を楽にしてくれるかも?なツールを探したので記録しておく。

CLI の kubefwd

  • txn2/kubefwd
  • sudo kubefwd svc -n {namespace} で、ドバドバっと port-forward してくれる。
    • sudo なんで、パスワード入力必要。
  • -n {namespace} は複数いれられるみたいだし、-l で Selector も使えるらしい。未検証。
  • kind (kubernetes in docker) で使う時は -c を使う。
    • sudo kubefwd svc -n default -c ~/.kube/kind-config-kind1 でいけた。
    • 上記は kind1 というクラスターを作成した状態。
$ sudo kubefwd svc -n default -c ~/.kube/kind-config-kind1
INFO[22:20:38]  _          _           __             _
INFO[22:20:38] | | ___   _| |__   ___ / _|_      ____| |
INFO[22:20:38] | |/ / | | | '_ \ / _ \ |_\ \ /\ / / _  |
INFO[22:20:38] |   <| |_| | |_) |  __/  _|\ V  V / (_| |
INFO[22:20:38] |_|\_\\__,_|_.__/ \___|_|   \_/\_/ \__,_|
INFO[22:20:38]
INFO[22:20:38] Version 1.10.0
INFO[22:20:38] https://github.com/txn2/kubefwd
INFO[22:20:38]
INFO[22:20:38] Press [Ctrl-C] to stop forwarding.
INFO[22:20:38] 'cat /etc/hosts' to see all host entries.
INFO[22:20:38] Loaded hosts file /etc/hosts
INFO[22:20:38] Hostfile management: Original hosts backup already exists at /Users/higuchi/hosts.original
INFO[22:20:38] Forwarding: echo:8080 to pod echo-599d77c5c7-4plfp:8080
INFO[22:20:38] Forwarding: echo:80 to pod echo-599d77c5c7-4plfp:8080
WARN[22:20:38] WARNING: No Pod selector for service kubernetes in default on cluster .
INFO[22:20:38] Saving hosts file
  • これは、 echo-server をデプロイしている状況で、下記のようにアクセスできる。
    • curl echo:8080
    • namespace 内の Pod を対象に一括でやってくれるので便利。
  • ただし hosts ファイルを変更しているので注意。上記の場合は下記が追加されていた。そりゃそうだよね。sudo も要求するし。
    • 127.1.27.1 echo echo.default.svc.cluster.local echo.default
  • 最後に、インストールは、 Mac なら下記。windows のインストールもあったし docker も用意されているっぽい。
    • brew install txn2/tap/kubefwd

GUI の kube-forwarder

kubeforwarder3.png

  • まずは、 ADD A CLUSTER から。
  • クラスターを追加したら、 Add a Resource で、クラスターを選択する。
    • この時 kind (kubernetes in docker) を使う場合は、 Add Kubernetes config manually からファイル指定で ~/.kube/kind-config-kind1 などを選ぶか、 config の内容を貼り付けてあげれば良い。
    • 今気づいたけど、 config 貼り付けの方はクラスターを作り直したらつながらなくて、ファイル指定はつながるかも?このあと試す。
  • 下記の画面を、入力していくと完成。 (Deployment も port-forward できたんだね。)

kubeforwarder2.png

  • 再生ボタン?で、ポートォォ、フォワァァァド!
  • open http://localhost:8080

kubeforwarder4.png

  • インストールは、 Mac の場合、ダウンロードも、 brew もある。 windows 、 linux もあるみたいなので、公式をチェック。

まとめ

8
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
4