目的

部署k8s dashboard

链接地址

https://github.com/kubernetes/dashboard

说明

本文主要阐述如何安装部署dashboard!

部署influxdb

文件名为:influxdb.yaml

  1. apiVersion: extensions/v1beta1
  2. kind: Deployment
  3. metadata:
  4. name: monitoring-influxdb
  5. namespace: kube-system
  6. spec:
  7. replicas: 1
  8. template:
  9. metadata:
  10. labels:
  11. task: monitoring
  12. k8s-app: influxdb
  13. spec:
  14. containers:
  15. - name: influxdb
  16. image: hub.k8s.com/apps/influxdb:latest
  17. volumeMounts:
  18. - mountPath: /data
  19. name: influxdb-storage
  20. volumes:
  21. - name: influxdb-storage
  22. emptyDir: {}
  23. ---
  24. apiVersion: v1
  25. kind: Service
  26. metadata:
  27. labels:
  28. task: monitoring
  29. # For use as a Cluster add-on (https://github.com/kubernetes/kubernetes/tree/master/cluster/addons)
  30. # If you are NOT using this as an addon, you should comment out this line.
  31. kubernetes.io/cluster-service: 'true'
  32. kubernetes.io/name: monitoring-influxdb
  33. name: monitoring-influxdb
  34. namespace: kube-system
  35. spec:
  36. ports:
  37. - port: 8086
  38. targetPort: 8086
  39. selector:
  40. k8s-app: influxdb

部署heapster

  1. apiVersion: v1
  2. kind: ServiceAccount
  3. metadata:
  4. name: heapster
  5. namespace: kube-system
  6. ---
  7. kind: ClusterRoleBinding
  8. apiVersion: rbac.authorization.k8s.io/v1beta1
  9. metadata:
  10. name: heapster
  11. roleRef:
  12. apiGroup: rbac.authorization.k8s.io
  13. kind: ClusterRole
  14. name: system:heapster
  15. subjects:
  16. - kind: ServiceAccount
  17. name: heapster
  18. namespace: kube-system
  19. ---
  20. apiVersion: extensions/v1beta1
  21. kind: Deployment
  22. metadata:
  23. name: heapster
  24. namespace: kube-system
  25. spec:
  26. replicas: 1
  27. template:
  28. metadata:
  29. labels:
  30. task: monitoring
  31. k8s-app: heapster
  32. spec:
  33. serviceAccountName: heapster
  34. dnsPolicy: ClusterFirst
  35. containers:
  36. - name: heapster
  37. image: hub.k8s.com/google-containers/heapster:v1.4.3
  38. imagePullPolicy: IfNotPresent
  39. command:
  40. - /heapster
  41. - --source=kubernetes:https://10.10.10.21
  42. - --sink=influxdb:http://monitoring-influxdb.kube-system.svc.cluster.local:8086
  43. ---
  44. apiVersion: v1
  45. kind: Service
  46. metadata:
  47. labels:
  48. task: monitoring
  49. # For use as a Cluster add-on (https://github.com/kubernetes/kubernetes/tree/master/cluster/addons)
  50. # If you are NOT using this as an addon, you should comment out this line.
  51. kubernetes.io/cluster-service: 'true'
  52. kubernetes.io/name: Heapster
  53. name: heapster
  54. namespace: kube-system
  55. spec:
  56. ports:
  57. - port: 80
  58. targetPort: 8082
  59. selector:
  60. k8s-app: heapster

