当前位置: 首页>后端>正文

Ubuntu下的k8s使用dashboard(ingress-nginx模式访问)

k8s的dashboard效果如下图:
Ubuntu下的k8s使用dashboard(ingress-nginx模式访问),第1张

如果还没有安装ingress-nginx,可以参考文章:

https://www.jianshu.com/p/4aafb121aac8

1.参考官网(可以将文件下载下来,然后再执行kubectl appley命令)

kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.7.0/aio/deploy/recommended.yaml

2.创建自签证书,并创建tls类型Secrets

openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout kube-dashboard.key -out kube-dashboard.crt -subj "/CN=dashboard.kube.com/O=k8s.dashboard.local"
kubectl create secret tls dashboard-tls --key kube-dashboard.key --cert kube-dashboard.crt -n kubernetes-dashboard

3.创建ingress-dashboard.yaml 文件,并且运行

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: dashboard-ingress
  namespace: kubernetes-dashboard
  annotations:
    nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"
spec:
  ingressClassName: "nginx"
  tls:
  - hosts:    
    - k8s.dashboard.local
    secretName: dashboard-tls
  rules:
  - host: k8s.dashboard.local   
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:   
          service:
            name: kubernetes-dashboard
            port:
              number: 443
# kubectl apply -f ingress-dashboard.yaml 
ingress.networking.k8s.io/dashboard-ingress created

4.配置host(这个IP可以通过名称为"ingress-nginx-controller-xxxx"的pod得到)

192.168.10.7 k8s.dashboard.local

5.创建用户和生成token

创建访问账号,准备一个yaml文件; vim account.yaml

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 create token admin-user -n kubernetes-dashboard

最终token会生成:

eyJhbGciOiJSUzI1NiIsImtpZCI6IkhpYktIcVZIVDE5SEI5SzBYUmM2eTRzVWF4VlhKVVk5R3BBMm9GU0dydUEifQ.eyJhdWQiOlsiaHR0cHM6Ly9rdWJlcm5ldGVzLmRlZmF1bHQuc3ZjLmNsdXN0ZXIubG9jYWwiXSwiZXhwIjoxNjk4NjQ3MTA1LCJpYXQiOjE2OTg2NDM1MDUsImlzcyI6Imh0dHBzOi8va3ViZXJuZXRlcy5kZWZhdWx0LnN2Yy5jbHVzdGVyLmxvY2FsIiwia3ViZXJuZXRlcy5pbyI6eyJuYW1lc3BhY2UiOiJrdWJlcm5ldGVzLWRhc2hib2FyZCIsInNlcnZpY2VhY2NvdW50Ijp7Im5hbWUiOiJhZG1pbi11c2VyIiwidWlkIjoiMGY1ZDAyNTctNjJkOC00YTU1LTlkMGUtZGY1NGNlMTRiZjZjIn19LCJuYmYiOjE2OTg2NDM1MDUsInN1YiI6InN5c3RlbTpzZXJ2aWNlYWNjb3VudDprdWJlcm5ldGVzLWRhc2hib2FyZDphZG1pbi11c2VyIn0.Rjdc82g4CSfpfPb3_Ne__RnbO7EB3CM1EaQBcGQtZxQqAWGAdFX86HIKlnOkoM_DgvDhet6w_WaGAD3XTrIvcX7vAvbmtHqQ1wktRNmdYz-zv0vuIQBdsKF-Sc7tW3_U_vdH42Zr5UPCe9k2FWTyiq8h3n1_yJrvSYilt4SeDe2_cSwcMHNnrJoko-l5o3qqB9ANyRla-GPFZR2HrGaRDtRxLTlfYIvITr0o6NBYRWd147DxBZr0tmXWY7Oag-6sjCu2bg_4O13vcifmEXCcXWTLWkg6i9dbo9nUjRothNOuPGZ40MGUpuT8yWqpo7MH9HAY3zWD6iTWLc9BCMGtMw

https://www.xamrdz.com/backend/3py1944820.html

相关文章: