Published on

k8s 常用命令

Authors

命令行补全

kubeadm, kubectl都可以自动补全

apt install bash-completion
// locate bash_completion
source /usr/share/bash-completion/bash_completion
source <(kubectl completion bash)
echo "source <(kubectl completion bash)" >> ~/.bashrc

kubeadm 重置

kubeadm reset
kubeadm reset 执行后不会删除$HOME/.kube文件,执行rm -rf $HOME/.kube

删除k8s上的服务集群

# 先删除deployment 包含了 pods和replicasets.apps
kubectl delete deployments.apps --namespace=mytest --all
# 再删除 services 里面的服务
kubectl delete services --namespace=mytest --all
# 最后删除 namespace
kubectl delete namespaces mytest

排错

kubectl get pods/services/deployment -n [namespace]
kubectl describe pods/services/deployment [podname] -n [namespace]

查看日志

kubectl logs -f [podname/deployment] -c [containername] -n [namespace]