一、 k8s的UI访问界面-dashboard
在dashboard中,虽然可以做到创建、删除、修改资源等操作,但通常情况下,我们会把它当做监控k8s集群的软件。
1、到GitHub主页上搜索"dashboard"即可。
//可以直接远程运行对应的yaml文件,不过,我们要看一看这个yaml文件内都有些什么内容,然后还需要将svc资源类型更改为NodePort的方式,所以这里我们可以先将这个yam文件下载到本地。
[root@master jk]# kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0/aio/deploy/recommended.yaml
[root@master jk]# ls
recommended.yaml
//更改其SVC资源的类型
[root@master jk]# vim recommended.yaml
...
spec:
type: NodePort
ports:
- port: 443
targetPort: 8443
nodePort: 30100
selector:
k8s-app: kubernetes-dashboard
...
[root@master jk]# 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
//通常,涉及到k8s的镜像,国内下载往往很慢,不过这个还好。运行过后,查看对应的SVC暴露端口,注意,这个是基于https的访问。
[root@master jk]# kubectl get pod -n kubernetes-dashboard
NAME READY STATUS RESTARTS AGE
dashboard-metrics-scraper-76679bc5b9-fnbsz 1/1 Running 0 106s
kubernetes-dashboard-7f9fd5966c-5gms5 1/1 Running 0 106s
[root@master jk]# kubectl get svc -n kubernetes-dashboard
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
dashboard-metrics-scraper ClusterIP 10.100.13.74 <none> 8000/TCP 68s
kubernetes-dashboard NodePort 10.108.0.135 <none> 443:30100/TCP 69s
浏览器访问:https://192.168.1.20:30100
//此时可以看到,登录dashboard有两种方式,哪一种都可以。(这里两种方式都列举出来)
基于token的方法登录dashboard
1、创建一个dashboard的管理用户。
[root@master jk]# kubectl create serviceaccount dashboard-admin -n kube-system
2、绑定用户为集群管理用户。
[root@master jk]# kubectl create clusterrolebinding dashboard-cluster-admin --clusterrole=cluster-admin --serviceaccount=kube-system:dashboard-admin
3、获取token
//得到token的名称
[root@master jk]# kubectl get secrets -n kube-system | grep dashboard-admin
dashboard-admin-token-5l2vh kubernetes.io/service-account-token 3 2m41s
//查看上述得到的secret资源的详细信息,会得到token. (后面加上刚得到的token名称)
[root@master jk]# kubectl describe secrets -n kube-system dashboard-admin-token-5l2vh