注:因为本次部署在Centos8.1上,Dashboard必须使⽤2.0-rc6以 上版本,rc6以下测试部署不成功
Dashboard介绍
Dashboard 是基于⻚的 Kubernetes ⽤户界⾯。您可以使⽤ Dashboard 将容器应⽤部署到 Kubernetes 集群中,也可以对容器应 ⽤排错,还能管理集群资源。您可以使⽤ Dashboard 获取运⾏在集群 中的应⽤的概览信息,也可以创建或者修改 Kubernetes 资源(如 Deployment,Job,DaemonSet 等等)。例如,您可以对 Deployment 实现弹性伸缩、发起滚动升级、重启 Pod 或者使⽤向导 创建新的应用。
获取并修改Yaml文件
GitHub上目前最新版本是dashboard v2.0.0-rc6
项⽬地址
https://github.com/kubernetes/dashboard/releases
# wget
https://raw.githubusercontent.com/kubernetes/dashboar
d/v2.0.0-beta8/aio/deploy/recommended.yaml
修改service通过NodePort方式访问K8S Dashboard
# vim recommended.yaml
kind: Service
apiVersion: v1
metadata:
labels:
k8s-app: kubernetes-dashboard
name: kubernetes-dashboard
namespace: kubernetes-dashboard
spec:
type: NodePort #新加此⾏
ports:
- port: 443
nodePort:30001 #新加此⾏
targetPort: 8443
selector:
k8s-app: kubernetes-dashboard
应用配置文件
# kubectl apply -f recommended.yaml
查看pod和service
[root@master dashboard1]# kubectl get pod -o wide -n
kubernetes-dashboard
NAME READY
STATUS RESTARTS AGE IP NODE
NOMINATED NODE READINESS GATES
dashboard-metrics-scraper-7b8b58dc8b-29wxq 1/1
Running 0 19m 10.244.2.18 node2
<none> <none>
kubernetes-dashboard-755dcb9575-fj8jl 1/1
Running 0 19m 10.244.1.28 node1
<none> <none>
[root@master dashboard1]# kubectl get svc -o wide -n
kubernetes-dashboard
NAME TYPE CLUSTER-IP
EXTERNAL-IP PORT(S) AGE SELECTOR
dashboard-metrics-scraper ClusterIP 10.98.53.94
<none> 8000/TCP 19m k8sapp=dashboard-metrics-scraper
kubernetes-dashboard NodePort 10.109.85.22
<none> 443:30001/TCP 19m k8sapp=kubernetes-dashboard
访问Dashboard
注:通过Chrome、IE、Safari可能⽆法访问这个⻚⾯,这⾥使⽤ ⽕狐访问
⽕狐浏览器访问
创建⼀个dashboard⽤户
# vim create-admin.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
# kubectl apply -f create-admin.yaml
获取Token
[root@master dashboard1]# kubectl -n kubernetesdashboard describe secret $(kubectl -n kubernetesdashboard get secret | grep admin-user | awk '{print
$1}')
Name: admin-user-token-z4jp6
Namespace: kubernetes-dashboard
Labels: <none>
Annotations: kubernetes.io/service-account.name:
admin-user
kubernetes.io/service-account.uid:
349285ce-741d-4dc1-a600-1843a6ec9751
Type: kubernetes.io/service-account-token
Data
====
token:
eyJhbGciOiJSUzI1NiIsImtpZCI6InY5M1pSc3RpejBVZ0x6LTNS
bWlCc2t5b01ualNZWnpYMVB5YzUwNmZ3ZmsifQ.eyJpc3MiOiJrd
WJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pb
y9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlcm5ldGVzL
WRhc2hib2FyZCIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291b
nQvc2VjcmV0Lm5hbWUiOiJhZG1pbi11c2VyLXRva2VuLXo0anA2I
iwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlL
WFjY291bnQubmFtZSI6ImFkbWluLXVzZXIiLCJrdWJlcm5ldGVzL
mlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC51aWQiO
iIzNDkyODVjZS03NDFkLTRkYzEtYTYwMC0xODQzYTZlYzk3NTEiL
CJzdWIiOiJzeXN0ZW06c2VydmljZWFjY291bnQ6a3ViZXJuZXRlc
y1kYXNoYm9hcmQ6YWRtaW4tdXNlciJ9.JtCa0VC7tYtIGLWlwSKU
wqSL0T8eRvZ8jk_AUxB4Atmi5PjF9IjAHNNwGS3HaTL3Q86fCI8M
vYGf3Eplk9X-ng9WsrFIxXxa0wGJxZp0d8R78A6vuN7I7Zd5CeQm_O2ycTUuQhYnS
ZlNplF8X033QOfjOoFnKKevbn2094XXWWZuAsT9haGnZ8BX92DmY
zsaMyLesfv7ZziJD80KgSQ8_jtb0n55zw5cedYTsRCZgofJ_o9U5
SUW3I0AXG-vVhI28m0sMBjZkuMppfB4eMLnSDHXAw3Gvwe_2NOLfS4hBTkYu7gJketgif9Cs8Ybkzvf2qXdZW5fydZUuSylafg
ca.crt: 1025 bytes
namespace: 20 bytes
登录dashboard
登陆后界⾯
使用Dashboard
在Dashboard中,我们之前通过kubectl所做的操作⼤部分都可以 可视化操作
比如
1、可以对Deployment做伸缩
2、执⾏命令以及⽇志追踪
3、编辑资源的yaml⽂件
4、导⼊yaml⽂件创建,更新资源等等
以上与大家分享的内容,如果需要领取免费学习资料,或者学习交流,扫码加我拉你进群