之前都是在命令行查看集群的一些信息,不是特别直观。这一节使用上一节学习的Helm安装下官方的可视化Dashboard,用图形界面查看下集群状态。

我是T型人小付,一位坚持终身学习的互联网从业者。喜欢我的博客欢迎在csdn上关注我,如果有问题欢迎在底下的评论区交流,谢谢。

安装Dashboard

这里使用Helm包管理工具进行安装,对Helm不是很熟悉的可以参考前一篇博客《【Kubernetes 019】包管理工具Helm安装和使用详解(最新Helm3版本》

下载Chart到本地

[root@k8s-master helm]# helm pull stable/kubernetes-dashboard
[root@k8s-master helm]# ll kuber*
-rw-r--r--. 1 root root 8682 May 17 15:15 kubernetes-dashboard-1.10.1.tgz

解压之后出现chart目录结构

[root@k8s-master helm]# cd kubernetes-dashboard
[root@k8s-master kubernetes-dashboard]# ll
total 28
-rwxr-xr-x. 1 root root   468 Jan  1  1970 Chart.yaml
-rwxr-xr-x. 1 root root 12858 Jan  1  1970 README.md
drwxr-xr-x. 2 root root   264 May 17 15:28 templates
-rwxr-xr-x. 1 root root  5470 Jan  1  1970 values.yaml

修改values.yaml文件

因为内容较多,我们直接新建一个自己的values-xiaofu.yaml文件如下


image:
  repository: registry.cn-shanghai.aliyuncs.com/zdl_work/kubernetes-dashboard-amd64
  tag: v1.10.1

ingress:
  enabled: true
  annotations:
    kubernetes.io/ingress.class: nginx
    kubernetes.io/tls-acme: 'true'
    nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"
  paths:
    - /
  hosts:
    - dashboard.xiaofu.com
  tls:
    - secretName: kubernetes-dashboard-tls
      hosts:
        - dashboard.xiaofu.com

rbac:
  clusterAdminRole: true

serviceAccount:
  name: dashboard-admin

需要注意几点:

  • 因为必须要用https的方式登录,所以这里要设置tls的信息。证书会自动被创建
  • RBAC直接给cluster-admin的role,这样Dashboard的权限最大,方便多个namespace进行查看和操作
  • SA不指定name也是可以的,会自动被创建。这里指定了为了方便后面进行查询
  • 如果不能用DNS,那么就修改hosts文件让dashboard.xiaofu.com指向任意一个node的ip

部署

接着用新建的values-xiaofu.yaml替代默认的values.yaml进行部署,注意-f参数

[root@k8s-master helm]# helm install kubernetes-dashboard -f values-xiaofu.yaml --generate-name
NAME: kubernetes-dashboard-1589711621
LAST DEPLOYED: Sun May 17 18:33:41 2020
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
*********************************************************************************
*** PLEASE BE PATIENT: kubernetes-dashboard may take a few minutes to install ***
*********************************************************************************
From outside the cluster, the server URL(s) are:
     https://dashboard.xiaofu.com

查看下Ingress的端口

[root@k8s-master helm]# kubectl get svc --all-namespaces
NAMESPACE       NAME                                 TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)                      AGE
default         kubernetes                           ClusterIP   10.96.0.1       <none>        443/TCP                      19d
default         kubernetes-dashboard-1589711621      ClusterIP   10.98.169.133   <none>        443/TCP                      6m45s
ingress-nginx   ingress-nginx-controller             NodePort    10.96.130.237   <none>        80:31958/TCP,443:30265/TCP   9d
ingress-nginx   ingress-nginx-controller-admission   ClusterIP   10.109.76.229   <none>        443/TCP                      9d
kube-system     kube-dns                             ClusterIP   10.96.0.10      <none>        53/UDP,53/TCP,9153/TCP       19d

这里使用30265端口对应https服务,于是从本地访问https://dashboard.xiaofu.com:30265
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-x96cv00U-1589723484677)(1-login.png)]
出现如上页面表示安装成功

登录

查询secret,找到含dashboard-admin的那一项。我这里是直接部署在default的namesapce下

[root@k8s-master helm]# kubectl get secret
NAME                                                    TYPE                                  DATA   AGE
basic-auth                                              Opaque                                1      8d
dashboard-admin-token-d4nfq                             kubernetes.io/service-account-token   3      17m
default-token-hln8x                                     kubernetes.io/service-account-token   3      19d
dockerhub-secret                                        kubernetes.io/dockerconfigjson        1      6d22h
kubernetes-dashboard-1589711621                         Opaque                                0      17m
sh.helm.release.v1.kubernetes-dashboard-1589711621.v1   helm.sh/release.v1                    1      17m
test-secret-1                                           Opaque                                1      7d2h
test-secret-2                                           Opaque                                2      6d23h
test-secret-3                                           Opaque                                2      7d1h
tls-secret                                              kubernetes.io/tls                     2      8d

查询一下即可

[root@k8s-master helm]# kubectl describe secret dashboard-admin-token-d4nfq
Name:         dashboard-admin-token-d4nfq
Namespace:    default
Labels:       <none>
Annotations:  kubernetes.io/service-account.name: dashboard-admin
              kubernetes.io/service-account.uid: bca698c8-6c31-4226-a2cf-4c92998ed8a8

Type:  kubernetes.io/service-account-token

Data
====
ca.crt:     1025 bytes
namespace:  7 bytes
token:      eyJhbGciOiJSUzI1NiIsImtpZCI6IiJ9.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJkZWZhdWx0Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZWNyZXQubmFtZSI6ImRhc2hib2FyZC1hZG1pbi10b2tlbi1kNG5mcSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50Lm5hbWUiOiJkYXNoYm9hcmQtYWRtaW4iLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC51aWQiOiJiY2E2OThjOC02YzMxLTQyMjYtYTJjZi00YzkyOTk4ZWQ4YTgiLCJzdWIiOiJzeXN0ZW06c2VydmljZWFjY291bnQ6ZGVmYXVsdDpkYXNoYm9hcmQtYWRtaW4ifQ.GLbXFhmc47ZZmAAaju91oK0ITU0NiuD6THGGQK3V8WOcRHyVuDcmw0eux_-0lmSqC6xr8FW0uUF1JhxsIfZtDhMi1WA1-TFwr-Qf69z5-dwduVHzAP48FSLrz2M22UdzR0Z9cUHMM2wjjfE2s3RHCFz-EUkzdfaZ29G-Bw01goJJr5lWWyfOI_NI-hsVmCRut2AnUrIpjXBUmj-1P61kNGZAccllpG5dsQ7xTtSjCjnMJgBmG2pxzcxjkNk3q6Xp7ilon5pE3QC6q_xcT6nsBXYPyfzm30NKg9-wGati9OC0Qqr4cWs6ytyhXSPgLezyfvAYHYfJPIAkJrvm9NB9Rw

将上述token信息直接填入网页即可
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-bzN8m2na-1589723484683)(2-main.png)]

利用Dashboard部署pod

如下图所示,切换到xiaofu-team的namespace,新建一个应用
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-dJOo2Zjs-1589723484687)(3-create.png)]
成功以后就会看到对应的Service已经起来
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-XFKGILYV-1589723484690)(4-6666.png)]
此时在node上curl 10.109.117.50:6666就会看到nginx的欢迎页面了

总结

这里只是简单的Dashboard安装和使用,更详细的自定义安装可以去看values.yaml中的各个字段的说明。

Logo

开源、云原生的融合云平台

更多推荐