K8S---多节点部署---UI界面(6)

K8S—多节点部署—UI界面

搭建k8s的Dashboard

1.创建目录,上次yaml文件
[root@localhost k8s]# mkdir dashboard

[root@localhost k8s]# cd dashboard/
[root@localhost dashboard]# ls
dashboard-configmap.yaml   dashboard-rbac.yaml    dashboard-service.yaml
dashboard-controller.yaml  dashboard-secret.yaml  k8s-admin.yaml
您在 /var/spool/mail/root 中有邮件
2.创建所需文件,按一下顺序
//配置授权访问api,角色控制,访问控制

[root@localhost dashboard]#  kubectl create -f dashboard-rbac.yaml
role.rbac.authorization.k8s.io/kubernetes-dashboard-minimal created
rolebinding.rbac.authorization.k8s.io/kubernetes-dashboard-minimal created

//配置进行加密,安全设定

[root@localhost dashboard]# kubectl create -f dashboard-secret.yaml
secret/kubernetes-dashboard-certs created
secret/kubernetes-dashboard-key-holder created

//配置网站应用

[root@localhost dashboard]# kubectl create -f dashboard-configmap.yaml
configmap/kubernetes-dashboard-settings created

//配置控制器

[root@localhost dashboard]# kubectl create -f dashboard-controller.yaml
serviceaccount/kubernetes-dashboard created
deployment.apps/kubernetes-dashboard created

//配置发布出去服务,给别人进行访问

[root@localhost dashboard]# kubectl create -f dashboard-service.yaml
service/kubernetes-dashboard created

//完成后查看创建在指定的kube-system命名空间下

[root@localhost dashboard]# kubectl get pods -n kube-system
NAME                                    READY   STATUS              RESTARTS   AGE
kubernetes-dashboard-65f974f565-9svdg   0/1     ContainerCreating   0          13s

//查看如何访问

[root@localhost dashboard]# kubectl get pods,svc -n kube-system
NAME                                        READY   STATUS    RESTARTS   AGE
pod/kubernetes-dashboard-65f974f565-9svdg   1/1     Running   0          2m18s

NAME                           TYPE       CLUSTER-IP   EXTERNAL-IP   PORT(S)         AGE
service/kubernetes-dashboard   NodePort   10.0.0.247           443:30001/TCP   2m12s
3.访问nodeIP就可以访问

出现如下错误:

K8S---多节点部署---UI界面(6)_第1张图片

4.产生上述错误是因为没有令牌,我们需要自行生成令牌
//制作证书脚本

[root@localhost dashboard]# vim dashboard-cert.sh

cat > dashboard-csr.json <
5.生成登陆token
//生成令牌

[root@localhost dashboard]# kubectl create -f k8s-admin.yaml
serviceaccount/dashboard-admin created
clusterrolebinding.rbac.authorization.k8s.io/dashboard-admin created

//保存令牌

[root@localhost dashboard]# kubectl get secret -n kube-system
NAME                               TYPE                                  DATA   AGE
dashboard-admin-token-7bm26        kubernetes.io/service-account-token   3      57s
default-token-8fmt5                kubernetes.io/service-account-token   3      4d17h
kubernetes-dashboard-certs         Opaque                                11     7m28s
kubernetes-dashboard-key-holder    Opaque                                2      16m
kubernetes-dashboard-token-cpcmn   kubernetes.io/service-account-token   3      16m

//查看令牌

[root@localhost dashboard]# kubectl describe secret dashboard-admin-token-7bm26 -n kube-system
Name:         dashboard-admin-token-7bm26
Namespace:    kube-system
Labels:       
Annotations:  kubernetes.io/service-account.name: dashboard-admin
              kubernetes.io/service-account.uid: 8d3a76f9-929f-11ea-96fd-000c297c1b9b

Type:  kubernetes.io/service-account-token

Data
====
ca.crt:     1359 bytes
namespace:  11 bytes
token:      eyJhbGciOiJSUzI1NiIsImtpZCI6IiJ9.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJkYXNoYm9hcmQtYWRtaW4tdG9rZW4tN2JtMjYiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC5uYW1lIjoiZGFzaGJvYXJkLWFkbWluIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQudWlkIjoiOGQzYTc2ZjktOTI5Zi0xMWVhLTk2ZmQtMDAwYzI5N2MxYjliIiwic3ViIjoic3lzdGVtOnNlcnZpY2VhY2NvdW50Omt1YmUtc3lzdGVtOmRhc2hib2FyZC1hZG1pbiJ9.EPvr9wEsCmYU4O1Jr7panpbPJISheqfFjSgwuKbNqmi8aJ2dpuE7TUhOgePaDFElVItyNrORVA61Gt13EMRIFulblHYp2iQ0kPrcJrCgoK2W6Ld7R1PHnNGcb6rsPid0ffNUdtANQhmtdA_PEvd0foMFvkzajS-5gJyQo_03p1Mu8_dTtZaHpowQbVL8EOpTGFAqVTd1zvx_5waj21KZhMKftCPLEm3dzPkHanDrUACSBHDgLnbVGin6r-jfvG8eZDk4-EvdKYp8mMKzklLhAUrwFOz73So0fMI4A27zL-IZ5c5t17APP5WNPRXBBTiuZHngakpACfhE_qK7Ek84FQ
6.登陆dashbord(如果node1地址访问不了,可以尝试用node2地址,因为apply之后,地址可能会重新获取)

K8S---多节点部署---UI界面(6)_第2张图片
K8S---多节点部署---UI界面(6)_第3张图片
K8S---多节点部署---UI界面(6)_第4张图片
K8S---多节点部署---UI界面(6)_第5张图片

你可能感兴趣的:(K8S)