這篇博文介紹的是安裝Dashboard V2.0.3
, 並將其映射到具體的域名上。先上一個成果圖,若是安裝過程當中有遇到什麼問題,能夠評論聯繫我html
本次安裝基於Helm
的chart
包安裝的,且向外暴露服務的方式爲Ingress,因此有如下前提:node
如未安裝helm,能夠參照:kubernetes系列(十六) - Helm安裝和入門nginx
DaemonSet
方式安裝好了Ingress-nginx
如未安裝,安裝教程能夠參照下篇文章的第四小節部分:kubernetes系列(十) - 經過Ingress實現七層代理git
由於使用的是ingress,因此必需要域名,且dashboard須要https才能外網訪問,證書能夠在阿里雲之類的購買一年期的免費贈書github
# 具體上傳過程不贅述 # 這裏假設證書aaa.key和bbb.crt已經上傳至路徑/usr/local/cert cd /usr/local/cert # 建立secret到kube-system命名空間下 # 以後咱們的dashboard也會建立在這個命名空間下,須要依賴這個,因此提早建立 kubectl creat secret tls dashboard-tls --key aaa.key --cert bbb.crt -n kube-system
# 添加helmhub上的dashboard官方repo倉庫 helm repo add kubernetes-dashboard https://kubernetes.github.io/dashboard/ # 查看添加完成後的倉庫 helm repo list # 查詢dashboard的chart helm search repo kubernetes-dashboard # 新建文件夾用於保存chart mkdir dashboard-chart && cd dashboard-chart # 拉取chart helm pull kubernetes-dashboard/kubernetes-dashboard # 此時會有一個壓縮包,解壓它 tar -zxvf kubernetes-dashboard-2.3.0.tgz # 進入到解壓後的文件夾 cd kubernetes-dashboard
注意:如下建立的new-values.yaml
是基於values.yaml
修改的,即意味着若是須要跟自定義的配置,能夠本身參照values.yaml
修改配置文件shell
注意:如下的host須要換成本身的域名,且secretname須要跟剛剛建立的secret對應起來api
image: repository: kubernetesui/dashboard tag: v2.0.3 pullPolicy: IfNotPresent pullSecrets: [] replicaCount: 1 annotations: {} labels: {} extraEnv: [] podAnnotations: seccomp.security.alpha.kubernetes.io/pod: 'runtime/default' nodeSelector: {} tolerations: [] affinity: {} resources: requests: cpu: 100m memory: 200Mi limits: cpu: 2 memory: 200Mi protocolHttp: false service: type: ClusterIP externalPort: 443 annotations: {} labels: {} ingress: enabled: true annotations: nginx.ingress.kubernetes.io/secure-backends: "true" nginx.ingress.kubernetes.io/backend-protocol: "HTTPS" paths: - / customPaths: [] hosts: - xxx.xxx.com # 你的域名 tls: # 注意這個名字要跟前面新建的secret對上 - secretName: dashboard-tls hosts: - xxx.xxx.com # 你的域名 metricsScraper: enabled: false image: repository: kubernetesui/metrics-scraper tag: v1.0.4 resources: {} containerSecurityContext: allowPrivilegeEscalation: false readOnlyRootFilesystem: true runAsUser: 1001 runAsGroup: 2001 metrics-server: enabled: false rbac: create: true clusterRoleMetrics: true clusterReadOnlyRole: false serviceAccount: create: true name: livenessProbe: initialDelaySeconds: 30 timeoutSeconds: 30 podDisruptionBudget: enabled: false minAvailable: maxUnavailable: containerSecurityContext: allowPrivilegeEscalation: false readOnlyRootFilesystem: true runAsUser: 1001 runAsGroup: 2001 networkPolicy: enabled: false
# 執行路徑在new-values.yaml目錄 helm install -f new-values.yaml --namespace kube-system kubernetes-dashboard .
注意:雲服務商的域名解析處,須要將域名經過A記錄解析到某個node節點上服務器
而後訪問剛剛配置文件配置的域名應該可以訪問到以下界面app
這裏咱們須要查看tokenui
[root@k8s-master kubernetes-dashboard]# kubectl get secret -n kube-system | grep kubernetes-dashboard-token kubernetes-dashboard-token-vgp9w kubernetes.io/service-account-token 3 22h
kubectl describe secret kubernetes-dashboard-token-vgp9w -n kube-system
根據以下的登錄
登錄成功
此時咱們剛進去界面,發現什麼資源都顯示不了,是由於dashboard默認的serviceaccount
並無權限,因此咱們須要給予它受權。
https://github.com/kubernetes/dashboard/blob/master/docs/user/access-control/README.md
dashboard-admin.yaml
,內容爲如下apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: kubernetes-dashboard namespace: kube-system roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: cluster-admin subjects: - kind: ServiceAccount name: kubernetes-dashboard namespace: kube-system
dashboard-admin.yaml
kubectl apply -f dashboard-admin.yaml