常用 Kubernetes 命令,复制,粘贴,这就是生活。
kubectl get secret mys --namespace=na -oyaml | grep -v '^\s*namespace:\s' | kubectl apply --namespace=nb -f -
kubectl get pods --all-namespaces | grep Evicted | awk '{print $2 " --namespace=" $1}' | xargs kubectl delete pod # Delete by label kubectl delete pod -n idaas-book -l app.kubernetes.io/name=idaas-book
kubectl rollout restart deploy/xxx -n your-namespace
# kubectl scale -h kubectl scale --replicas=1 deploy/xxx -n your-namespace
kubectl get secret my-creds -n mysql -o jsonpath="{.data.ADMIN_PASSWORD}" | base64 --decode
export KUBECONFIG=~/.kube/config:~/.kube/anotherconfig kubectl config view --flatten > ~/.kube/config-all cp ~/.kube/config-all ~/.kube/config # 顺手把权限改了,避免 helm 或 kubectl 客户端 warning chmod 600 ~/.kube/config
ns=your-namespace for resource in `kubectl api-resources --verbs=list --namespaced -o name | xargs -n 1 kubectl get -o name -n $ns`; do kubectl get $resource -n $ns; # kubectl patch $resource -p '{"metadata": {"finalizers": []}}' --type='merge' -n $ns; done
# 根据重启次数排序 kubectl get pods --sort-by='.status.containerStatuses[0].restartCount' -A