1.部署dashboard
mkdir -p /home/yaml/dashboard && cd /home/yaml/dashboard
wget https://raw.githubusercontent.com/kubernetes/dashboard/v2.2.0/aio/deploy/recommended.yaml
vi recommended.yaml
...
kind: Service
apiVersion: v1
metadata:
labels:
k8s-app: kubernetes-dashboard
name: kubernetes-dashboard
namespace: kubernetes-dashboard
spec:
ports:
- port: 443
targetPort: 8443
nodePort: 30001
type: NodePort
selector:
k8s-app: kubernetes-dashboard
kubectl apply -f recommended.yaml
2.chrome 可以访问
vi recommended.yaml
...
args:
- --auto-generate-certificates
- --tls-key-file=server-key.pem
- --tls-cert-file=server.pem
...
kubectl delete secret kubernetes-dashboard-certs -n kubernetes-dashboard
kubectl get secrets -n kubernetes-dashboard
NAME TYPE DATA AGE
default-token-krq7c kubernetes.io/service-account-token 3 17m
kubernetes-dashboard-certs Opaque 0 16m
kubernetes-dashboard-csrf Opaque 1 17m
kubernetes-dashboard-key-holder Opaque 2 17m
kubernetes-dashboard-token-sbgrp kubernetes.io/service-account-token 3 17m
kubectl create secret generic kubernetes-dashboard-certs \
--from-file=/opt/kubernetes/ssl/server-key.pem --from-file=/opt/kubernetes/ssl/server.pem -n kubernetes-dashboard
kubectl get secrets -n kubernetes-dashboard
NAME TYPE DATA AGE
default-token-krq7c kubernetes.io/service-account-token 3 17m
kubernetes-dashboard-certs Opaque 2 16m
kubernetes-dashboard-csrf Opaque 1 17m
kubernetes-dashboard-key-holder Opaque 2 17m
kubernetes-dashboard-token-sbgrp kubernetes.io/service-account-token 3 17m
kubectl get pod -n kubernetes-dashboard
NAME READY STATUS RESTARTS AGE
dashboard-metrics-scraper-694557449d-9tcnh 1/1 Running 0 69s
kubernetes-dashboard-9774cc786-xj7wl 1/1 Running 0 29s
kubectl delete po kubernetes-dashboard-9774cc786-xj7wl -n kubernetes-dashboard
3.创建管理角色
kubectl create serviceaccount dashboard-admin -n kube-system
kubectl create clusterrolebinding dashboard-admin --clusterrole=cluster-admin --serviceaccount=kube-system:dashboard-admin
kubectl describe secrets -n kube-system $(kubectl -n kube-system get secret | awk '/dashboard-admin/{print $1}')
4.安装监控插件 metrics-server
mkdir -p /home/yaml/metrics
cd /home/yaml/metrics
wget https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml
spec:
hostNetwork: true
containers:
- args:
- --cert-dir=/tmp
- --secure-port=4443
- --kubelet-insecure-tls
- --kubelet-preferred-address-types=InternalIP,ExternalIP,Hostname
- --kubelet-use-node-status-port
image: bitnami/metrics-server:0.4.4
imagePullPolicy: IfNotPresent
kubectl apply -f components.yaml
kubectl get pod -n kube-system | grep metrics-server
metrics-server-6d59d8cdd6-hmjw7 1/1 Running 0 21m
5.dashboard 500错误
如果dashboard 显示 500 的错误,
日志提示有 http: TLS handshake error from 10.244.159.128:35885: remote error: tls: unknown certificate
在master 节点上执行
kubectl proxy
Starting to serve on 127.0.0.1:8001
再次访问就没有问题了