安装版本信息
k8s v1.15.4

  1. # kubeadm version -o short
  2. v1.15.4

查看镜像信息
dashboard 是1.10.1

  1. # kubectl get pod kubernetes-dashboard-7dffbd5994-7zn2v -n kube-system -o yaml|grep image
  2. image: registry.cn-hangzhou.aliyuncs.com/google_containers/kubernetes-dashboard-amd64:v1.10.1
  3. imagePullPolicy: IfNotPresent
  4. image: registry.cn-hangzhou.aliyuncs.com/google_containers/kubernetes-dashboard-amd64:v1.10.1
  5. imageID: docker-pullable://registry.cn-hangzhou.aliyuncs.com/google_containers/kubernetes-dashboard-amd64@sha256:0ae6b69432e78069c5ce2bcde0fe409c5c4d6f0f4d9cd50a17974fea38898747

在Dashboard v1.10.1 和k8s 1.16.1无法使用
https://github.com/kubernetes/dashboard/issues/4401

查看当前pod

  1. # kubectl get pods --all-namespaces
  2. NAMESPACE NAME READY STATUS RESTARTS AGE
  3. kube-system coredns-bccdc95cf-smmxq 1/1 Running 0 7m5s
  4. kube-system coredns-bccdc95cf-wlr8b 1/1 Running 0 7m5s
  5. kube-system etcd-k8s-master01 1/1 Running 0 6m11s
  6. kube-system kube-apiserver-k8s-master01 1/1 Running 0 6m5s
  7. kube-system kube-controller-manager-k8s-master01 1/1 Running 0 6m15s
  8. kube-system kube-flannel-ds-amd64-rld8p 1/1 Running 0 5m50s
  9. kube-system kube-proxy-lpr6h 1/1 Running 0 7m5s
  10. kube-system kube-scheduler-k8s-master01 1/1 Running 0 5m57s

由于yaml配置文件中指定镜像从google拉取,先下载yaml文件到本地,修改配置从阿里云仓库拉取镜像。

  1. $wget https://raw.githubusercontent.com/kubernetes/dashboard/v1.10.1/src/deploy/recommended/kubernetes-dashboard.yaml

修改yaml配置文件image部分,指定镜像从阿里云镜像仓库拉取:

  1. [centos@k8s-master ~]$ vi kubernetes-dashboard.yaml
  2. ......
  3. containers:
  4. - name: kubernetes-dashboard
  5. #image: k8s.gcr.io/kubernetes-dashboard-amd64:v1.10.1
  6. image: registry.cn-hangzhou.aliyuncs.com/google_containers/kubernetes-dashboard-amd64:v1.10.1
  7. ports:
  8. ......

修改成NodePort的网络

  1. kind: Service
  2. apiVersion: v1
  3. metadata:
  4. labels:
  5. k8s-app: kubernetes-dashboard
  6. name: kubernetes-dashboard
  7. namespace: kube-system
  8. spec:
  9. # 添加Service的type为NodePort
  10. type: NodePort
  11. ports:
  12. - port: 443
  13. targetPort: 8443
  14. # 添加映射到虚拟机的端口,k8s只支持30000以上的端口
  15. nodePort: 32288
  16. selector:
  17. k8s-app: kubernetes-dashboard

