K8S笔记07 -- 部署dashbord


Kubernetes Dashboard 是 Kubernetes 集群的 Web UI,用于可视化管理集群

准备配置文件

到github 下载配置文件recommended.yaml,参考地址如下:
https://github.com/kubernetes/dashboard/tree/v2.1.0/aio/deploy/recommended.yaml

创建dashboard服务

eric@server1:/usr/local/kubernetes/cluster$ kubectl create -f  recommended.yaml
eric@server1:/usr/local/kubernetes/cluster$ kubectl get service -A
NAMESPACE              NAME                        TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)                  AGE
default                kubernetes                  ClusterIP      10.96.0.1        <none>        443/TCP                  7d15h
default                mysql-myshop                LoadBalancer   10.104.140.183   <pending>     3306:32036/TCP           104m
default                tomcat-http                 LoadBalancer   10.98.183.59     <pending>     8080:32168/TCP           7d3h
kube-system            kube-dns                    ClusterIP      10.96.0.10       <none>        53/UDP,53/TCP,9153/TCP   7d15h
kubernetes-dashboard   dashboard-metrics-scraper   ClusterIP      10.98.128.165    <none>        8000/TCP                 62m
kubernetes-dashboard   kubernetes-dashboard        ClusterIP      10.109.217.122   <none>        443/TCP                  62m

暴露服务并访问

可以看到默认采用ClusterIP模式,外部无法访问,修改为NodePort类型,如下:

eric@server1:/usr/local/kubernetes/cluster$ kubectl patch svc kubernetes-dashboard -p '{"spec":{"type":"NodePort"}}' -n kubernetes-dashboard
service/kubernetes-dashboard patched
eric@server1:/usr/local/kubernetes/cluster$ kubectl get service -A
NAMESPACE              NAME                        TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)                  AGE
default                kubernetes                  ClusterIP      10.96.0.1        <none>        443/TCP                  7d15h
default                mysql-myshop                LoadBalancer   10.104.140.183   <pending>     3306:32036/TCP           109m
default                tomcat-http                 LoadBalancer   10.98.183.59     <pending>     8080:32168/TCP           7d3h
kube-system            kube-dns                    ClusterIP      10.96.0.10       <none>        53/UDP,53/TCP,9153/TCP   7d15h
kubernetes-dashboard   dashboard-metrics-scraper   ClusterIP      10.98.128.165    <none>        8000/TCP                 67m
kubernetes-dashboard   kubernetes-dashboard        NodePort       10.109.217.122   <none>        443:30423/TCP            67m

通过master节点的 30423端口访问如下(由于安全设置 谷歌浏览器无法访问,使用火狐浏览器访问即可):请添加图片描述

创建Token

准备配置文件 dashborduser.yaml

apiVersion: v1
kind: ServiceAccount
metadata:
  name: admin-user
  namespace: kube-system
---
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

创建token

eric@server1:/usr/local/kubernetes/cluster$ kubectl create -f dashborduser.yaml
serviceaccount/admin-user created
clusterrolebinding.rbac.authorization.k8s.io/admin-user created

打印token

eric@server1:/usr/local/kubernetes/cluster$ kubectl -n kube-system describe secret $(![请添加图片描述](https://img-blog.csdnimg.cn/b2c125da3be04071bf1c32e848647932.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3poYW5neG1fcXo=,size_16,color_FFFFFF,t_70)
 | grep admin-user | awk '{print $1}')
Name:         admin-user-token-bxb7f
Namespace:    kube-system
Labels:       <none>
Annotations:  kubernetes.io/service-account.name: admin-user
              kubernetes.io/service-account.uid: 8c54db0e-031b-11ec-9d95-000c298dac9c

Type:  kubernetes.io/service-account-token

Data
====
ca.crt:     1025 bytes
namespace:  11 bytes
token:      eyJhbGciOiJSUzI1NiIsImtpZCI6IiJ9.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJhZG1pbi11c2VyLXRva2VuLWJ4YjdmIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQubmFtZSI6ImFkbWluLXVzZXIiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC51aWQiOiI4YzU0ZGIwZS0wMzFiLTExZWMtOWQ5NS0wMDBjMjk4ZGFjOWMiLCJzdWIiOiJzeXN0ZW06c2VydmljZWFjY291bnQ6a3ViZS1zeXN0ZW06YWRtaW4tdXNlciJ9.tir4SfGGYjJKC7BOee3zel-AiHS9f1itw-bwdhoDUJpnw8w0ZiNslZaXYMsjPuZGJZlexILSavluhS-ITslWxDpiFekAQ6st5TGa5HTX7NsYYmDpuBzKe8pbe8YIoAY9QJR5PKc1Oo50ZGRPfHqgjP_wfTuqKlpRzM5pTTG6HJtBiS8cwrBdKT7mgYI_nEly5-lMPPSXftD-NSF7eR3tvVxRxd27b6s6BKZULBlVBRHRWAjgmHWkftghcTEWBBWwbDLg2CQVeAYmAsiQ_j_V6nZEQtaIts2hRwl96w7K53qvnIx8ZWAEJGoo9B6Yo49KzwdORt1hpv8jY4-kFrvxdQ

登录dashboard

将上述token输入浏览器,并点击登录,进入dashboard界面,如下图:如下图:

请添加图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

catch that elf

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值