直接按以下部署会出来几个问题
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v1.10.1/src/deploy/recommended/kubernetes-dashboard.yaml
第一个问题是pod报以下错误,导致 CrashLoopBackOff
2019/10/12 08:37:25 Starting overwatch
2019/10/12 08:37:25 Using in-cluster config to connect to apiserver
2019/10/12 08:37:25 Using service account token for csrf signing
2019/10/12 08:37:26 Error while initializing connection to Kubernetes apiserver. This most likely means that the cluster is misconfigured (e.g., it has invalid apiserver certificates or service account's configuration) or the --apiserver-host param points to a server that does not exist. Reason: Get https://10.96.0.1:443/version: dial tcp 10.96.0.1:443: connect: no route to host
Refer to our FAQ and wiki pages for more information: https://github.com/kubernetes/dashboard/wiki/FAQ
要解决这个错误就要把Dashboard部署到Master节点,
将kubernetes-dashboard.yaml下载下来,注释掉下面的行
# Comment the following tolerations if Dashboard must not be deployed on master
# tolerations:
- key: node-role.kubernetes.io/master
effect: NoSchedule
然后添加nodeName(你的Master节点)
spec:
nodeName: k8s-master
containers:
- name: kubernetes-dashboard
image: k8s.gcr.io/kubernetes-dashboard-amd64:v1.10.1
ports:
- containerPort: 8443
protocol: TCP
第二个问题是service使用没有使用nodePort,不能从外部访问,需要使用Proxy。
可以通过修改这个yaml里的service服务,添加tyep: nodePort解决
kind: Service
apiVersion: v1
metadata:
labels:
k8s-app: kubernetes-dashboard
name: kubernetes-dashboard
namespace: kube-system
spec:
type: NodePort
ports:
- port: 443
targetPort: 8443
selector:
k8s-app: kubernetes-dashboard
第三个,请使用Firefox来访问避免证书无效相关问题。
最后重新发布这个yaml即可,原因可能是apiserver证书权限相关,还没搞清楚,有空查明原因再来更新Blog。
通过以下获取随机的nodePort(或者在yaml里指定)
kubectl get svc --all-namespaces
获取Token
kubectl get secret -n kube-system | grep dashboard
kubectl describe secret kubernetes-dashboard-token-7t469 -n kube-system