【K8S 四】部署 kubernetes-dashboard 插件
目录修改配置并安装下载配置文件并修改配置创建并查看状态访问访问方式创建访问用户Bearer TokenKubeconfig修改配置并安装下载配置文件并修改配置wgethttps://raw.githubusercontent.com/kubernetes/dashboard/v2.0.4/aio/deploy/recommended.yamlcp recommended.yaml kube-das
目录
Kubernetes-Dashboard
Kubernetes仪表板是用于Kubernetes集群的基于web的通用UI。它允许用户去管理集群中运行的应用程序并对它们进行故障排除,还可以管理集群本身。
注意:
Kubeconfig认证方法不支持外部身份提供者或基于证书的认证。
metrches -server必须在集群中运行,才能提供度量和图表
修改配置并安装
下载配置文件并修改配置
wget https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.4/aio/deploy/recommended.yaml
cp recommended.yaml kube-dashboard.yaml
编辑kube-dashboard.yaml,追加ServiceAccount和ClusterRoleBinding,以供访问kube-dashboard。
这里为admin-user帐号绑定的是管理员权限:ClusterRole:cluster-admin。正式环境中,需要进行限制。
---
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 kube-dashboard.yaml
kubectl get all -n kubernetes-dashboard
NAME READY STATUS RESTARTS AGE
pod/dashboard-metrics-scraper-7b59f7d4df-vbmp8 1/1 Running 0 2d20h
pod/kubernetes-dashboard-665f4c5ff-pw4hf 1/1 Running 0 2d20hNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/dashboard-metrics-scraper ClusterIP 10.254.119.167 <none> 8000/TCP 2d20h
service/kubernetes-dashboard ClusterIP 10.254.200.228 <none> 443/TCP 2d20hNAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/dashboard-metrics-scraper 1/1 1 1 2d20h
deployment.apps/kubernetes-dashboard 1/1 1 1 2d20hNAME DESIRED CURRENT READY AGE
replicaset.apps/dashboard-metrics-scraper-7b59f7d4df 1 1 1 2d20h
replicaset.apps/kubernetes-dashboard-665f4c5ff 1 1 1 2d20h
访问
访问方式
kubernetes dashboard访问可以通过下面的方式:
1、kubectl proxy
通过命令(kubectl proxy --address='0.0.0.0' --port=8001)将代理服务开放到8001端口,并运行外网访问。但是,会有权限限制:(貌似:从 1.7 开始,dashboard 只允许通过 https 访问,如果使用 kube proxy 则必须监听 localhost 或 127.0.0.1。)
2、kubectl port-forward
通过命令(kubectl port-forward -n kubernetes-dashboard svc/kubernetes-dashboard 8443:443 --address 0.0.0.0)将dashboard的服务端口443转发到8443端口,并运行外网访问。
3、NodePort
修改kube-dashboard.yaml,将 service/kubernetes-dashboard的类型修改为NodePort,指定nodePort=4443。
通过上面任意方式访问kube-dashboard成功展示如下:
创建访问用户
Bearer Token
前面,我们已经修改kube-dashboard.yaml,追加ServiceAccount和ClusterRoleBinding。在创建dashboard时已经一起被创建,通过下面的命令查看admin-user的不记名Token:
kubectl -n kubernetes-dashboard describe secret $(kubectl -n kubernetes-dashboard get secret | grep admin-user | awk '{print $1}')
# kubectl -n kubernetes-dashboard describe secret $(kubectl -n kubernetes-dashboard get secret | grep admin-user | awk '{print $1}')
Name: admin-user-token-l7vhc
Namespace: kubernetes-dashboard
Labels: <none>
Annotations: kubernetes.io/service-account.name: admin-user
kubernetes.io/service-account.uid: 8d534c3b-51bb-4800-a750-e8252d1170cbType: kubernetes.io/service-account-token
Data
====
token: ……I1NiIsImtpZCI6Ik9ERWJvSVdyS0FBaVNfVDE3SjQ0MHVuNklYNXlXTzFpdk8xdTc……
ca.crt: 1066 bytes
namespace: 20 bytes在登录界面,选择Token输入token值,登录Dashboard:
Username/password
用户名密码认证属于Base Auth,默认是禁用的,需要配置Api-server;详细参考:
https://github.com/kubernetes/dashboard/blob/master/docs/user/access-control/README.md#basic
Kubeconfig
(未完待续)
修改默认token认证过期时间
默认900s/15分钟后认证token回话失效,需要重新登录认证,修改1h,方便使用;命令或者在线修改kubernetes-dashboardd,新增 --token-ttl=3600
kubectl edit deployment kubernetes-dashboard -n kubernetes-dashboard
更多推荐
所有评论(0)