Dashboard是Kubernetes集群的基于Web的通用UI。 它允许用户管理在群集中运行的应用程序并对其进行故障排除,以及管理群集本身。
安装步骤
- 解压源码包
- 修改配置文件
- 创建dashboard容器
- 创建Service Account,Dashboard Role & Role Binding
- 测试访问
解压源码包
我们解压了kubernetes-server-linux-amd64.tar.gz
之后,进入kubernetes
[root@k8s ~]# cd kubernetes
[root@k8s kubernetes]# ls
addons kubernetes-src.tar.gz LICENSES server
[root@k8s kubernetes]# tar zxf kubernetes-src.tar.gz
[root@k8s kubernetes]# ls
addons cluster hack Makefile.generated_files SECURITY_CONTACTS translations
api cmd kubernetes-src.tar.gz OWNERS server vendor
build code-of-conduct.md LICENSE OWNERS_ALIASES staging WORKSPACE
BUILD.bazel CONTRIBUTING.md LICENSES pkg SUPPORT.md
CHANGELOG-1.13.md docs logo plugin test
CHANGELOG.md Godeps Makefile README.md third_party
[root@k8s kubernetes]# cd cluster/addons/dashboard/
[root@k8s dashboard]# ls
dashboard-configmap.yaml dashboard-rbac.yaml dashboard-service.yaml OWNERS
dashboard-controller.yaml dashboard-secret.yaml MAINTAINERS.md README.md
修改配置文件
- 需要修改的文件是dashboard-controller.yaml,将其中的镜像替换成国内的镜像:
k8s.gcr.io/kubernetes-dashboard-amd64 替换成 registry.cn-hangzhou.aliyuncs.com/kuberneters/kubernetes-dashboard-amd64
阿里云的镜像地址为
https://cr.console.aliyun.com/cn-hangzhou/instances/images
替换完成后如图所示
修改文件dashboard-service.yaml 的外部访问方式修改为NodePort,增加type: NodePort
和nodePort: 30001
如图所示:
创建dashboard容器
创建对应的对象
[root@k8s dashboard]# kubectl create -f dashboard-configmap.yaml
configmap/kubernetes-dashboard-settings created
[root@k8s dashboard]# kubectl create -f dashboard-rbac.yaml
role.rbac.authorization.k8s.io/kubernetes-dashboard-minimal created
rolebinding.rbac.authorization.k8s.io/kubernetes-dashboard-minimal created
[root@k8s dashboard]# kubectl create -f dashboard-secret.yaml
secret/kubernetes-dashboard-certs created
secret/kubernetes-dashboard-key-holder created
[root@k8s dashboard]# kubectl create -f dashboard-controller.yaml
serviceaccount/kubernetes-dashboard created
deployment.apps/kubernetes-dashboard created
[root@k8s dashboard]# kubectl get pods -n kube-system
NAME READY STATUS RESTARTS AGE
kubernetes-dashboard-5fbc6b767b-mqps8 1/1 Running 0 13s
[root@k8s dashboard]# vim dashboard-service.yaml
[root@k8s dashboard]# kubectl create -f dashboard-service.yaml
service/kubernetes-dashboard created
[root@k8s dashboard]# kubectl get pods,svc -n kube-system
NAME READY STATUS RESTARTS AGE
pod/kubernetes-dashboard-5fbc6b767b-mqps8 1/1 Running 0 2m49s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes-dashboard NodePort 10.0.0.223 <none> 443:30001/TCP 32s
创建Service Account,Dashboard Role & Role Binding
创建admin-dashboard.yaml文件
[root@k8s dashboard]# cat admin-dashboard.yaml
# ------------------- Dashboard Service Account ------------------- #
apiVersion: v1
kind: ServiceAccount
metadata:
labels:
k8s-app: dashboard-admin
name: dashboard-admin
namespace: kube-system
---
# ------------------- Dashboard Role & Role Binding ------------------- #
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: kubernetes-dashboard-admin
namespace: kube-system
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: dashboard-admin
namespace: kube-system
[root@k8s dashboard]#
创建Service Account,Dashboard Role & Role Binding
[root@k8s dashboard]# kubectl create -f admin-dashboard.yaml
serviceaccount/dashboard-admin created
clusterrolebinding.rbac.authorization.k8s.io/kubernetes-dashboard-admin created
测试访问
访问地址:https://NodeIP:30001
注意:需要使用火狐浏览器,Google Chrome不可以
我们选择
令牌
选项获取令牌方式如下:
[root@k8s dashboard]# kubectl get secret -n kube-system
NAME TYPE DATA AGE
dashboard-admin-token-ms29g kubernetes.io/service-account-token 3 3m3s
default-token-9tsft kubernetes.io/service-account-token 3 2d23h
kubernetes-dashboard-certs Opaque 0 14m
kubernetes-dashboard-key-holder Opaque 2 14m
kubernetes-dashboard-token-5kx9h kubernetes.io/service-account-token 3 11m
[root@k8s dashboard]# kubectl describe secret dashboard-admin-token-ms29g -n kube-system
Name: dashboard-admin-token-ms29g
Namespace: kube-system
Labels: <none>
Annotations: kubernetes.io/service-account.name: dashboard-admin
kubernetes.io/service-account.uid: 6e7b454c-8374-11e9-b261-000c29f3daa6
Type: kubernetes.io/service-account-token
Data
====
namespace: 11 bytes
token: eyJhbGciOiJSUzI1NiIsImtpZCI6IiJ9.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJkYXNoYm9hcmQtYWRtaW4tdG9rZW4tbXMyOWciLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC5uYW1lIjoiZGFzaGJvYXJkLWFkbWluIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQudWlkIjoiNmU3YjQ1NGMtODM3NC0xMWU5LWIyNjEtMDAwYzI5ZjNkYWE2Iiwic3ViIjoic3lzdGVtOnNlcnZpY2VhY2NvdW50Omt1YmUtc3lzdGVtOmRhc2hib2FyZC1hZG1pbiJ9.Aqq5tiKJTSkPHkCwfQEyTmDpbny05BzopgZzLrmCpJSsW3atbxo0XP1Bo8g8Ja8qL8VUQMJDDp14R-UN0jEd2PEAQo56REJHHx55Lg3M4uIFL9bSshUlZWYjk3Rfpyk0-siuNBD8fO15kaEFBYnMHAbYYGmsdG0ysCmAk51VWhoEuuUn7xWoSDICU41rQw5549o9Ipi52dvynrbWbRKFhan_vMpR-bMBhzIC6fsl9p0eyy5hXg5BJBIbGGVxJqLVH-xHGp8TFHR0iUBHj3vOGihevuhKTo9R4oGY3xpACeZp8JO0a5gNtZrQC-mfMlqvlkEgZswfmb-1XeCFDtTPCA
ca.crt: 1359 bytes
- 首先查询secret,寻找dashboard-admin-token-xxxx命名的secret
-
使用describe查询令牌,token的那一长串即使令牌。复制到登陆页面的令牌输入框,点击登录即可进入主页面
至此,Dashboard部署完成。