kubernetes dashboard部署

Step#1 下载yaml文件

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

Step#2 修改image地址

kind: Deployment
apiVersion: apps/v1
metadata:
  labels:
    k8s-app: kubernetes-dashboard
  name: kubernetes-dashboard
  namespace: kube-system
spec:
  replicas: 1
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      k8s-app: kubernetes-dashboard
  template:
    metadata:
      labels:
        k8s-app: kubernetes-dashboard
    spec:
      containers:
      - name: kubernetes-dashboard
        image: k8s.gcr.io/kubernetes-dashboard-amd64:v1.10.1

把image中的k8s.gcr.io 改成 registry.cn-hangzhou.aliyuncs.com/google_containers

Step#3 添加主机映射端口

原内容:

kind: Service
apiVersion: v1
metadata:
  labels:
    k8s-app: kubernetes-dashboard
  name: kubernetes-dashboard
  namespace: kube-system
spec:
  ports:
    - port: 443
      targetPort: 8443
  selector:
    k8s-app: kubernetes-dashboard

改为:

kind: Service
apiVersion: v1
metadata:
  labels:
    k8s-app: kubernetes-dashboard
  name: kubernetes-dashboard
  namespace: kube-system
spec:
  type: NodePort
  ports:
    - port: 443
      targetPort: 8443
      nodePort: 30003
  selector:
    k8s-app: kubernetes-dashboard

Step#4 部署

kubectl apply -f kubernetes-dashboard.yaml

Step#5 创建登录令牌

# 创建dashboard管理用户
kubectl create serviceaccount dashboard-admin -n kube-system

# 绑定用户为集群管理用户
kubectl create clusterrolebinding dashboard-cluster-admin --clusterrole=cluster-admin --serviceaccount=kube-system:dashboard-admin

# 生成tocken
kubectl describe secret -n kube-system dashboard-admin-token
# --- 输出如下 ---
Name:         dashboard-admin-token-h8thm
Namespace:    kube-system
Labels:       <none>
Annotations:  kubernetes.io/service-account.name: dashboard-admin
              kubernetes.io/service-account.uid: 4aec6906-204a-4adb-b88b-9fdc05756029

Type:  kubernetes.io/service-account-token

Data
====
ca.crt:     1025 bytes
namespace:  11 bytes
token:      eyJhbGciOiJSUzI1NiIsImtpZCI6IiJ9.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJkYXNoYm9hcmQtYWRtaW4tdG9rZW4taDh0aG0iLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC5uYW1lIjoiZGFzaGJvYXJkLWFkbWluIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQudWlkIjoiNGFlYzY5MDYtMjA0YS00YWRiLWI4OGItOWZkYzA1NzU2MDI5Iiwic3ViIjoic3lzdGVtOnNlcnZpY2VhY2NvdW50Omt1YmUtc3lzdGVtOmRhc2hib2FyZC1hZG1pbiJ9.yvJUfwA3Xvf9rviYRWfojDH4gRIuDi5X6yTcvkExtor03eg7woxk7Dt73K9thCfOkKhiv1YdCs7irItIpJZ4vflEGY0RgTWhFLbYyGQMuib5MrGS8-XDeJ5Myklu41NbDxlc43N3Io0QYKpGcEI6hx1uOMFV7LwxXIaOAObenU_3peYUWv5nyfy2avj3Wen8rdoGTeuPkyRdd-Uxa2VD4jIamJvdfzQiZCVAE4gWWYriFtGSn5nPHSK1ZqTfezXiSHuEPsPNHhxjBEwtKs0zXnp8xdLScH1FshUCzuSiv2VP4OsWS0wquW31w7A-csQMR2ZJrwhE2TvMEwgeBtQhVg