最终文件

  1. # Copyright 2017 The Kubernetes Authors.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. # ------------------- Dashboard Secret ------------------- #
  15. apiVersion: v1
  16. kind: Secret
  17. metadata:
  18. labels:
  19. k8s-app: kubernetes-dashboard
  20. name: kubernetes-dashboard-certs
  21. namespace: kube-system
  22. type: Opaque
  23. ---
  24. # ------------------- Dashboard Service Account ------------------- #
  25. apiVersion: v1
  26. kind: ServiceAccount
  27. metadata:
  28. labels:
  29. k8s-app: kubernetes-dashboard
  30. name: kubernetes-dashboard
  31. namespace: kube-system
  32. ---
  33. # ------------------- Dashboard Role & Role Binding ------------------- #
  34. kind: Role
  35. apiVersion: rbac.authorization.k8s.io/v1
  36. metadata:
  37. name: kubernetes-dashboard-minimal
  38. namespace: kube-system
  39. rules:
  40. # Allow Dashboard to create 'kubernetes-dashboard-key-holder' secret.
  41. - apiGroups: [""]
  42. resources: ["secrets"]
  43. verbs: ["create"]
  44. # Allow Dashboard to create 'kubernetes-dashboard-settings' config map.
  45. - apiGroups: [""]
  46. resources: ["configmaps"]
  47. verbs: ["create"]
  48. # Allow Dashboard to get, update and delete Dashboard exclusive secrets.
  49. - apiGroups: [""]
  50. resources: ["secrets"]
  51. resourceNames: ["kubernetes-dashboard-key-holder", "kubernetes-dashboard-certs"]
  52. verbs: ["get", "update", "delete"]
  53. # Allow Dashboard to get and update 'kubernetes-dashboard-settings' config map.
  54. - apiGroups: [""]
  55. resources: ["configmaps"]
  56. resourceNames: ["kubernetes-dashboard-settings"]
  57. verbs: ["get", "update"]
  58. # Allow Dashboard to get metrics from heapster.
  59. - apiGroups: [""]
  60. resources: ["services"]
  61. resourceNames: ["heapster"]
  62. verbs: ["proxy"]
  63. - apiGroups: [""]
  64. resources: ["services/proxy"]
  65. resourceNames: ["heapster", "http:heapster:", "https:heapster:"]
  66. verbs: ["get"]
  67. ---
  68. apiVersion: rbac.authorization.k8s.io/v1
  69. kind: RoleBinding
  70. metadata:
  71. name: kubernetes-dashboard-minimal
  72. namespace: kube-system
  73. roleRef:
  74. apiGroup: rbac.authorization.k8s.io
  75. kind: Role
  76. name: kubernetes-dashboard-minimal
  77. subjects:
  78. - kind: ServiceAccount
  79. name: kubernetes-dashboard
  80. namespace: kube-system
  81. ---
  82. # ------------------- Dashboard Deployment ------------------- #
  83. kind: Deployment
  84. apiVersion: apps/v1
  85. metadata:
  86. labels:
  87. k8s-app: kubernetes-dashboard
  88. name: kubernetes-dashboard
  89. namespace: kube-system
  90. spec:
  91. replicas: 1
  92. revisionHistoryLimit: 10
  93. selector:
  94. matchLabels:
  95. k8s-app: kubernetes-dashboard
  96. template:
  97. metadata:
  98. labels:
  99. k8s-app: kubernetes-dashboard
  100. spec:
  101. nodeName: k8s-master01
  102. containers:
  103. - name: kubernetes-dashboard
  104. image: registry.cn-hangzhou.aliyuncs.com/google_containers/kubernetes-dashboard-amd64:v1.10.1
  105. ports:
  106. - containerPort: 8443
  107. protocol: TCP
  108. args:
  109. - --auto-generate-certificates
  110. # Uncomment the following line to manually specify Kubernetes API server Host
  111. # If not specified, Dashboard will attempt to auto discover the API server and connect
  112. # to it. Uncomment only if the default does not work.
  113. # - --apiserver-host=http://my-address:port
  114. volumeMounts:
  115. - name: kubernetes-dashboard-certs
  116. mountPath: /certs
  117. # Create on-disk volume to store exec logs
  118. - mountPath: /tmp
  119. name: tmp-volume
  120. livenessProbe:
  121. httpGet:
  122. scheme: HTTPS
  123. path: /
  124. port: 8443
  125. initialDelaySeconds: 30
  126. timeoutSeconds: 30
  127. volumes:
  128. - name: kubernetes-dashboard-certs
  129. secret:
  130. secretName: kubernetes-dashboard-certs
  131. - name: tmp-volume
  132. emptyDir: {}
  133. serviceAccountName: kubernetes-dashboard
  134. # Comment the following tolerations if Dashboard must not be deployed on master
  135. #tolerations:
  136. #- key: node-role.kubernetes.io/master
  137. # effect: NoSchedule
  138. ---
  139. # ------------------- Dashboard Service ------------------- #
  140. kind: Service
  141. apiVersion: v1
  142. metadata:
  143. labels:
  144. k8s-app: kubernetes-dashboard
  145. name: kubernetes-dashboard
  146. namespace: kube-system
  147. spec:
  148. type: NodePort
  149. ports:
  150. - port: 443
  151. targetPort: 8443
  152. nodePort: 32288
  153. selector:
  154. k8s-app: kubernetes-dashboard

