Kubernetes----Dashboard部署

一、Dashboard简介

Dashboard 是基于网页的 Kubernetes 用户界面。您可以使用 Dashboard 将容器应用部署到 Kubernetes 集群中,也可以对容器应用排错,还能管理集群本身及其附属资源。您可以使用 Dashboard 获取运行在集群中的应用的概览信息,也可以创建或者修改 Kubernetes 资源(如 Deployment,Job,DaemonSet 等等)。例如,您可以对 Deployment 实现弹性伸缩、发起滚动升级、重启 Pod 或者使用向导创建新的应用。

二、k8s集群部署Dashboard

k8s集群搭建文档参考:Kubernetes----kubeadm初始化k8s集群(1.16.9)

2.1、获取github上Dashboard部署的yaml文件

Dashboard的github地址

[root@master ~]# wget https://raw.githubusercontent.com/kubernetes/dashboard/v1.10.1/src/deploy/recommended/kubernetes-dashboard.yaml
--2019-07-30 11:03:36--  https://raw.githubusercontent.com/kubernetes/dashboard/v1.10.1/src/deploy/recommended/kubernetes-dashboard.yaml
正在解析主机 raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.228.133
正在连接 raw.githubusercontent.com (raw.githubusercontent.com)|151.101.228.133|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:4577 (4.5K) [text/plain]
正在保存至: “kubernetes-dashboard.yaml”

100%[=========================================================================================================================================================================>] 4,577       --.-K/s 用时 0s      

2019-07-30 11:03:38 (16.0 MB/s) - 已保存 “kubernetes-dashboard.yaml” [4577/4577])

2.2、修改下载的kubernetes-dashboard.yaml文件

service模块配置暴露k8s集群外部访问端口,配置如下:

# ------------------- Dashboard Service ------------------- #

kind: Service
apiVersion: v1
metadata:
  labels:
    k8s-app: kubernetes-dashboard
  name: kubernetes-dashboard
  namespace: kube-system
spec:
  type: NodePort
  ports:
    - port: 443
      targetPort: 8443
      nodePort: 30001
  selector:
    k8s-app: kubernetes-dashboard

修改与文件镜像

-        image: k8s.gcr.io/kubernetes-dashboard-amd64:v1.10.1
+        image: cuiyf/kubernetes-dashboard-amd64:v1.10.1

2.3、启动Dashboard

[root@master yaml]# kubectl create -f kubernetes-dashboard.yaml 
secret/kubernetes-dashboard-certs created
serviceaccount/kubernetes-dashboard created
role.rbac.authorization.k8s.io/kubernetes-dashboard-minimal created
rolebinding.rbac.authorization.k8s.io/kubernetes-dashboard-minimal created
deployment.apps/kubernetes-dashboard created
service/kubernetes-dashboard created

2.4、访问master节点:https://masterip:30001

注意:一定要https,web界面如下:
在这里插入图片描述

2.5、使用令牌登录(需要创建能够访问 Dashboard 的用户)

account.yaml配置如下:

# Create Service Account
apiVersion: v1
kind: ServiceAccount
metadata:
  name: admin-user
  namespace: kube-system
---
# Create ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
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

创建用户:

[root@master yaml]# kubectl create -f account.yaml

获取tocken:

[root@master ~]# kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep admin-user | awk '{print $1}')
Name:         admin-user-token-p7p6p
Namespace:    kube-system
Labels:       <none>
Annotations:  kubernetes.io/service-account.name: admin-user
              kubernetes.io/service-account.uid: aef9512e-b1e6-11e9-ac67-0800273a2eb7

Type:  kubernetes.io/service-account-token

Data
====
ca.crt:     1025 bytes
namespace:  11 bytes
token:      eyJhbGciOiJSUzI1NiIsImtpZCI6IiJ9.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJhZG1pbi11c2VyLXRva2VuLXA3cDZwIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQubmFtZSI6ImFkbWluLXVzZXIiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC51aWQiOiJhZWY5NTEyZS1iMWU2LTExZTktYWM2Ny0wODAwMjczYTJlYjciLCJzdWIiOiJzeXN0ZW06c2VydmljZWFjY291bnQ6a3ViZS1zeXN0ZW06YWRtaW4tdXNlciJ9.Z5VD5NBGUWTxteQoKsKSJNyQDBMNT5MlEB_WI60qjvltK2lggyxiN5pJdo0Rz7C9RP_HFMN4Vkni2X7zHvEIGuAKda74V4JQXg8wzQoQR-kX70f3YZWNEw5wkSZjKCNcWnxcptWAdDAHnsk_gMhR5nWqTKOkk3CZMKFZbJQ-fdkuw9GnyAfBJTSmg2ajXi4FSaRiQlhAr9fH9954Ed5iht5TZipVvb7T4LN-3Ba5rPBqFqKnyp92pntN-UTpesvo7oAffrauSyIjIU10zu4OEvrvQysAa5lT9beyMOQsWJ82_Owqqk4fYUyfsmc-KGVaa8XeR808DiPypwGvGy2oGg

2.6、最终登录界面如下在这里插入图片描述

参考资料

Kubernetes Dashboard 及监控组件 Heapster 部署

附004.Kubernetes Dashboard简介及使用

Kubernetes DashboardKubernetes 官方提供的一个 Web 界面,用于管理 Kubernetes 集群。以下是部署 Kubernetes Dashboard 的步骤: 1. 下载 Kubernetes Dashboard YAML 文件: ```bash curl -LO https://raw.githubusercontent.com/kubernetes/dashboard/v2.4.0/aio/deploy/recommended.yaml ``` 2. 修改 Kubernetes Dashboard Service 类型: 将 recommended.yaml 文件中的 Service 类型从 ClusterIP 修改为 NodePort,这样可以通过 Node 的 IP 地址加端口号访问 Kubernetes Dashboard。 ```yaml apiVersion: v1 kind: Service metadata: name: kubernetes-dashboard namespace: kubernetes-dashboard labels: k8s-app: kubernetes-dashboard spec: type: NodePort # 将类型修改为 NodePort ports: - port: 443 targetPort: 8443 selector: k8s-app: kubernetes-dashboard ``` 3. 部署 Kubernetes Dashboard: ```bash kubectl apply -f recommended.yaml ``` 4. 创建 Service Account: ```bash cat <<EOF | kubectl apply -f - apiVersion: v1 kind: ServiceAccount metadata: name: admin-user namespace: kubernetes-dashboard EOF ``` 5. 创建 Cluster Role Binding: ```bash cat <<EOF | kubectl apply -f - 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 EOF ``` 6. 获取 Token: ```bash kubectl -n kubernetes-dashboard describe secret $(kubectl -n kubernetes-dashboard get secret | grep admin-user | awk '{print $1}') ``` 7. 访问 Kubernetes Dashboard: 使用浏览器访问 Node 的 IP 地址加端口号,输入 Token 登录即可。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值