0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

kubectlコマンドでタブ補完を使えるようにする

Posted at

はじめに

シェルはbash派なんですが、bashだとタブを押すとでコマンドを補完してくれます。
kubectlコマンドもシェルで補完してくれますが、サブコマンドは補完してくれません。
kubectl get podくらいなら別にいいんですが、describeとかは地味に面倒。そこで調べてみると、サブコマンドまでタブで補完してくれる機能があったので、試してみました。

環境変数の設定

「.bashrc」ファイルに以下の一行を追記する。
source <(kubectl completion bash)

.bashrc
# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

# Uncomment the following line if you don't like systemctl's auto-paging feature:
# export SYSTEMD_PAGER=

# User specific aliases and functions

source <(kubectl completion bash) #added

ドット実行で反映させる。

$ . .bashrc

動作確認

$ kubectl de
delete    describe
$ kubectl describe p
persistentvolumeclaims             poddisruptionbudgets.policy        pods.metrics.k8s.io                podtemplates
persistentvolumes                  pods                               podsecuritypolicies.policy         priorityclasses.scheduling.k8s.io
$ kubectl describe pod -n sock-shop carts-
carts-5fc45568c4-r4fqk     carts-db-64ff6c747f-vlghp

これだけだと感動が伝わらないんですが、サブコマンドだけでなく、namespaceやリソース名なんかもタブで補完できるようになりました。
特にPodはシステムがランダムな英数字を付与するし、起動するたびにそこが変わるので、毎回確認する必要があったけど、これで確認する手間が省けるようになりました。

ちょっとしたことですが、これでだいぶ楽になります!

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?