k8s之图形界面DashBoard【九】

镇场


在这里插入图片描述


9. DashBoard

之前在kubernetes中完成的所有操作都是通过命令行工具kubectl完成的。其实,为了提供更丰富的用户体验,kubernetes还开发了一个基于web的用户界面(Dashboard)。用户可以使用Dashboard部署容器化的应用,还可以监控应用的状态,执行故障排查以及管理kubernetes中各种资源。

9.1 部署Dashboard

  1. 下载yaml,并运行Dashboard
# 下载yaml
[root@k8s-master ~]# mkdir dashboard
[root@k8s-master ~]# cd dashboard/
[root@k8s-master dashboard]# ls
[root@k8s-master dashboard]# wget https://raw.githubusercontent.com/kubernetes/dashboard/v2.7.0/aio/deploy/recommended.yaml
[root@k8s-master dashboard]# ls
recommended.yaml

# 修改kubernetes-dashboard的Service类型
kind: Service
apiVersion: v1
metadata:
  labels:
    k8s-app: kubernetes-dashboard
  name: kubernetes-dashboard
  namespace: kubernetes-dashboard
spec:
  type: NodePort  # 新增
  ports:
    - port: 443
      targetPort: 8443
      nodePort: 30009  # 新增
  selector:
    k8s-app: kubernetes-dashboard

# 部署
[root@k8s-master dashboard]# pwd
/root/dashboard
[root@k8s-master dashboard]# kubectl apply -f recommended.yaml 
namespace/kubernetes-dashboard created
serviceaccount/kubernetes-dashboard created
service/kubernetes-dashboard created
secret/kubernetes-dashboard-certs created
secret/kubernetes-dashboard-csrf created
secret/kubernetes-dashboard-key-holder created
configmap/kubernetes-dashboard-settings created
role.rbac.authorization.k8s.io/kubernetes-dashboard created
clusterrole.rbac.authorization.k8s.io/kubernetes-dashboard created
rolebinding.rbac.authorization.k8s.io/kubernetes-dashboard created
clusterrolebinding.rbac.authorization.k8s.io/kubernetes-dashboard created
deployment.apps/kubernetes-dashboard created
service/dashboard-metrics-scraper created
deployment.apps/dashboard-metrics-scraper created

[root@k8s-master ~]# kubectl get ns
NAME                   STATUS   AGE
default                Active   27d
kube-flannel           Active   27d
kube-node-lease        Active   27d
kube-public            Active   27d
kube-system            Active   27d
kubernetes-dashboard   Active   53s  # 创建了namespace

# 查看namespace下的kubernetes-dashboard下的资源
[root@k8s-master ~]# kubectl get pod,svc -n kubernetes-dashboard
NAME                                             READY   STATUS    RESTARTS   AGE
pod/dashboard-metrics-scraper-5657497c4c-srlqd   1/1     Running   0          83s
pod/kubernetes-dashboard-78f87ddfc-mmxpt         1/1     Running   0          83s

NAME                                TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)         AGE
service/dashboard-metrics-scraper   ClusterIP   10.110.144.31   <none>        8000/TCP        83s
service/kubernetes-dashboard        NodePort    10.106.32.91    <none>        443:30009/TCP   83s

2)创建访问账户,获取token

[root@k8s-master ~]# cd dashboard/
[root@k8s-master dashboard]# vi serviceaccount-admin-user.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
  name: admin-user       # 创建账号
  namespace: kubernetes-dashboard
---
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: kubernetes-dashboard
[root@k8s-master dashboard]# kubectl apply -f serviceaccount-admin-user.yaml 
serviceaccount/admin-user created
clusterrolebinding.rbac.authorization.k8s.io/admin-user created


# 获取账号token
[root@k8s-master dashboard]# kubectl -n kubernetes-dashboard create token admin-user
eyJhbGciOiJSUzI1NiIsImtpZCI6IjJ2OGY3aGtNYkR0ZEZBZi1PZHBpNTU0TUF4TXV6RW5CanE4U3RUa2xYNjgifQ.eyJhdWQiOlsiaHR0cHM6Ly9rdWJlcm5ldGVzLmRlZmF1bHQuc3ZjLmNsdXN0ZXIubG9jYWwiXSwiZXhwIjoxNzA0Njg3ODAyLCJpYXQiOjE3MDQ2ODQyMDIsImlzcyI6Imh0dHBzOi8va3ViZXJuZXRlcy5kZWZhdWx0LnN2Yy5jbHVzdGVyLmxvY2FsIiwia3ViZXJuZXRlcy5pbyI6eyJuYW1lc3BhY2UiOiJrdWJlcm5ldGVzLWRhc2hib2FyZCIsInNlcnZpY2VhY2NvdW50Ijp7Im5hbWUiOiJhZG1pbi11c2VyIiwidWlkIjoiNDY4YWE0OGEtZmI3NC00MGE5LWI3YTAtM2I2ZTIyNDJhZGUwIn19LCJuYmYiOjE3MDQ2ODQyMDIsInN1YiI6InN5c3RlbTpzZXJ2aWNlYWNjb3VudDprdWJlcm5ldGVzLWRhc2hib2FyZDphZG1pbi11c2VyIn0.Va4LcUxpaLMKzS_ItOqrHjnEin8iu0q1vGY831StGXmDCM-MuF4YBt2V1dpSitkbLSUsYZNVzpvCLmIgdPstBdPV7jW0VMwffwIsPI_8MVuUc6vnJP2_soqMyS_ZxVkb3gogSGAL6QzAcbPpXirIbHHtLutQnLSfXOa9j_Lpu85ANJFXEFV0kwSLI_DC9dlYu8-pQmPC8e706kjUGfVDnHGg-KmnvV9cuNHxFoe06uUd9IcSJdGIKpx7wZu--O0IAQ6Cq_MRS8enYf6jN83OJ2xiD33KZQ9YCrpUCQFNMGX7diK4Wbx5s1aFZiPSs8hfeDXMzRT24jQYyp6FTzYgMw
[root@k8s-master dashboard]# 

3)通过浏览器访问Dashboard的UI

在登录页面上输入上面的token

在这里插入图片描述

出现下面的页面代表成功

在这里插入图片描述

9.2 使用DashBoard

本章节以Deployment为例演示DashBoard的使用

查看

选择指定的命名空间dev,然后点击Deployments,查看dev空间下的所有deployment

在这里插入图片描述

扩缩容

Deployment上点击规模,然后指定目标副本数量,点击确定

在这里插入图片描述

编辑

Deployment上点击编辑,然后修改yaml文件,点击确定

在这里插入图片描述

查看Pod

点击Pods, 查看pods列表

在这里插入图片描述

操作Pod

选中某个Pod,可以对其执行日志(logs)、进入执行(exec)、编辑、删除操作

在这里插入图片描述

Dashboard提供了kubectl的绝大部分功能,这里不再 一 一 演示

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值