kubectl 命令自动补全

https://www.cnblogs.com/blablablabla/p/9646232.html

linux:

# apt-get install -y bash-completion
# locate bash_completion /usr/share/bash-completion/bash_completion
# source /usr/share/bash-completion/bash_completion
# source <(kubectl completion bash)

成功实现命令自动补全

root@ubuntu-128:~# kubectl get
apiservices.apiregistration.k8s.io                            horizontalpodautoscalers.autoscaling                          podtemplates
certificatesigningrequests.certificates.k8s.io                ingresses.extensions                                          priorityclasses.scheduling.k8s.io
clusterrolebindings.rbac.authorization.k8s.io                 jobs.batch                                                    replicasets.apps
clusterroles.rbac.authorization.k8s.io                        leases.coordination.k8s.io                                    replicasets.extensions
componentstatuses                                             limitranges                                                   replicationcontrollers
configmaps                                                    mutatingwebhookconfigurations.admissionregistration.k8s.io    resourcequotas
controllerrevisions.apps                                      namespaces                                                    rolebindings.rbac.authorization.k8s.io
cronjobs.batch                                                networkpolicies.extensions                                    roles.rbac.authorization.k8s.io
customresourcedefinitions.apiextensions.k8s.io                networkpolicies.networking.k8s.io                             secrets
daemonsets.apps                                               nodes                                                         serviceaccounts
daemonsets.extensions                                         persistentvolumeclaims                                        services
deployments.apps                                              persistentvolumes                                             statefulsets.apps
deployments.extensions                                        poddisruptionbudgets.policy                                   storageclasses.storage.k8s.io
endpoints                                                     pods                                                          validatingwebhookconfigurations.admissionregistration.k8s.io
events                                                        podsecuritypolicies.extensions                                volumeattachments.storage.k8s.io
events.events.k8s.io                                          podsecuritypolicies.policy
root@ubuntu-128:~# kubectl get
apiservices.apiregistration.k8s.io                            horizontalpodautoscalers.autoscaling                          podtemplates
certificatesigningrequests.certificates.k8s.io                ingresses.extensions                                          priorityclasses.scheduling.k8s.io
clusterrolebindings.rbac.authorization.k8s.io                 jobs.batch                                                    replicasets.apps
clusterroles.rbac.authorization.k8s.io                        leases.coordination.k8s.io                                    replicasets.extensions
componentstatuses                                             limitranges                                                   replicationcontrollers
configmaps                                                    mutatingwebhookconfigurations.admissionregistration.k8s.io    resourcequotas
controllerrevisions.apps                                      namespaces                                                    rolebindings.rbac.authorization.k8s.io
cronjobs.batch                                                networkpolicies.extensions                                    roles.rbac.authorization.k8s.io
customresourcedefinitions.apiextensions.k8s.io                networkpolicies.networking.k8s.io                             secrets
daemonsets.apps                                               nodes                                                         serviceaccounts
daemonsets.extensions                                         persistentvolumeclaims                                        services
deployments.apps                                              persistentvolumes                                             statefulsets.apps
deployments.extensions                                        poddisruptionbudgets.policy                                   storageclasses.storage.k8s.io
endpoints                                                     pods                                                          validatingwebhookconfigurations.admissionregistration.k8s.io
events                                                        podsecuritypolicies.extensions                                volumeattachments.storage.k8s.io
events.events.k8s.io                                          podsecuritypolicies.policy

对于CentOS而言,没有locate 和 bash_completion需要安装对应的rpm包

mlocate

http://www.rpmfind.net/linux/rpm2html/search.php?query=mlocate(x86-64)

bash_completion包

https://download.csdn.net/download/ggwanbo/10407348

按照上述命令执行后,成功实现

[root@test images]# kubectl get po
poddisruptionbudgets.policy       podsecuritypolicies.extensions    podtemplates
pods                              podsecuritypolicies.policy        policies.authentication.istio.io

 

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