1、下载yaml文件:https://github.com/kubernetes/dashboard/blob/v2.0.0/aio/deploy/recommended.yaml
2、修改yaml文件的service 配置:
---------------------------------------------
---
kind: Service
apiVersion: v1
metadata:
labels:
k8s-app: kubernetes-dashboard
name: kubernetes-dashboard
namespace: kubernetes-dashboard
spec:
type: NodePort #新增 允许外部访问
ports:
- port: 443
targetPort: 8443
nodePort: 30009 #自定义外部访问端口
selector:
k8s-app: kubernetes-dashboard
---
-------------------------------------------------------------------
3、执行yaml文件部署dashboard:
·kubectl create -f recommended.yaml
4、查看svc和pod:
·kubectl get svc,pods -n kubernetes-dashboard
------------------------------------------------------------------------------------
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/dashboard-metrics-scraper ClusterIP 10.111.75.214 <none> 8000/TCP 70s
service/kubernetes-dashboard NodePort 10.107.18.72 <none> 443:30009/TCP 70s
NAME READY STATUS RESTARTS AGE
pod/dashboard-metrics-scraper-c79c65bb7-m294t 0/1 ContainerCreating 0 70s
pod/kubernetes-dashboard-56484d4c5-hzjr7 0/1 ContainerCreating 0 70s
-----------------------------------------------------------------------------------------------------------------------
5、访问网页:https://192.168.177.160:30009 #建议使用火狐浏览器访问
6、登录需要Token、创建访问账号、获取token:
#dashboard-admin 用户名 给用户授权 -n (namespace的权限) kubernetes-dashboard
·创建账号:kubectl create serviceaccount dashboard-admin -n kubernetes-dashboard
·授权:kubectl create clusterrolebinding dashboard-admin-rb --clusterrole=cluster-admin --serviceaccount=kubernetes-dashboard:dashboard-admin
7、获取账号token:
·kubectl get secrets -n kubernetes-dashboard | grep dashboard-admin
--------------------------------------------------------------------------------------------
dashboard-admin-token-k4dnd kubernetes.io/service-account-token 3 12m
-----------------------------------------------------------------------------------------------
·kubectl describe secrets dashboard-admin-token-k4dnd -n kubernetes-dashboard
-----------------------------------------------------------------------------------------------------
Name: dashboard-admin-token-k4dnd
Namespace: kubernetes-dashboard
Labels: <none>
Annotations: kubernetes.io/service-account.name: dashboard-admin
kubernetes.io/service-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------------------------------------------------------------------------------------------------------------------------------------
8、将获取的token写入到网页:
标签:web,service,kubernetes,kubectl,admin,50,token,dashboard,k8s From: https://www.cnblogs.com/littlecc/p/17701190.html