LoginSignup
4
5

More than 5 years have passed since last update.

Kubernetes関連のシェル自動補完詰め合わせ

Last updated at Posted at 2018-11-15

設定後のイメージ

設定後の使用イメージは以下の通り。TAB入力で候補が表示されます。入力途中の補完もあり。

$ kubectl ::TABプッシュ::
alpha          attach         completion     create         exec           logs           proxy          set            wait
annotate       auth           config         delete         explain        options        replace        taint
api-resources  autoscale      convert        describe       expose         patch          rollout        top
api-versions   certificate    cordon         drain          get            plugin         run            uncordon
apply          cluster-info   cp             edit           label          port-forward   scale          version

設定

bash-completionが入ってない場合はapt-get install bash-completionでインストール。

.bashrcに以下を追加。

.bashrc(追加部分のみ)
if [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
    source <(kubectl completion bash)
    source <(helm completion bash)      # いれてない場合は削除
    source <(skaffold completion bash)  # いれてない場合は削除
fi

Dockerの場合はDockerfileに以下を追加

Dockerfile(追加部分のみ)
RUN echo "\
if [ -f /etc/bash_completion ] && ! shopt -oq posix; then\n\
    . /etc/bash_completion\n\
    source <(kubectl completion bash)\n\
    source <(helm completion bash)\n\
    source <(skaffold completion bash)\n\
fi\n\
" >> ~/.bashrc # いれてないものは削除

あとはsource ~/.bashrcか、Dockerならコンテナ再起動で動くはず。

参考ページ

4
5
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
4
5