[root@k8s-master dashboard]# pwd
/usr/local/src/kubernetes/cluster/addons/dashboard[root@k8s-master dashboard]# mkdir /usr/local/src/dashboard
[root@k8s-master dashboard]# cp dashboard-rbac.yaml dashboard-service.yaml dashboard-controller.yaml /usr/local/src/dashboard[root@k8s-master dashboard]# cd /usr/local/src/dashboard/[root@k8s-master dashboard]# lltotal 12-rw-r--r-- 1 root root 1821 May 30 01:01 dashboard-controller.yaml-rw-r--r-- 1 root root 1353 May 30 01:01 dashboard-rbac.yaml-rw-r--r-- 1 root root 322 May 30 01:01 dashboard-service.yaml
[root@k8s-master dashboard]# pwd/usr/local/src/dashboard[root@k8s-master dashboard]# lltotal 12-rw-r--r-- 1 root root 1147 May 30 02:09 dashboard-controller.yaml-rw-r--r-- 1 root root 606 May 30 01:54 dashboard-rbac.yaml-rw-r--r-- 1 root root 338 May 30 02:10 dashboard-service.yaml[root@k8s-master dashboard]# kubectl create -f dashboard-rbac.yaml [root@k8s-master dashboard]# kubectl create -f dashboard-controller.yaml deployment "kubernetes-dashboard" created[root@k8s-master dashboard]# kubectl create -f dashboard-service.yaml service "kubernetes-dashboard" created###查看[root@k8s-master ~]# kubectl get services kubernetes-dashboard -n kube-systemNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGEkubernetes-dashboard NodePort 10.10.10.19980:45439/TCP 2m[root@k8s-master dashboard]# kubectl get pods -n kube-system #####status not runningNAME READY STATUS RESTARTS AGEkubernetes-dashboard-765c8bfdff-ddwvw 0/1 ImagePullBackOff 0 22m[root@k8s-master dashboard]# kubectl describe pod kubernetes-dashboard-765c8bfdff-ddwvw -n kube-system ####查看原因发现里面的一个image地址写错了,解决办法如下:[root@k8s-master dashboard]# kubectl delete -f dashboard-controller.yaml deployment "kubernetes-dashboard" deleted[root@k8s-master dashboard]# kubectl create -f dashboard-controller.yaml deployment "kubernetes-dashboard" created[root@k8s-master dashboard]# kubectl get podsNAME READY STATUS RESTARTS AGEnginx-64f497f8fd-jnhgm 1/1 Running 0 20hnginx-64f497f8fd-n5pst 1/1 Running 0 20hnginx-64f497f8fd-rzldm 1/1 Running 0 20h[root@k8s-master dashboard]# kubectl get pods -n kube-systemNAME READY STATUS RESTARTS AGEkubernetes-dashboard-769c9999cb-wwxsn 1/1 Running 0 21s[root@k8s-master dashboard]# kubectl get all -n kube-systemNAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGEdeploy/kubernetes-dashboard 1 1 1 1 18mNAME DESIRED CURRENT READY AGErs/kubernetes-dashboard-769c9999cb 1 1 1 18mNAME READY STATUS RESTARTS AGEpo/kubernetes-dashboard-769c9999cb-wwxsn 1/1 Running 0 18mNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGEsvc/kubernetes-dashboard NodePort 10.10.10.199 80:45439/TCP 42m[root@k8s-master dashboard]# kubectl get svc -n kube-systemNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGEkubernetes-dashboard NodePort 10.10.10.199 80:45439/TCP 46m
[root@k8s-master dashboard]# cat dashboard-controller.yaml apiVersion: apps/v1beta2kind: Deploymentmetadata: name: kubernetes-dashboard namespace: kube-system labels: k8s-app: kubernetes-dashboard kubernetes.io/cluster-service: "true" addonmanager.kubernetes.io/mode: Reconcilespec: selector: matchLabels: k8s-app: kubernetes-dashboard template: metadata: labels: k8s-app: kubernetes-dashboard annotations: scheduler.alpha.kubernetes.io/critical-pod: '' spec: serviceAccountName: kubernetes-dashboard containers: - name: kubernetes-dashboard image: registry.cn-hangzhou.aliyuncs.com/google_containers/kubernetes-dashboard-amd64:v1.7.1 resources: limits: cpu: 100m memory: 300Mi requests: cpu: 100m memory: 100Mi ports: - containerPort: 9090 protocol: TCP livenessProbe: httpGet: scheme: HTTP path: / port: 9090 initialDelaySeconds: 30 timeoutSeconds: 30 tolerations: - key: "CriticalAddonsOnly" operator: "Exists"
[root@k8s-master dashboard]# cat dashboard-rbac.yaml apiVersion: v1kind: ServiceAccountmetadata: labels: k8s-app: kubernetes-dashboard addonmanager.kubernetes.io/mode: Reconcile name: kubernetes-dashboard namespace: kube-system---kind: ClusterRoleBindingapiVersion: rbac.authorization.k8s.io/v1beta1metadata: name: kubernetes-dashboard-minimal namespace: kube-system labels: k8s-app: kubernetes-dashboard addonmanager.kubernetes.io/mode: ReconcileroleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: cluster-adminsubjects:- kind: ServiceAccount name: kubernetes-dashboard namespace: kube-system
[root@k8s-master dashboard]# cat dashboard-service.yaml apiVersion: v1kind: Servicemetadata: name: kubernetes-dashboard namespace: kube-system labels: k8s-app: kubernetes-dashboard kubernetes.io/cluster-service: "true" addonmanager.kubernetes.io/mode: Reconcilespec: type: NodePort selector: k8s-app: kubernetes-dashboard ports: - port: 80 targetPort: 9090
#####可以在浏览器输入其中一个节点和端口访问