创建上下文

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# 创建并设置 kubeconfig
kubectl config set-cluster example --server=$APISERVER --embed-certs --certificate-authority=$K8S_CA
kubectl config set-credentials test --embed-certs --client-certificate=$K8S_CLIENT_DIR/test.crt --client-key=$K8S_CLIENT_DIR/test.key
kubectl config set-context test@example --cluster=example --user=test
kubectl config use-context test@example

# 查看 kubeconfig
kubectl config view --minify

# kubectl 测试访问
kubectl get pods

切换上下文

1
2
3
4
5
kubectl config use-context test@example

# 查看 kubeconfig
kubectl config view --minify
kubectl get pods

重启

1
kubectl rollout restart -n test-uat deployment powerjob

转发

1
kubectl --kubeconfig=/Users/test/kubeconfigs/test-k8s.conf port-forward --namespace test-prod svc/rabbitmq 5672:5672

排空节点

1
2
3
4
kubectl get nodes
kubectl cordon test-worker-1-01

kubectl drain test-worker-1-01 --force --ignore-daemonsets

清理孤岛容器

1
2
3
journalctl -xfu kubelet
cd /var/lib/kubelet/pods
rm -rf xxxxxxx