然后执行以下命令部署dashboard服务:

  1. ]# kubectl apply -f kubernetes-dashboard.yaml
  2. secret/kubernetes-dashboard-certs created
  3. serviceaccount/kubernetes-dashboard created
  4. role.rbac.authorization.k8s.io/kubernetes-dashboard-minimal created
  5. rolebinding.rbac.authorization.k8s.io/kubernetes-dashboard-minimal created
  6. deployment.apps/kubernetes-dashboard created
  7. service/kubernetes-dashboard created

查看kubernetes-dashboar 是否运行成功

  1. # kubectl get pods -n kube-system
  2. NAME READY STATUS RESTARTS AGE
  3. coredns-bccdc95cf-smmxq 1/1 Running 0 9m15s
  4. coredns-bccdc95cf-wlr8b 1/1 Running 0 9m15s
  5. etcd-k8s-master01 1/1 Running 0 8m21s
  6. kube-apiserver-k8s-master01 1/1 Running 0 8m15s
  7. kube-controller-manager-k8s-master01 1/1 Running 0 8m25s
  8. kube-flannel-ds-amd64-rld8p 1/1 Running 0 8m
  9. kube-proxy-lpr6h 1/1 Running 0 9m15s
  10. kube-scheduler-k8s-master01 1/1 Running 0 8m7s
  11. kubernetes-dashboard-7dffbd5994-7zn2v 1/1 Running 0 30

使用token 创建登录用户权限文件
https://github.com/kubernetes/dashboard/blob/master/docs/user/access-control/creating-sample-user.md

  1. apiVersion: rbac.authorization.k8s.io/v1
  2. kind: ClusterRoleBinding
  3. metadata:
  4. name: admin-user
  5. roleRef:
  6. apiGroup: rbac.authorization.k8s.io
  7. kind: ClusterRole
  8. name: cluster-admin
  9. subjects:
  10. - kind: ServiceAccount
  11. name: admin-user
  12. namespace: kube-system
  13. ---
  14. apiVersion: v1
  15. kind: ServiceAccount
  16. metadata:
  17. name: admin-user
  18. namespace: kube-system

运行

  1. # kubectl apply -f dashboard-adminuser.yaml
  2. clusterrolebinding.rbac.authorization.k8s.io/admin-user configured
  3. serviceaccount/admin-user created

获取token

  1. kubectl describe secret $(kubectl get secret -nkube-system |grep admin|awk '{print $1}') -nkube-system
  1. # kubectl describe secret/$(kubectl get secret -nkube-system |grep admin|awk '{print $1}') -nkube-system
  2. Name: admin-token-5fhzc
  3. Namespace: kube-system
  4. Labels: <none>
  5. Annotations: kubernetes.io/service-account.name: admin
  6. kubernetes.io/service-account.uid: d8ea8268-4f2c-4134-85ea-4b8e1527e9e6
  7. Type: kubernetes.io/service-account-token
  8. Data
  9. ====
  10. ca.crt: 1025 bytes
  11. namespace: 11 bytes
  12. token: eyJhbGciOiJSUzI1NiIsImtpZCI6IiJ9.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJhZG1pbi10b2tlbi01Zmh6YyIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50Lm5hbWUiOiJhZG1pbiIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50LnVpZCI6ImQ4ZWE4MjY4LTRmMmMtNDEzNC04NWVhLTRiOGUxNTI3ZTllNiIsInN1YiI6InN5c3RlbTpzZXJ2aWNlYWNjb3VudDprdWJlLXN5c3RlbTphZG1pbiJ9.A4_b3g3r9jaEGHmERA2ufizs_nRVKyi2WAeaz5iQdDDNwXb9-1shQevsx8KjvI5BAdeFPMLLqduS97PEYHkrWQB9SmNd6b0KHIfc8jswC7g6dHYpNx-2Q0QeGrll6oeP37LSdWqehQxA_7QDn7hiz86amsAi6hm6natvOyfZoHgjXo1RaJ0zs6VVrS_ftkywQi_NrdwKx2cvv1tVKEXge6cepQzyGc7zXNVWELxywjL34gsIwne3RbS3TNx2nPIRNeJm8FAjhvaU9LBLCrYYCEWZZzugTIV3j0TGh4U7aThonFPGBjvbhVll_-YpC0GkanVZOSj0h1iUFM_AtmRgk

主要是https 例如我本地的地址是https://172.17.245.18:32288/#!/login
图片.png
选择:高级——接收风险并继续

图片.png

参考文章

https://blog.csdn.net/networken/article/details/85607593