臨時容器的作用:
當由于容器崩潰或容器鏡像不包含調試工具而導致 kubectl exec 無用時, 臨時容器對于交互式故障排查很有用。
開啟臨時容器
vi /usr/lib/systemd/system/kube-apiserver.service
--feature-gates=EphemeralContainers=true
vi /usr/lib/systemd/system/kube-controller-manager.service
--feature-gates=EphemeralContainers=true
vi /usr/lib/systemd/system/kube-scheduler.service
--feature-gates=EphemeralContainers=true
vi /usr/lib/systemd/system/kube-proxy.service
--feature-gates=EphemeralContainers=true
vi /etc/kubernetes/kubelet-conf.yml
featureGates:
EphemeralContainers: true
重啟所有服務
臨時容器的使用
K8s 1.16+
https://kubernetes.io/docs/concepts/workloads/pods/ephemeral-containers/
K8s 1.18+
kubectl alpha debug redis-new-5b577b46c7-2jv4j -ti --image=registry.cn-beijing.aliyuncs.com/dotbalo/debug-tools
K8s 1.20+
kubectl debug redis-new-5b577b46c7-2jv4j -ti --image=registry.cn-beijing.aliyuncs.com/dotbalo/debug-tools
kubectl debug node/k8s-node01 -it --image=registry.cn-beijing.aliyuncs.com/dotbalo/debug-tools