部署grafana (可选)

  1. apiVersion: extensions/v1beta1
  2. kind: Deployment
  3. metadata:
  4. name: monitoring-grafana
  5. namespace: kube-system
  6. spec:
  7. replicas: 1
  8. template:
  9. metadata:
  10. labels:
  11. task: monitoring
  12. k8s-app: grafana
  13. spec:
  14. containers:
  15. - name: grafana
  16. image: hub.k8s.com/apps/heapster-grafana-amd64:v4.4.3
  17. ports:
  18. - containerPort: 3000
  19. protocol: TCP
  20. volumeMounts:
  21. - mountPath: /etc/ssl/certs
  22. name: ca-certificates
  23. readOnly: true
  24. - mountPath: /var
  25. name: grafana-storage
  26. env:
  27. - name: INFLUXDB_HOST
  28. value: monitoring-influxdb
  29. - name: GF_SERVER_HTTP_PORT
  30. value: "3000"
  31. # The following env variables are required to make Grafana accessible via
  32. # the kubernetes api-server proxy. On production clusters, we recommend
  33. # removing these env variables, setup auth for grafana, and expose the grafana
  34. # service using a LoadBalancer or a public IP.
  35. - name: GF_AUTH_BASIC_ENABLED
  36. value: "false"
  37. - name: GF_AUTH_ANONYMOUS_ENABLED
  38. value: "true"
  39. - name: GF_AUTH_ANONYMOUS_ORG_ROLE
  40. value: Admin
  41. - name: GF_SERVER_ROOT_URL
  42. # If you're only using the API Server proxy, set this value instead:
  43. # value: /api/v1/namespaces/kube-system/services/monitoring-grafana/proxy
  44. value: /
  45. volumes:
  46. - name: ca-certificates
  47. hostPath:
  48. path: /etc/ssl/certs
  49. - name: grafana-storage
  50. emptyDir: {}
  51. ---
  52. apiVersion: v1
  53. kind: Service
  54. metadata:
  55. labels:
  56. # For use as a Cluster add-on (https://github.com/kubernetes/kubernetes/tree/master/cluster/addons)
  57. # If you are NOT using this as an addon, you should comment out this line.
  58. kubernetes.io/cluster-service: 'true'
  59. kubernetes.io/name: monitoring-grafana
  60. name: monitoring-grafana
  61. namespace: kube-system
  62. spec:
  63. # In a production setup, we recommend accessing Grafana through an external Loadbalancer
  64. # or through a public IP.
  65. # type: LoadBalancer
  66. # You could also use NodePort to expose the service at a randomly-generated port
  67. # type: NodePort
  68. ports:
  69. - port: 80
  70. targetPort: 3000
  71. selector:
  72. k8s-app: grafana

部署dashboard

注意

要直接访问dashboard(无kubectl proxy),应使用有效证书建立安全的HTTPS连接。我们使用自有的证书颁发机构生成dashboard证书。使用它们替换仪表板中的自动生成的证书。

生成保密字典

你有dashboard.crt和dashboard.key存储在./certs目录下的文件,你可以使用如下命令创建名称为“kubernetes-dashboard-certs”的保密字典

  1. shell># kubectl create secret generic kubernetes-dashboard-certs --from-file=$HOME/certs -n kube-system

验证

  1. shell># kubectl get secrets kubernetes-dashboard-certs -n kube-system
  2. NAME TYPE DATA AGE
  3. kubernetes-dashboard-certs Opaque 2 0d
  4. shell># kubectl describe secrets kubernetes-dashboard-certs -n kube-system
  5. Name: kubernetes-dashboard-certs
  6. Namespace: kube-system
  7. Labels: <none>
  8. Annotations: <none>
  9. Type: Opaque
  10. Data
  11. ====
  12. dashboard.crt: 1399 bytes
  13. dashboard.key: 1675 bytes

部署dashboard

