k8s安装dashboard时pod出现CarshLoopBackoff

k8s安装dashboard时pod出现CarshLoopBackoff

输入kubectl get pods -A查看所有pod的运行状态

[root@k8s-master ~]# kubectl get pod -A
NAMESPACE              NAME                                         READY   STATUS             RESTARTS   AGE
kube-system            calico-kube-controllers-547686d897-krxh7     1/1     Running            4          22h
kube-system            calico-node-c6xpt                            1/1     Running            4          22h
kube-system            calico-node-qpk78                            1/1     Running            3          22h
kube-system            calico-node-xr9zz                            1/1     Running            4          22h
kube-system            coredns-5897cd56c4-4hz2x                     1/1     Running            4          23h
kube-system            coredns-5897cd56c4-xjnbk                     1/1     Running            4          23h
kube-system            etcd-k8s-master                              1/1     Running            5          23h
kube-system            kube-apiserver-k8s-master                    1/1     Running            5          23h
kube-system            kube-controller-manager-k8s-master           1/1     Running            6          23h
kube-system            kube-proxy-7qdtq                             1/1     Running            3          22h
kube-system            kube-proxy-xx68j                             1/1     Running            4          22h
kube-system            kube-proxy-zvr4b                             1/1     Running            4          23h
kube-system            kube-scheduler-k8s-master                    1/1     Running            7          23h
kubernetes-dashboard   dashboard-metrics-scraper-79c5968bdc-bxjbd   1/1     Running            1          16h
kubernetes-dashboard   kubernetes-dashboard-658485d5c7-4c2sg        0/1     CrashLoopBackOff   8          16h

可以看到dashboard未运行成功

通过 kubectl logs kubernetes-dashboard-658485d5c7-4c2sg -n kubernetes-dashboard查看pod运行失败的日志, kubernetes-dashboard-658485d5c7-4c2sg为pod的name,kubernetes-dashboard是pod所在的命名空间

[root@k8s-master ~]# kubectl logs kubernetes-dashboard-658485d5c7-4c2sg -n kubernetes-dashboard
2022/02/23 00:58:28 Starting overwatch
2022/02/23 00:58:28 Using namespace: kubernetes-dashboard
2022/02/23 00:58:28 Using in-cluster config to connect to apiserver
2022/02/23 00:58:28 Using secret token for csrf signing
2022/02/23 00:58:28 Initializing csrf token from kubernetes-dashboard-csrf secret
panic: Get "https://10.96.0.1:443/api/v1/namespaces/kubernetes-dashboard/secrets/kubernetes-dashboard-csrf": dial tcp 10.96.0.1:443: i/o timeout

goroutine 1 [running]:
github.com/kubernetes/dashboard/src/app/backend/client/csrf.(*csrfTokenManager).init(0xc00017bba0)
	/home/runner/work/dashboard/dashboard/src/app/backend/client/csrf/manager.go:41 +0x413
github.com/kubernetes/dashboard/src/app/backend/client/csrf.NewCsrfTokenManager(...)
	/home/runner/work/dashboard/dashboard/src/app/backend/client/csrf/manager.go:66
github.com/kubernetes/dashboard/src/app/backend/client.(*clientManager).initCSRFKey(0xc00007e980)
	/home/runner/work/dashboard/dashboard/src/app/backend/client/manager.go:502 +0xc6
github.com/kubernetes/dashboard/src/app/backend/client.(*clientManager).init(0xc00007e980)
	/home/runner/work/dashboard/dashboard/src/app/backend/client/manager.go:470 +0x47
github.com/kubernetes/dashboard/src/app/backend/client.NewClientManager(...)
	/home/runner/work/dashboard/dashboard/src/app/backend/client/manager.go:551
main.main()
	/home/runner/work/dashboard/dashboard/src/app/backend/dashboard.go:95 +0x21c

可以看到报错原因为:Initializing csrf token from kubernetes-dashboard-csrf secret panic: Get https://10.96.0.1:443/api/v1/namespaces/kubernetes-dashboard/secrets/kubernetes-dashboard-csrf: dial tcp 10.96.0.1:443: i/o timeout

解决方法:
将dashboard安装到master节点,修改kubernetes-dashboard.yaml中的配置。
修改以下三处配置:
1、在以下截图处增加nodeName: k8s-master(这个为自己master节点的名字)
k8s安装dashboard时pod出现CarshLoopBackoff_第1张图片
k8s安装dashboard时pod出现CarshLoopBackoff_第2张图片
配置nodePord,并指定 Service 通过 Cluster 节点的静态端口对外提供服务。Cluster 外部可以通过 : 访问 Service。
k8s安装dashboard时pod出现CarshLoopBackoff_第3张图片
最后通过kubectl apply -f kubernetes-dashboard.yaml重新启用dashboard

第二种方式解决timeout

该方法主要解决NetworkManager 对 Calico 网卡的控制。
解决方法参考:
https://support.qacafe.com/knowledge-base/how-do-i-prevent-network-manager-from-controlling-an-interface/

你可能感兴趣的:(kubernetes,docker,centos)