K8S 搭建一套带Dashboard的kubernetes集群( 二 )

第二个是添加一个type,指定端口类型为 NodePort,这样外界可以通过地址 nodeIP:nodePort 访问 dashboard,kubernetes-dashboard.yaml配置文件158行:
148 # ------------------- Dashboard Service ------------------- #149 150 kind: Service151 apiVersion: v1152 metadata:153 labels:154 k8s-app: kubernetes-dashboard155 name: kubernetes-dashboard156 namespace: kube-system157 spec:158 type: NodePort159 ports:160 - port: 443161 targetPort: 8443162 selector:163 k8s-app: kubernetes-dashboard部署到k8s集群
# kubectl apply -f kubernetes-dashboard.yaml # kubectl get pods -n kube-system |grep dashboardkubernetes-dashboard-6685cb584f-xlk2h 1/1 Running 0 98s# kubectl get pods,svc -n kube-systemNAME READY STATUS RESTARTS AGEpod/coreDNS-78d4cf999f-5hcjm 1/1 Running 0 3h21mpod/coredns-78d4cf999f-6mlql 1/1 Running 0 3h21mpod/etcd-k8sm-218 1/1 Running 0 3h20mpod/kube-apiserver-k8sm-218 1/1 Running 0 3h19mpod/kube-controller-manager-k8sm-218 1/1 Running 0 3h20mpod/kube-flannel-ds-amd64-6kfhg 1/1 Running 0 3h13mpod/kube-flannel-ds-amd64-c4fr4 1/1 Running 0 152mpod/kube-flannel-ds-amd64-qhc2w 1/1 Running 0 151mpod/kube-proxy-7hntq 1/1 Running 0 151mpod/kube-proxy-b4txb 1/1 Running 0 3h21mpod/kube-proxy-bz529 1/1 Running 0 152mpod/kube-scheduler-k8sm-218 1/1 Running 0 3h20mpod/kubernetes-dashboard-6685cb584f-xlk2h 1/1 Running 0 3m5sNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGEservice/kube-dns ClusterIP 10.96.0.10 <none> 53/UDP,53/TCP 3h21mservice/kubernetes-dashboard NodePort 10.104.4.26 <none> 443:31667/TCP 3m5s通过https访问ui

K8S 搭建一套带Dashboard的kubernetes集群

文章插图
登录页
Token (令牌) 认证方式登录
1)授权 (所有 namespace )
// 创建serviceaccount# kubectl create serviceaccount dashboard-serviceaccount -n kube-system// 创建clusterrolebinding# kubectl create clusterrolebinding dashboard-cluster-admin --clusterrole=cluster-admin --serviceaccount=kube-system:dashboard-serviceaccount2)获取令牌(用于网页登录)
// 查看口令列表# kubectl get secret -n kube-system |grep dashboard-serviceaccount-tokendashboard-serviceaccount-token-f45wg kubernetes.io/service-account-token 3 22s// 获取口令# kubectl describe secret dashboard-serviceaccount-token-f45wg -n kube-system3)将获取到的token放在令牌里
K8S 搭建一套带Dashboard的kubernetes集群

文章插图
输入token
4)登录成功
K8S 搭建一套带Dashboard的kubernetes集群

文章插图
K8S UI
至此,K8S集群+Dashboard搭建成功!
后记此篇不涉及理论,面向对象是刚接触K8S的朋友,最小成本来搭建一套K8S集群,以最快时间来看到效果,增加学习的信心^_^

【K8S 搭建一套带Dashboard的kubernetes集群】


推荐阅读