创建Kubernetes-dashboard.yaml

  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. # Configuration to deploy release version of the Dashboard UI compatible with
  15. # Kubernetes 1.8.
  16. #
  17. # Example usage: kubectl create -f <this_file>
  18. # ------------------- Dashboard Secret ------------------- #
  19. #apiVersion: v1
  20. #kind: Secret
  21. #metadata:
  22. # labels:
  23. # k8s-app: kubernetes-dashboard
  24. # name: kubernetes-dashboard-certs
  25. # namespace: kube-system
  26. #type: Opaque
  27. ---
  28. # ------------------- Dashboard Service Account ------------------- #
  29. apiVersion: v1
  30. kind: ServiceAccount
  31. metadata:
  32. labels:
  33. k8s-app: kubernetes-dashboard
  34. name: kubernetes-dashboard
  35. namespace: kube-system
  36. ---
  37. # ------------------- Dashboard Role & Role Binding ------------------- #
  38. kind: Role
  39. apiVersion: rbac.authorization.k8s.io/v1
  40. metadata:
  41. name: kubernetes-dashboard-minimal
  42. namespace: kube-system
  43. rules:
  44. # Allow Dashboard to create 'kubernetes-dashboard-key-holder' secret.
  45. - apiGroups: [""]
  46. resources: ["secrets"]
  47. verbs: ["create"]
  48. # Allow Dashboard to create 'kubernetes-dashboard-settings' config map.
  49. - apiGroups: [""]
  50. resources: ["configmaps"]
  51. verbs: ["create"]
  52. # Allow Dashboard to get, update and delete Dashboard exclusive secrets.
  53. - apiGroups: [""]
  54. resources: ["secrets"]
  55. resourceNames: ["kubernetes-dashboard-key-holder", "kubernetes-dashboard-certs"]
  56. verbs: ["get", "update", "delete"]
  57. # Allow Dashboard to get and update 'kubernetes-dashboard-settings' config map.
  58. - apiGroups: [""]
  59. resources: ["configmaps"]
  60. resourceNames: ["kubernetes-dashboard-settings"]
  61. verbs: ["get", "update"]
  62. # Allow Dashboard to get metrics from heapster.
  63. - apiGroups: [""]
  64. resources: ["services"]
  65. resourceNames: ["heapster"]
  66. verbs: ["proxy"]
  67. - apiGroups: [""]
  68. resources: ["services/proxy"]
  69. resourceNames: ["heapster", "http:heapster:", "https:heapster:"]
  70. verbs: ["get"]
  71. ---
  72. apiVersion: rbac.authorization.k8s.io/v1
  73. kind: RoleBinding
  74. metadata:
  75. name: kubernetes-dashboard-minimal
  76. namespace: kube-system
  77. roleRef:
  78. apiGroup: rbac.authorization.k8s.io
  79. kind: Role
  80. name: kubernetes-dashboard-minimal
  81. subjects:
  82. - kind: ServiceAccount
  83. name: kubernetes-dashboard
  84. namespace: kube-system
  85. ---
  86. # ------------------- Dashboard Deployment ------------------- #
  87. kind: Deployment
  88. apiVersion: apps/v1beta2
  89. metadata:
  90. labels:
  91. k8s-app: kubernetes-dashboard
  92. name: kubernetes-dashboard
  93. namespace: kube-system
  94. spec:
  95. replicas: 1
  96. revisionHistoryLimit: 10
  97. selector:
  98. matchLabels:
  99. k8s-app: kubernetes-dashboard
  100. template:
  101. metadata:
  102. labels:
  103. k8s-app: kubernetes-dashboard
  104. spec:
  105. containers:
  106. - name: kubernetes-dashboard
  107. image: hub.k8s.com/google-containers/kubernetes-dashboard:v1.8.1
  108. ports:
  109. - containerPort: 8443
  110. protocol: TCP
  111. args:
  112. - --auto-generate-certificates
  113. # Uncomment the following line to manually specify Kubernetes API server Host
  114. # If not specified, Dashboard will attempt to auto discover the API server and connect
  115. # to it. Uncomment only if the default does not work.
  116. - --apiserver-host=http://10.10.1.21:8080
  117. - --authentication-mode=kubeconfig
  118. volumeMounts:
  119. - name: kubernetes-dashboard-certs
  120. mountPath: /certs
  121. # Create on-disk volume to store exec logs
  122. - mountPath: /tmp
  123. name: tmp-volume
  124. livenessProbe:
  125. httpGet:
  126. scheme: HTTPS
  127. path: /
  128. port: 8443
  129. initialDelaySeconds: 30
  130. timeoutSeconds: 30
  131. volumes:
  132. - name: kubernetes-dashboard-certs
  133. secret:
  134. secretName: kubernetes-dashboard-certs
  135. - name: tmp-volume
  136. emptyDir: {}
  137. serviceAccountName: kubernetes-dashboard
  138. # Comment the following tolerations if Dashboard must not be deployed on master
  139. tolerations:
  140. - key: node-role.kubernetes.io/master
  141. effect: NoSchedule
  142. ---
  143. # ------------------- Dashboard Service ------------------- #
  144. kind: Service
  145. apiVersion: v1
  146. metadata:
  147. labels:
  148. k8s-app: kubernetes-dashboard
  149. name: kubernetes-dashboard
  150. namespace: kube-system
  151. spec:
  152. type: NodePort
  153. ports:
  154. - port: 443
  155. targetPort: 8443
  156. nodePort: 30001
  157. selector:
  158. k8s-app: kubernetes-dashboard

验证

访问http://master.k8s.com:8080/ui