对于kubectl
来说还是很新的。我有一个Rancher测试环境(通过Terraform部署(,我正在上面学习。我在尝试将一个新的k8s集群部署到我的环境时收到了一个超时错误。我看了看吊舱,发现了4个舵舱,都有错误:
% kubectl get pods --all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE
cattle-logging rancher-logging-fluentd-linux-6x8vr 2/2 Running 0 20h
cattle-logging rancher-logging-fluentd-linux-9llsf 2/2 Running 0 20h
cattle-logging rancher-logging-fluentd-linux-hhwtb 2/2 Running 0 20h
cattle-logging rancher-logging-fluentd-linux-rzbc8 2/2 Running 0 20h
cattle-logging rancher-logging-log-aggregator-linux-9q6w8 1/1 Running 0 20h
cattle-logging rancher-logging-log-aggregator-linux-b27c4 1/1 Running 0 20h
cattle-logging rancher-logging-log-aggregator-linux-h8q75 1/1 Running 0 20h
cattle-logging rancher-logging-log-aggregator-linux-hhbk7 1/1 Running 0 20h
cattle-system helm-operation-2ztsk 1/2 Error 0 41m
cattle-system helm-operation-7jlwf 1/2 Error 0 12m
cattle-system helm-operation-fv5hq 1/2 Error 0 55m
cattle-system helm-operation-zbdnd 1/2 Error 0 27m
cattle-system rancher-6f77f5cbb4-cs4sp 2/2 Running 0 42m
cattle-system rancher-6f77f5cbb4-gvkv7 2/2 Running 0 42m
cattle-system rancher-6f77f5cbb4-jflnb 2/2 Running 0 42m
cert-manager cert-manager-cainjector-596464bfbd-zj2wg 1/1 Running 0 6h39m
cert-manager cert-manager-df467b89d-c5kdw 1/1 Running 0 6h39m
cert-manager cert-manager-df467b89d-kbvgm 1/1 Running 0 6h39m
cert-manager cert-manager-df467b89d-lndnp 1/1 Running 0 6h40m
cert-manager cert-manager-webhook-55f8bd4b8c-m58n2 1/1 Running 0 6h39m
fleet-system fleet-agent-6688b99df5-n26zf 1/1 Running 0 6h40m
fleet-system fleet-controller-6dc545d5db-f6f2t 1/1 Running 0 6h40m
fleet-system gitjob-84bd8cf9c4-4q95g 1/1 Running 0 6h40m
ingress-nginx nginx-nginx-ingress-controller-58689b79d9-44q95 1/1 Running 0 6h40m
ingress-nginx nginx-nginx-ingress-controller-58689b79d9-blgpf 1/1 Running 0 6h39m
ingress-nginx nginx-nginx-ingress-controller-58689b79d9-wkdg9 1/1 Running 0 6h40m
ingress-nginx nginx-nginx-ingress-default-backend-65d7b58ccc-tbwlk 1/1 Running 0 6h39m
kube-system coredns-799dffd9c4-nmplh 1/1 Running 0 6h39m
kube-system coredns-799dffd9c4-stjhl 1/1 Running 0 6h40m
kube-system coredns-autoscaler-7868844956-qr67l 1/1 Running 0 6h41m
kube-system kube-flannel-5wzd7 2/2 Running 0 20h
kube-system kube-flannel-hm7tc 2/2 Running 0 20h
kube-system kube-flannel-hptdm 2/2 Running 0 20h
kube-system kube-flannel-jjbpq 2/2 Running 0 20h
kube-system kube-flannel-pqfkh 2/2 Running 0 20h
kube-system metrics-server-59c6fd6767-ngrzg 1/1 Running 0 6h40m
kube-system rke-coredns-addon-deploy-job-l7n2b 0/1 Completed 0 20h
kube-system rke-metrics-addon-deploy-job-bkpf2 0/1 Completed 0 20h
kube-system rke-network-plugin-deploy-job-vht9d 0/1 Completed 0 20h
metallb-system controller-7686dfc96b-fn7hw 1/1 Running 0 6h39m
metallb-system speaker-9l8fp 1/1 Running 0 20h
metallb-system speaker-9mxp2 1/1 Running 0 20h
metallb-system speaker-b2ltt 1/1 Running 0 20h
rancher-operator-system rancher-operator-576f654978-5c4kb 1/1 Running 0 6h39m
我想看看重新启动pod是否会让它们变直,但我不知道如何做到这一点。Helm不会出现在kubectl get deployments --all-namespaces
下,所以我无法缩放pod或执行kubectl rollout restart
。
如何重新启动这些吊舱?
您可以尝试查看有关特定pod的更多信息,以便使用以下命令进行故障排除:kubectl describe pod
正如您已经注意到的,重新启动Pods可能不是解决问题的方法。更好的解决方案是尝试更好地了解到底出了什么问题,并专注于解决这个问题。为了做到这一点,你可以按照以下步骤(按顺序(:
- 通过执行
kubectl describe pods ${POD_NAME}
并检查失败原因来调试Pods。请注意,一旦调度了pod,调试运行pod中描述的方法就可以用于调试。这些方法是:
-
检查pod日志:使用
kubectl logs ${POD_NAME} ${CONTAINER_NAME}
或kubectl logs --previous ${POD_NAME} ${CONTAINER_NAME}
-
使用容器exec调试:通过使用
kubectl exec
在特定容器内运行命令 -
使用临时调试容器进行调试:当容器崩溃或容器映像不包括调试实用程序(如使用发行版映像(导致
kubectl exec
不足时,临时容器对于交互式故障排除非常有用。kubectl
有一个alpha命令,它可以创建用于从版本v1.18
开始调试的临时容器。 -
通过节点上的shell进行调试:如果这些方法都不起作用,您可以找到pod正在运行的主机,并通过SSH连接到该主机
这些步骤应该足以进入问题的核心,而不是专注于解决它。