美文网首页kubernetes
k8s 安装访问dashboard

k8s 安装访问dashboard

作者: 陈sir的知识图谱 | 来源:发表于2019-06-27 16:27 被阅读0次

    安装 dashbaord

    microk8s.enable dns
    microk8s.enable dashboard
    microk8s.enable ingress
    microk8s.enable rbac
    

    验证

    microk8s.status
    
    image.png

    配置访问

    第一步 生成证书,并使用证书创建 K8S secret

    gencert.sh 内容如下

    # 生成证书
    openssl req -x509 -nodes -days 3650 -newkey rsa:2048 -keyout dashboard.com.key -out dashboard.com.pem -subj "/CN=dashboard.com"
    # 生成secret 注意 命名空间需要和dashboard 所在空间一致
    kubectl create secret tls dashboard-secret --namespace=kube-system --cert dashboard.com.pem --key dashboard.com.key
    # 192.168.10.5 是外网可以访问ingress 边缘node的地址,添加这个记录仅仅是为了curl 测试
    sudo echo "192.168.10.5 dashboard.com" >> /etc/hosts
    echo " please use curl -I -k https//dashboard.com  to test access "
    echo " use kubectl -n kube-system describe secret \$(kubectl -n kube-system get secret | grep admin-user | awk '{print $1}') to get login token"
    

    运行完成后,会生成 dashboard.com.key 与 dashboard.com.pem 文件

    生成 dashboard-admin 账户 以及授权其为cluster-admin

    dashboard-admin.yaml文件内容如下

    apiVersion: v1
    kind: ServiceAccount
    metadata:
      name: admin-user
      namespace: kube-system
    
    
    ---
    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: kube-system
    

    创建账户

    kubectl apply -f dashboard-admin.yaml
    

    创建dashboard ingress 描述文件

    dashboard-ingress.yml 内容如下

    apiVersion: extensions/v1beta1
    kind: Ingress
    metadata:
      name: kubernetes-dashboard
      namespace: kube-system
      annotations:
        ingress.kubernetes.io/ssl-passthrough: "true"
        nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"
    spec:
      tls:
      - hosts:
        - dashboard.com
        secretName: dashboard-secret
      rules:
      - host: "dashboard.com"
        http:
          paths:
          - path: /
            backend:
              serviceName: kubernetes-dashboard
              servicePort: 443
    

    创建 dashboard ingress

    kubectl apply -f dashboard-ingress.yml
    

    浏览器验证

    windows 和linux 都改host 文件添加
    192.168.10.5 dashboard.com
    浏览器访问 https://dashboard.com

    登录

    获取token

    kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep admin-user | awk '{print $1}')
    
    image.png

    在浏览器中选择token 登录,然后填上刚刚得到的token 就可以看到dashboard了

    image.png

    相关文章

      网友评论

        本文标题:k8s 安装访问dashboard

        本文链接:https://www.haomeiwen.com/subject/bqprcctx.html