k8s之图形界面DashBoard【九】

文章目录

  • [9. DashBoard](#9. DashBoard)
    • [9.1 部署Dashboard](#9.1 部署Dashboard)
    • [9.2 使用DashBoard](#9.2 使用DashBoard)

镇场



9. DashBoard

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

9.1 部署Dashboard

  1. 下载yaml,并运行Dashboard
shell 复制代码
# 下载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

shell 复制代码
[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的绝大部分功能,这里不再 一 一 演示

相关推荐
皮锤打乌龟4 小时前
(干货)Jenkins使用kubernetes插件连接k8s的认证方式
运维·kubernetes·jenkins
南猿北者5 小时前
docker Network(网络)
网络·docker·容器
ggaofeng8 小时前
通过命令学习k8s
云原生·容器·kubernetes
death bell8 小时前
Docker基础概念
运维·docker·容器
想学习java初学者11 小时前
Docker Compose部署Kafka(非Zookeeper)
docker·容器·kafka
qq_道可道11 小时前
K8S升级到1.24后,切换运行时导致 dind 构建镜像慢根因定位与解决
云原生·容器·kubernetes
SONGW201811 小时前
k8s拓扑域 :topologyKey
kubernetes
weixin_4381973813 小时前
K8S实现反向代理,负载均衡
linux·运维·服务器·nginx·kubernetes
牛右刀薛面15 小时前
麒麟V10,arm64,离线安装docker和docker-compose
运维·docker·容器·麒麟·鲲鹏
后端常规开发人员15 小时前
在 Mac 上使用 Docker 安装宝塔并部署 LNMP 环境
macos·docker·容器·宝塔