Kubernetes-Dashboard 简单介绍
Kubernetes-Dashboard 简单来说,就是一个 Kubernetes 集群的 Web UI 网页管理工具,提供了部署应用、资源对象管理、容器日志查询、监控系统等功能。下面是官网的一些介绍:
Dashboard is a web-based Kubernetes user interface. You can use Dashboard to deploy containerized applications to a Kubernetes cluster, troubleshoot your containerized application, and manage the cluster resources. You can use Dashboard to get an overview of applications running on your cluster, as well as for creating or modifying individual Kubernetes resources (such as Deployments, Jobs, DaemonSets, etc). For example, you can scale a Deployment, initiate a rolling update, restart a pod or deploy new applications using a deploy wizard.
Dashboard also provides information on the state of Kubernetes resources in your cluster and on any errors that may have occurred.
Kubernetes-Dashboard 安装部署
Kubernetes-Dashboard 的安装步骤主要有以下几步:
- 安装部署 kubernetes-dashboard
- 创建访问账户
- 访问 kubernetes-dashboard 的 UI 界面
1. 安装部署 kubernetes-dashboard
安装部署 kubernetes-dashboard 比较简单:
官方提供的方式,非常简单粗暴,允许以下命令就OK了:
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v1.10.1/src/deploy/recommended/kubernetes-dashboard.yaml
但由于国内不可描述的原因,我们还需要些额外步骤。具体安装步骤如下:
- 下载并修改官方提供的 kubernetes-dashboard.yaml 文件(出于国内不可描述的环境)
- 应用 kubernetes-dashboard.yaml
-
下载并修改官方提供的 kubernetes-dashboard.yaml 文件
curl https://raw.githubusercontent.com/kubernetes/dashboard/v1.10.1/src/deploy/recommended/kubernetes-dashboard.yaml > kubernetes-dashboard.yaml sed -i "s/k8s.gcr.io/registry.cn-hangzhou.aliyuncs.com\/google_containers/g" ./kubernetes-dashboard.yaml
-
应用 kubernetes-dashboard.yaml
kubectl apply -f kubernetes-dashboard.yaml
到这里,kubernetes-dashboard 就已经安装完成了,接下来创建访问账户的即可。
2.创建访问账户
使用 Kubernetes 的服务帐户机制创建一个新用户,授予该用户管理权限,并使用绑定到该用户的承载令牌登录到 dashboadr web 界面。这里主要有以下几个步骤:
- 创建服务帐户和集群角色绑定
- 获取用户登录 Token
- 创建导入浏览器的 .p12 文件
-
创建服务帐户和集群角色绑定
# 创建服务帐户 cat > dashboard_service_account_admin.yaml << EOF apiVersion: v1 kind: ServiceAccount metadata: name: admin-user namespace: kube-system EOF kubectl apply -f dashboard_service_account_admin.yaml # 创建集群角色绑定 cat > dashboard_cluster_role_binding_admin.yaml << EOF apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: admin-user roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: cluster-admin subjects: - kind: ServiceAccount name: admin-user namespace: kube-system EOF kubectl apply -f dashboard_cluster_role_binding_admin.yaml
-
获取用户登录 Token
kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep admin-user | awk '{print $1}') > admin-token.yaml && cat admin-token.yaml
输出如下:(记录输出的 token 信息即可)
Name: admin-user-token-d7ggs Namespace: kube-system Labels: <none> Annotations: kubernetes.io/service-account.name: admin-user kubernetes.io/service-account.uid: d98bf14c-3946-498c-a412-476f23395d72 Type: kubernetes.io/service-account-token Data ==== ca.crt: 1025 bytes namespace: 11 bytes token: // 记录 token ,登录时需要认证 eyJhbGciOiJSUzI1NiIsImtpZCI6IiJ9.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3 ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVy bmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJhZG1pbi11c2VyLXRva2VuLWQ 3Z2dzIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQubmFtZSI6Im FkbWluLXVzZXIiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC51 aWQiOiJkOThiZjE0Yy0zOTQ2LTQ5OGMtYTQxMi00NzZmMjMzOTVkNzIiLCJzdWIiOiJzeXN0ZW06 c2VydmljZWFjY291bnQ6a3ViZS1zeXN0ZW06YWRtaW4tdXNlciJ9.OZS63UIopsAl1_8klnRbB2INHs3 IRfb85bIiivUVgizpk2KcehcKjpsKJis27e_ucdwgSzkwYMzfeOUz8iBZM98PrBMi0N41UpSAlJJG7Xxwf1 eIUu3uWHVMF1phv3FIkHCmbVdVC40lguBOUT8_6Em3UyI3oKW_hIQEDLyyZEfSdQbmeeGZuQ-im LaXzvMR-V4q3UnD3gw775MaePYm4CZYlo5i6mfo2eGdQpl2ycaOJ-ZHbkpRhHS6x6E1ws13zTsRaSfru AmVfNa5wazC7-djBDZuBGuGq1y3fFlaEKB9YL4w__AG4rcz7Qm7Q3uAelZrph4_e9FWc2MXLxoew
-
创建导入浏览器的 .p12 证书文件
grep 'client-certificate-data' ~/.kube/config | head -n 1 | awk '{print $2}' | base64 -d >> kubecfg.crt grep 'client-key-data' ~/.kube/config | head -n 1 | awk '{print $2}' | base64 -d >> kubecfg.key openssl pkcs12 -export -clcerts -inkey kubecfg.key -in kubecfg.crt -out kubecfg.p12 -name "kubernetes-web-client"
输出如下:(记录输入的证书密码,登录时导入证书会用到)
Enter Export Password: // 输入证书密码 Verifying - Enter Export Password: // 输入证书密码
这时会在当前目录生成 kubecfg.p12 的证书文件
3.访问 kubernetes-dashboard 的 UI 界面
-
导入证书
在访问 kubernetes-dashboard 的 UI 界面前,首先需下载刚刚生成的 kubecfg.p12 证书文件并导入浏览器
image.png -
访问界面
image.png
访问https://<MASTER_IP>:6443/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/
,选择令牌,输入刚刚记录的 token 即可
接下来就可以进入 kubernetes-dashboard 的 UI 界面了
image.png
网友评论