Kubernetes-dashboard的部署及认证

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/isaiah282485068/article/details/85545260

部署Kubernetes-dashboard

简介:

dashboard是通用的基于Web的k8s集群图形化管理工具,它允许用户管理在集群中运行的应用程序,并对它们进行故障排除,以及管理集群本身。

部署:

  1. 部署dashboard应用资源:
    kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v1.10.1/src/deploy/recommended/kubernetes-dashboard.yaml
  2. 修改为NodePort类型的service,让集群外部也可以访问dashboard:

    kubectl patch svc kubernetes-dashboard -p '{"spec": {"type":"NodePort"}}' -n kube-system
  3. 在集群外部访问dashboard:

使用token认证进行登录

dashboard运行在POD资源中的,所以呢dashboard所在的POD要以serviceAcount类型的用户身份认证到k8s集群上去访问k8s的api server组件

  1.  创建serviceAccount,假如用户名为dashboard-admin

    kubectl create serviceaccount dashboard-admin -n kube-system
  2. 通过clusterrolebinding绑定到内置的cluster-admin角色上

    kubectl create clusterrolebinding dashboard-cluster-admin --clusterrole=cluster-admin --serviceaccount=kube-system:dashboard-admin
  3. 查看dashboard-admin用户的securet:

    kubectl get secret -n kube-system
    
    kubectl describe secret dashboard-admin-token-6lk9l  -n kube-system
  4. 复制dashboard-admin用户的对应的securet对象中的token进行登录dashboard:

使用kubeconfig认证进行登录

上面认证时使用的token采用的是base64编码,并登录时需要复制原内容粘贴到文本框中,存储和操作非常不方便,建议使用将它保存到kubeconfig配置文件中,使用kubeconfig的认证方式进行登录。

  1. 设置集群信息:

     kubectl config set-cluster kubernetes --certificate-authority=/etc/kubernetes/pki/ca.crt --server="https://172.16.0.246:30160" --embed-certs=true --kubeconfig=/root/def-ns-admin.conf
    
    kubectl config view --kubeconfig=/root/def-ns-admin.conf
  2. 设置用户信息:

    kubectl get secret def-ns-admin-token-7jfxq -o jsonpath={.data.token} | base64 -d
    
    DEF_NS_ADMIN_TOKEN=$( kubectl get secret def-ns-admin-token-7jfxq -o jsonpath={.data.token} | base64 -d)
    
    kubectl config set-credentials def-ns-admin --token=$DEF_NS_ADMIN_TOKEN --kubeconfig=/root/def-ns-admin.conf
    
    kubectl config view --kubeconfig=/root/def-ns-admin.conf
  3. 设置context:

    kubectl config set-context def-ns-admin@kubernetes --cluster=kubernetes --user=def-ns-admin --kubeconfig=/root/def-ns-admin.conf
    
    kubectl config view --kubeconfig=/root/def-ns-admin.conf
  4. 设置当前认证时使用context

    kubectl config use-context def-ns-admin@kubernetes --kubeconfig=/root/def-ns-admin.conf
    
    kubectl config view --kubeconfig=/root/def-ns-admin.conf
  5. 将之前生成的config复制到远程客户端

     scp [email protected]:/root/def-ns-admin.conf ./
  6. 在运行客户端访问dashboard,使用刚才生成的kubeconfig文件进行论证登录

 

猜你喜欢

转载自blog.csdn.net/isaiah282485068/article/details/85545260