0%

解决Google Chrome浏览器无法打开Kubernetes(K8S) Dashboard页面

环境

k8s version: v.1.16.3

dashboard: dashboard:v2.0.0-beta6

问题描述

K8S Dashboard安装好以后,通过Firefox浏览器是可以打开的,但通过Google Chrome浏览器,无法成功浏览页面。如图:

解决方案

kubeadm自动生成的证书,很多浏览器不支持。所以我们需要自己创建证书。

创建一个目录

存放证书等文件

1
2
mkdir key
cd key

生成证书

1
2
3
4
5
6
7
8
9
10
11
12
openssl genrsa -out dashboard.key 2048
Generating RSA private key, 2048 bit long modulus
.................+++
......+++
e is 65537 (0x10001)

# 172.16.64.229为master节点的IP地址
openssl req -new -out dashboard.csr -key dashboard.key -subj '/CN=172.16.64.229'
openssl x509 -req -in dashboard.csr -signkey dashboard.key -out dashboard.crt
Signature ok
subject=/CN=172.16.64.229
Getting Private key

删除原有证书

注意新版的Dashboard的namespace已经变为kubernetes-dashboard

1
2
kubectl delete secret kubernetes-dashboard-certs -n kubernetes-dashboard
secret "kubernetes-dashboard-certs" deleted

创建新证书的secret

1
2
kubectl create secret generic kubernetes-dashboard-certs --from-file=dashboard.key --from-file=dashboard.crt -n kubernetes-dashboard
secret/kubernetes-dashboard-certs created

查找正在运行的pod

1
2
3
4
kubectl get pod -n kubernetes-dashboard
NAME READY STATUS RESTARTS AGE
dashboard-metrics-scraper-76585494d8-dzgt9 1/1 Running 0 8m20s
kubernetes-dashboard-b65488c4-rcdjh 1/1 Running 0 8m20s

删除pod

1
2
3
4
kubectl delete po kubernetes-dashboard-b65488c4-rcdjh -n kubernetes-dashboard
pod "kubernetes-dashboard-b65488c4-rcdjh" deleted
kubectl delete po dashboard-metrics-scraper-76585494d8-dzgt9 -n kubernetes-dashboard
pod "dashboard-metrics-scraper-76585494d8-dzgt9" deleted

如果pod比较多的时候,可以使用以下这条命令批量删除。

1
kubectl get pod -n kubernetes-dashboard | grep -v NAME | awk '{print "kubectl delete po " $1 " -n kubernetes-dashboard"}' | sh

删除后,新的pod会自动启动起来。

这时,再次刷新Chrome浏览器的Dashboard页面,如图:

点击继续前往,页面就可以正常显示了。