k8s配置dashboard

1.获取创建dashboard的yaml文件

[root@master-11 ~]# wget https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0/aio/deploy/recommended.yaml

拉取不下来的话可以执行这条命令添加到/raw.githubusercontent.com的主机解析

echo "151.101.108.133 raw.githubusercontent.com" >> /etc/hosts

2.拉取相关镜像

[root@master-11 ~]# docker pull registry.cn-hangzhou.aliyuncs.com/ccgg/metrics-scraper:v1.0.4
[root@master-11 ~]# docker pull registry.cn-hangzhou.aliyuncs.com/ccgg/dashboard:v2.0.0

3.修改yaml文件所使用的镜像

[root@master-11 ~]# sed -i 's#kubernetesui/dashboard:v2.0.0#registry.cn-hangzhou.aliyuncs.com/ccgg/dashboard:v2.0.0#g' recommended.yaml 
[root@master-11 ~]# sed -i 's#kubernetesui/metrics-scraper:v1.0.4#registry.cn-hangzhou.aliyuncs.com/ccgg/metrics-scraper:v1.0.4#g' recommended.yaml 

4.修改yaml文件访问的方式

[root@master-11 ~]# vim recommended.yaml  #
----
spec:
  type: NodePort ##在第40行左右添加service的类型为NodePort
  ports:
    - port: 443
      targetPort: 8443
      nodePort: 30001  ##还有访问的端口为30001
----

5.创建dashboard所需要的相关资源

[root@master-11 ~]# 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

6.查看pod状态

[root@master-11 ~]# kubectl get pods -n kubernetes-dashboard  ##当这两个pod都起来时,我们就可以访问了
NAME                                         READY   STATUS    RESTARTS   AGE
dashboard-metrics-scraper-7fc97b986d-2fm72   1/1     Running   0          8m28s
kubernetes-dashboard-679648ffb-7jbtk         1/1     Running   0          8m28s

7.使用浏览器访问并初始化

访问地址是 https://172.16.210.11:30001
点击高级

image.png

点击继续前往
image.png

这里需要我们输入token证书
image.png

7.创建service acount并绑定默认cluster-admin管理员角色

kubectl create serviceaccount dashboard-admin -n kube-system
kubectl create clusterrolebinding dashboard-admin --clusterrole=cluster-admin --serviceaccount=kube-system:dashboard-admin
 kubectl describe secrets -n kube-system $(kubectl -n kube-system get secret | awk '/dashboard-admin/{print $1}')
image.png

将输出的token粘贴到浏览器里,再点击登录

image.png

登录成功
image.png

你可能感兴趣的:(k8s配置dashboard)