Kubernetes1.13.1 dashboard安装
一.准备kubernetes-dashboard-amd64:v1.10.0
#拉取镜像
docker pull mirrorgooglecontainers/kubernetes-dashboard-amd64:v1.10.0
#重新打标签
docker tag mirrorgooglecontainers/kubernetes-dashboard-amd64:v1.10.0 k8s.gcr.io/kubernetes-dashboard-amd64:v1.10.0
#删除无用镜像
docker image rm mirrorgooglecontainers/kubernetes-dashboard-amd64:v1.10.0
二.获取kubernetes-dashboard.yaml
wget https://zxytest.zhixueyun.com/installler/kubernetes-dashboard.yaml
kubectl create -f kubernetes-dashboard.yaml
kubernetes-dashboard.yaml的内容如下
# Copyright 2017 The Kubernetes Authors. # # Licensed under the Apache License, Version 2.0 (the "License" ); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http: //www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # ------------------- Dashboard Secret ------------------- # apiVersion: v1 kind: Secret metadata: labels: k8s-app: kubernetes-dashboard name: kubernetes-dashboard-certs namespace: kube-system type: Opaque --- # ------------------- Dashboard Service Account ------------------- # apiVersion: v1 kind: ServiceAccount metadata: labels: k8s-app: kubernetes-dashboard name: kubernetes-dashboard namespace: kube-system --- # ------------------- Dashboard Role & Role Binding ------------------- # kind: Role apiVersion: rbac.authorization.k8s.io/v1 metadata: name: kubernetes-dashboard-minimal namespace: kube-system rules: # Allow Dashboard to create 'kubernetes-dashboard-key-holder' secret. - apiGroups: [ "" ] resources: [ "secrets" ] verbs: [ "create" ] # Allow Dashboard to create 'kubernetes-dashboard-settings' config map. - apiGroups: [ "" ] resources: [ "configmaps" ] verbs: [ "create" ] # Allow Dashboard to get, update and delete Dashboard exclusive secrets. - apiGroups: [ "" ] resources: [ "secrets" ] resourceNames: [ "kubernetes-dashboard-key-holder" , "kubernetes-dashboard-certs" ] verbs: [ "get" , "update" , "delete" ] # Allow Dashboard to get and update 'kubernetes-dashboard-settings' config map. - apiGroups: [ "" ] resources: [ "configmaps" ] resourceNames: [ "kubernetes-dashboard-settings" ] verbs: [ "get" , "update" ] # Allow Dashboard to get metrics from heapster. - apiGroups: [ "" ] resources: [ "services" ] resourceNames: [ "heapster" ] verbs: [ "proxy" ] - apiGroups: [ "" ] resources: [ "services/proxy" ] resourceNames: [ "heapster" , "http:heapster:" , "https:heapster:" ] verbs: [ "get" ] --- apiVersion: rbac.authorization.k8s.io/v1 kind: RoleBinding metadata: name: kubernetes-dashboard-minimal namespace: kube-system roleRef: apiGroup: rbac.authorization.k8s.io kind: Role name: kubernetes-dashboard-minimal subjects: - kind: ServiceAccount name: kubernetes-dashboard namespace: kube-system --- # ------------------- Dashboard Deployment ------------------- # kind: Deployment apiVersion: apps/v1beta2 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: mirrorgooglecontainers/kubernetes-dashboard-amd64:v1. 10.0 ports: - containerPort: 8443 protocol: TCP args: - --auto-generate-certificates # Uncomment the following line to manually specify Kubernetes API server Host # If not specified, Dashboard will attempt to auto discover the API server and connect # to it. Uncomment only if the default does not work. # - --apiserver-host=http: //my-address:port volumeMounts: - name: kubernetes-dashboard-certs mountPath: /certs # Create on-disk volume to store exec logs - mountPath: /tmp name: tmp-volume livenessProbe: httpGet: scheme: HTTPS path: / port: 8443 initialDelaySeconds: 30 timeoutSeconds: 30 volumes: - name: kubernetes-dashboard-certs secret: secretName: kubernetes-dashboard-certs - name: tmp-volume emptyDir: {} serviceAccountName: kubernetes-dashboard # Comment the following tolerations if Dashboard must not be deployed on master tolerations: - key: node-role.kubernetes.io/master effect: NoSchedule --- # ------------------- Dashboard Service ------------------- # kind: Service apiVersion: v1 metadata: labels: k8s-app: kubernetes-dashboard name: kubernetes-dashboard namespace: kube-system spec: type: NodePort ports: - port: 8443 nodePort: 32323 name: kubernetes-dashboard selector: k8s-app: kubernetes-dashboard |
查看dashboard的POD是否正常启动,如果正常说明安装成功
[root@iZbp1at8fph52evh70atb0Z ~]# kubectl get pods --namespace=kube-system
NAME READY STATUS RESTARTS AGE
kubernetes-dashboard-7b9c7bc8c9-d9jnt 1/1 Running 0 52m
查看kubernetes dashboard的nodeport
3.kubernetes dashboard有个bug,当容器名称太长之后,下载按钮被挤掉不显示,属于样式bug
当容器名称比较短的时候,下载日志按钮可以显示
四.生成dashboard.kubeconfig文件
1.执行以下命令生成kubeconfig文件,注意红色字体部分根据具体环境修改
kubectl create sa dashboard-admin -n kube-system
kubectl create clusterrolebinding dashboard-admin --clusterrole=cluster-admin --serviceaccount=kube-system:dashboard-admin
ADMIN_SECRET=$(kubectl get secrets -n kube-system | grep dashboard-admin | awk '{print $1}')
DASHBOARD_LOGIN_TOKEN=$(kubectl describe secret -n kube-system ${ADMIN_SECRET} | grep -E '^token' | awk '{print $2}')
echo ${DASHBOARD_LOGIN_TOKEN}
export KUBE_APISERVER=https://10.47.92.186:6443
kubectl config set-cluster kubernetes \
--certificate-authority=/etc/kubernetes/cert/ca.pem \
--embed-certs=true \
--server=${KUBE_APISERVER} \
--kubeconfig=dashboard.kubeconfig
# 设置客户端认证参数,使用上面创建的 Token
kubectl config set-credentials dashboard_user \
--token=${DASHBOARD_LOGIN_TOKEN} \
--kubeconfig=dashboard.kubeconfig
# 设置上下文参数
kubectl config set-context default \
--cluster=kubernetes \
--user=dashboard_user \
--kubeconfig=dashboard.kubeconfig
# 设置默认上下文
kubectl config use-context default --kubeconfig=dashboard.kubeconfig
2.登陆的时候不用输入一长串token,直接选择刚才生成的kubeconfig文件即可
五.上面那个token的权限太大了,为了生成查询权限的账号,执行以下步骤
1.rbac-zxy.yaml的内容如下
kind: ClusterRole apiVersion: rbac.authorization.k8s.io/v1 metadata: name: role-zxy rules: - apiGroups: [ "" ] resources: [ "*" ] verbs: [ "get" , "watch" , "list" ] - apiGroups: [ "storage.k8s.io" ] resources: [ "*" ] verbs: [ "get" , "watch" , "list" ] - apiGroups: [ "rbac.authorization.k8s.io" ] resources: [ "*" ] verbs: [ "get" , "watch" , "list" ] - apiGroups: [ "batch" ] resources: [ "*" ] verbs: [ "get" , "watch" , "list" ] - apiGroups: [ "apps" ] resources: [ "*" ] verbs: [ "get" , "watch" , "list" ] - apiGroups: [ "extensions" ] resources: [ "*" ] verbs: [ "get" , "watch" , "list" ] - apiGroups: [ "" ] resources: [ "pods/exec" ] verbs: [ "create" ] --- kind: ClusterRoleBinding apiVersion: rbac.authorization.k8s.io/v1 metadata: name: role-bind-zxy subjects: - kind: ServiceAccount name: zxy namespace: kube-system roleRef: kind: ClusterRole name: role-zxy apiGroup: rbac.authorization.k8s.io |
2.配置权限,只有"get","watch","list"等查询权限
kubectl create sa zxy -n kube-system
kubectl create -f rbac-zxy.yaml
kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep zxy | awk '{print $1}')
[root @iZbp13ke7onfhiq7ycl4m0Z ~]# kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep zxy | awk '{print $1}' ) Name: zxy-token-xwrqk Namespace: kube-system Labels: <none> Annotations: kubernetes.io/service-account.name: zxy kubernetes.io/service-account.uid: f44468f7-147d-11e9- 8505 -00163e0d735c Type: kubernetes.io/service-account-token Data ==== ca.crt: 1367 bytes namespace: 11 bytes token: eyJhbGciOiJSUzI1NiIsImtpZCI6IiJ9.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJ6eHktdG9rZW4teHdycWsiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC5uYW1lIjoienh5Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQudWlkIjoiZjQ0NDY4ZjctMTQ3ZC0xMWU5LTg1MDUtMDAxNjNlMGQ3MzVjIiwic3ViIjoic3lzdGVtOnNlcnZpY2VhY2NvdW50Omt1YmUtc3lzdGVtOnp4eSJ9.kaGX8mNOJ0snLk7Q4wcBeMo0AjrV1k91AHUvJ0PRDOukx5aT2FH5xbd4CdRL0O7VgMEmEc4J3-u7Jr03yQNkDWCb9rMWOXZFw5qIz7hl98JhEWB-ouIdJMPVsVKEFKjpayBaCdBUMlbPKh31QSeWS7dvZdxDAkUeF0OiNFeh91D7FlKe0DDxUMX-aOsoSRr1x6PJv9LEm7Fm5HWJyrSlTh6P4N6dxZhAf1wMxZGTFwr3XE0NOGS8to_p53qJOIIoGs5klxZ-CaU38NVmsNA02BedXELU3_1PySt9eKVwGDDilKuwwSyTvGgoktcC6TwQ71o_TAGQ-vpFWuB8VnpOAg |
3.删除权限执行以下命令
kubectl delete -f rbac-zxy.yaml
kubectl delete sa zxy -n kube-system
4.如果出现dashboard nodeport无法访问的时候,可以通过nodeName: k8s_master_ip绑定到master ip启动该服务