2
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 3 years have passed since last update.

Kubectlのコマンド補完とエイリアスは設定すべし!!

Last updated at Posted at 2021-10-09

エイリアスは設定してたけど・・・コマンド補完は設定してなかったので・・・設定してやったぜ!!

コマンド補完とエイリアスを設定

bashを利用している場合は、以下の設定をすればkubectlのコマンド補完を使えるようになります!!

# コード補完が使えるようにする
$ echo "source <(kubectl completion bash)" >> ~/.bashrc

# エイリアスの設定とエイリアスでコード補完を使えるようにする
$ echo "alias k=kubectl" >> ~/.bashrc
$ echo "complete -F __start_kubectl k" >> ~/.bashrc

# 設定をターミナルへ反映
$ . ~/.bashrc

ターミナルに反映後は、タブを押すとサブコマンドの候補が表示されるようになります。

$ k get {タブ押下}
apiservices.apiregistration.k8s.io                            events.events.k8s.io                                          podtemplates
certificatesigningrequests.certificates.k8s.io                flowschemas.flowcontrol.apiserver.k8s.io                      priorityclasses.scheduling.k8s.io
clusterrolebindings.rbac.authorization.k8s.io                 horizontalpodautoscalers.autoscaling                          prioritylevelconfigurations.flowcontrol.apiserver.k8s.io
clusterroles.rbac.authorization.k8s.io                        ingressclasses.networking.k8s.io                              replicasets.apps
componentstatuses                                             ingresses.networking.k8s.io                                   replicationcontrollers
configmaps                                                    jobs.batch                                                    resourcequotas
controllerrevisions.apps                                      leases.coordination.k8s.io                                    rolebindings.rbac.authorization.k8s.io
cronjobs.batch                                                limitranges                                                   roles.rbac.authorization.k8s.io
csidrivers.storage.k8s.io                                     mutatingwebhookconfigurations.admissionregistration.k8s.io    runtimeclasses.node.k8s.io
csinodes.storage.k8s.io                                       namespaces                                                    secrets
csistoragecapacities.storage.k8s.io                           networkpolicies.networking.k8s.io                             serviceaccounts
customresourcedefinitions.apiextensions.k8s.io                nodes                                                         services
daemonsets.apps                                               persistentvolumeclaims                                        statefulsets.apps
deployments.apps                                              persistentvolumes                                             storageclasses.storage.k8s.io
endpoints                                                     poddisruptionbudgets.policy                                   validatingwebhookconfigurations.admissionregistration.k8s.io
endpointslices.discovery.k8s.io                               pods                                                          volumeattachments.storage.k8s.io
events

ってな感じ。

参考サイト

まとめ

Enjoy the Kubernetes using with command line tools!!

2
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
2
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?