[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]# ll
total 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]# ll total 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-system NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes-dashboard NodePort 10.10.10.199 <none> 80:45439/TCP 2m [root@k8s-master dashboard]# kubectl get pods -n kube-system #####status not running NAME READY STATUS RESTARTS AGE kubernetes-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 pods NAME READY STATUS RESTARTS AGE nginx-64f497f8fd-jnhgm 1/1 Running 0 20h nginx-64f497f8fd-n5pst 1/1 Running 0 20h nginx-64f497f8fd-rzldm 1/1 Running 0 20h [root@k8s-master dashboard]# kubectl get pods -n kube-system NAME READY STATUS RESTARTS AGE kubernetes-dashboard-769c9999cb-wwxsn 1/1 Running 0 21s [root@k8s-master dashboard]# kubectl get all -n kube-system NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE deploy/kubernetes-dashboard 1 1 1 1 18m NAME DESIRED CURRENT READY AGE rs/kubernetes-dashboard-769c9999cb 1 1 1 18m NAME READY STATUS RESTARTS AGE po/kubernetes-dashboard-769c9999cb-wwxsn 1/1 Running 0 18m NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE svc/kubernetes-dashboard NodePort 10.10.10.199 <none> 80:45439/TCP 42m [root@k8s-master dashboard]# kubectl get svc -n kube-system NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes-dashboard NodePort 10.10.10.199 <none> 80:45439/TCP 46m
[root@k8s-master dashboard]# cat dashboard-controller.yaml apiVersion: apps/v1beta2 kind: Deployment metadata: name: kubernetes-dashboard namespace: kube-system labels: k8s-app: kubernetes-dashboard kubernetes.io/cluster-service: "true" addonmanager.kubernetes.io/mode: Reconcile spec: 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: v1 kind: ServiceAccount metadata: labels: k8s-app: kubernetes-dashboard addonmanager.kubernetes.io/mode: Reconcile name: kubernetes-dashboard namespace: kube-system --- kind: ClusterRoleBinding apiVersion: rbac.authorization.k8s.io/v1beta1 metadata: name: kubernetes-dashboard-minimal namespace: kube-system labels: k8s-app: kubernetes-dashboard addonmanager.kubernetes.io/mode: Reconcile roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: cluster-admin subjects: - kind: ServiceAccount name: kubernetes-dashboard namespace: kube-system
[root@k8s-master dashboard]# cat dashboard-service.yaml apiVersion: v1 kind: Service metadata: name: kubernetes-dashboard namespace: kube-system labels: k8s-app: kubernetes-dashboard kubernetes.io/cluster-service: "true" addonmanager.kubernetes.io/mode: Reconcile spec: type: NodePort selector: k8s-app: kubernetes-dashboard ports: - port: 80 targetPort: 9090
#####可以在浏览器输入其中一个节点和端口访问