Kubernetes kubectl简介-命令补全
Kubectl
是一个通过命令行对kubernetes集群进行管理的客户端工具
命令补全
1.命令补全 如果报错缺少依赖包
[root@xksmaster1 k8s_images]# source <(kubectl completion bash)
[root@xksmaster1 k8s_images]# kubectl cre-bash: _get_comp_words_by_ref: command not found
#yum -y install bash-completion
2、在使用kubectl 自动补全报如下错误
报错:-bash: _get_comp_words_by_ref: command not found
解决方法:如果安装了bash-completion,还报上面的错误进行如下命令。
#source /usr/share/bash-completion/bash_completion
3.vim /etc/profile 放到 系统环境变量中 开机启动执行
source /usr/share/bash-completion/bash_completion
source <(kubectl completion bash)
查看集群情况
[root@xksmaster1 k8s_images]# kubectl cluster-info
Kubernetes control plane is running at https://192.168.19.180:6443
CoreDNS is running at https://192.168.19.180:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
查看版本:api-resources、version、api-versions
kubectl api-versions
kubectl api-resources
kubectl version
各种命令
# kubectlget service--all-namespaces -o wide
# kubectlget pods--all-namespaces -o wide
# kubectlget nodes--all-namespaces -o wide
# kubectl get deployment --all-namespaces
# kubectlget deployment -n magedu -o wide #更改显示格式
# kubectl describe pods magedu-tomcat-app1-deployment -n magedu #查看某个资源详细信息
# kubectl create -f tomcat-app1.yaml
# kubectl apply -f tomcat-app1.yaml
# kubectl delete -f tomcat-app1.yaml
# kubectl create -f tomcat-app1.yaml--save-config --record
# kubectl apply -f tomcat-app1.yaml --record #推荐命令
# kubectl exec -it magedu-tomcat-app1-deployment-6bccd8f9c7-g76s5 bash -n magedu
# kubectl logs magedu-tomcat-app1-deployment-6bccd8f9c7-g76s5 -n magedu
# kubect delete pods magedu-tomcat-app1-deployment-6bccd8f9c7-g76s5 -n magedu