使用kubectl重启头盔舱

时间:2020-10-30 15:43:25

标签: kubectl

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是否会使它们直立,但我不知道该怎么做。头盔未显示在kubectl get deployments --all-namespaces下,因此我无法缩放吊舱或进行kubectl rollout restart

如何重启这些吊舱?

2 个答案:

答案 0 :(得分:1)

您可以尝试使用以下命令查看有关特定吊舱的更多信息,以进行故障排除:kubectl describe pod

答案 1 :(得分:1)

您已经注意到,重启Pod可能不是解决问题的方法。更好的解决方案是尝试集中精力解决问题,以弄清到底出了什么问题。为此,您可以按照以下顺序执行以下步骤:

  1. Debugging Pods,方法是执行kubectl describe pods ${POD_NAME}并检查其失败的原因。请注意,安排好您的Pod后,Debug Running Pods中描述的方法可用于调试。这些方法是:
  • Examining pod logs:带有kubectl logs ${POD_NAME} ${CONTAINER_NAME}kubectl logs --previous ${POD_NAME} ${CONTAINER_NAME}

  • Debugging with container exec:通过使用kubectl exec

    在特定容器内运行命令
  • Debugging with an ephemeral debug container:当kubectl exec不足时(因为容器崩溃或容器映像不包含调试实用程序,例如{{3}),临时容器可用于交互式故障排除}。 kubectl有一个alpha命令,该命令可以创建临时容器以从版本v1.18开始进行调试。

  • distroless images:如果以上方法均无效,则可以找到运行Pod的主机并通过SSH进入该主机

这些步骤应该足以解决问题的核心,而不是专注于解决问题。