`
m635674608
  • 浏览: 5004470 次
  • 性别: Icon_minigender_1
  • 来自: 南京
社区版块
存档分类
最新评论

k8s dashboard 认证配置

 
阅读更多

Authentication to the Kubernetes API Server

A number of components are involved in the authentication process and the first step is to narrow down the source of the problem, namely whether it is a problem with user authentication or with service authentication. Both authentications must work:

+-------------+   user             +-------------+   service          +-------------+
|             |   authentication   |             |   authentication   |             |
|  browser    +------------------->+  apiserver  +<-------------------+  dashboard  |
|             |                    |             |                    |             |
+-------------+                    +-------------+                    +-------------+

User authentication

From your workstation you can connect to Dashboard in three different ways:

  1. Authentication through kubectl: This is recommended, because it is secure and easy. In your desktop environment (e.g. laptop) verify that kubectl is configured properly with kubectl cluster-info. If you get a response then you can continue. Enter the command kubectl proxy. kubectl will relay the user's credentials to apiserver for authentication and proxy every API request to a local server. This server is unprotected, but this is not a problem as it is only accessible from within the workstation. Now access Dashboard with http://localhost:8001/ui. If it fails then your problem is located with service authentication (see next section).

  2. Direct access to apiserver: Open a browser with the URL https://<master>/. A login dialog should pop up. If it does not, then username & password authentication is not configured for the apiserver. See documentation if you want to configure it manually. Next, access Dashboard with https://<master>/ui. If it fails then your problem is located with service authentication (see next section).

  3. Bypass apiserver: If you are working in a trusted environment then you may access Dashboard without authentication. Expose Dashboard service via NodePort. See user guide for details.

Service authentication

Dashboard needs information from apiserver. Therefore, authentication is required, which can be achieved in two different ways:

  1. Service Account: This is recommended, because nothing has to be configured. Dashboard will use information provided by the system to communicate with the API server. See 'Service Account' section for details.

  2. Kubeconfig file: In some Kubernetes environments service accounts are not available. In this case a manual configuration is required. The Dashboard binary can be started with the --kubeconfig flag. The value of the flag is a path to a file specifying how to connect to the API server. The contents of the file is identical to ~/.kube/config which is used by kubectl to connect to the API server. See 'kubeconfig' section for details.

In the diagram below you can see the full authentication flow with all options, starting with the browser on the lower left hand side.


Workstation                                        Kubernetes
+------------------+                               +----------------------------------------------------+
|                  |                               |                                                    |
|                  |                               |                                                    |
|  +------------+  |                               |  +------------+   apiserver        +------------+  |
|  |            |  |  authentication with kubectl  |  |            |   proxy            |            |  |
|  | kubectl    +------------------------------------>+ apiserver  +------------------->+ dashboard  |  |
|  | proxy      |  |                               |  |            |                    |            |  |
|  |            |  |                               |  |            |                    |            |  |
|  +--------+---+  |                               |  |            |                    |            |  |
|           ^      |                          +------>+            |  service account/  |            |  |
|  localhost|      |                          |    |  |            |  kubeconfig        |            |  |
|           |      |                          |    |  |            +<-------------------+            |  |
|  +--------+---+  |                          |    |  |            |                    |            |  |
|  |            |  |      direct access       |    |  +------------+                    +------+-----+  |
|  | browser    +-----------------------------+    |                                           |        |
|  |            |  |                               |                                           |        |
|  |            +----------------------------------------------------------------------------->O        |
|  +------------+  |      bypass apiserver         |                                        NodePort    |
|                  |                               |                                                    |
|                  |                               |                                                    |
+------------------+                               +----------------------------------------------------+

Service Account

If using a service account to connect to the API server, Dashboard expects the file/var/run/secrets/kubernetes.io/serviceaccount/token to be present. It provides a secret token that is required to authenticate with the API server.

Verify with the following commands:

# start a container that contains curl
$ kubectl run test --image=tutum/curl -- sleep 10000

# check that container is running
$ kubectl get pods
NAME                   READY     STATUS    RESTARTS   AGE
test-701078429-s5kca   1/1       Running   0          16s

# check if secret exists
$ kubectl exec test-701078429-s5kca ls /var/run/secrets/kubernetes.io/serviceaccount/
ca.crt
namespace
token

# get service IP of master
$ kubectl get services
NAME         CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
kubernetes   10.0.0.1     <none>        443/TCP   1d

# check base connectivity from cluster inside
$ kubectl exec test-701078429-s5kca -- curl -k https://10.0.0.1
Unauthorized

# connect using tokens
$ TOKEN_VALUE=$(kubectl exec test-701078429-s5kca -- cat /var/run/secrets/kubernetes.io/serviceaccount/token)
$ echo $TOKEN_VALUE
eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3Mi....9A
$ kubectl exec test-701078429-s5kca -- curl --cacert /var/run/secrets/kubernetes.io/serviceaccount/ca.crt -H  "Authorization: Bearer $TOKEN_VALUE" https://10.0.0.1
{
  "paths": [
    "/api",
    "/api/v1",
    "/apis",
    "/apis/apps",
    "/apis/apps/v1alpha1",
    "/apis/authentication.k8s.io",
    "/apis/authentication.k8s.io/v1beta1",
    "/apis/authorization.k8s.io",
    "/apis/authorization.k8s.io/v1beta1",
    "/apis/autoscaling",
    "/apis/autoscaling/v1",
    "/apis/batch",
    "/apis/batch/v1",
    "/apis/batch/v2alpha1",
    "/apis/certificates.k8s.io",
    "/apis/certificates.k8s.io/v1alpha1",
    "/apis/extensions",
    "/apis/extensions/v1beta1",
    "/apis/policy",
    "/apis/policy/v1alpha1",
    "/apis/rbac.authorization.k8s.io",
    "/apis/rbac.authorization.k8s.io/v1alpha1",
    "/apis/storage.k8s.io",
    "/apis/storage.k8s.io/v1beta1",
    "/healthz",
    "/healthz/ping",
    "/logs",
    "/metrics",
    "/swaggerapi/",
    "/ui/",
    "/version"
  ]
}

If it is not working, there are two possible reasons:

  1. The contents of the tokens is invalid. Find the secret name with kubectl get secrets | grep service-account and delete it with kubectl delete secret <name>. It will automatically be recreated.

  2. You have a non-standard Kubernetes installation and the file containing the token may not be present. The API server will mount a volume containing this file, but only if the API server is configured to use the ServiceAccount admission controller. If you experience this error, verify that your API server is using the ServiceAccount admission controller. If you are configuring the API server by hand, you can set this with the --admission-control parameter. Please note that you should use other admission controllers as well. Before configuring this option, you should read about admission controllers.

More information:

kubeconfig

If you want to use a kubeconfig file for authentication, create a deployment file similar to the one below:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  labels:
    app: kubernetes-dashboard
  name: kubernetes-dashboard
  namespace: kube-system
spec:
  replicas: 1
  selector:
    matchLabels:
      app: kubernetes-dashboard
  template:
    metadata:
      labels:
        app: kubernetes-dashboard
    spec:
      containers:
      - name: kubernetes-dashboard
        image: gcr.io/google_containers/kubernetes-dashboard-amd64:v1.x.x
        imagePullPolicy: Always
        ports:
        - containerPort: 9090
          protocol: TCP
        volumeMounts:
        - name: "kubeconfig"
          mountPath: "/etc/kubernetes/"
          readOnly: true
        args:
          - --kubeconfig=/etc/kubernetes/kubeconfig.yaml
        livenessProbe:
          httpGet:
            path: /
            port: 9090
          initialDelaySeconds: 30
          timeoutSeconds: 30
      volumes:
      - name: "kubeconfig"
        hostPath:
          path: "/etc/kubernetes/"
---
kind: Service
apiVersion: v1
metadata:
  labels:
    app: kubernetes-dashboard
  name: kubernetes-dashboard
  namespace: kube-system
spec:
  type: NodePort
  ports:
  - port: 80
    targetPort: 9090
  selector:
    app: kubernetes-dashboar


 

 

 

https://github.com/kubernetes/dashboard/blob/master/docs/user-guide/troubleshooting.md


分享到:
评论

相关推荐

    k8s kubernetes dashboard dns 配置文件 yaml

    在Kubernetes(k8s)集群环境中,配置和管理各个组件是系统运维的关键部分。这里我们聚焦于Kubernetes Dashboard、DNS服务以及相关的YAML配置文件。YAML是一种常用的语言,用于编写Kubernetes的资源定义,它简洁且...

    5-k8s部署之Dashboard1

    - 删除 Dashboard:如果不再需要 Dashboard,可以使用 `kubectl delete ns kubernetes-dashboard` 删除整个命名空间,或者使用 `kubectl delete -f kubernetes-dashboard.yaml` 删除特定的配置。 5. **安全性与...

    k8s-dashboardv2.0.3.zip

    `k8s-dashboard-deploy.yaml` 文件是用于部署 Kubernetes Dashboard 的配置文件。在这个文件中,包含了 Dashboard 服务的定义,包括使用的镜像、端口映射、服务类型(如 ClusterIP 或 NodePort)以及任何必要的环境...

    使用prometheus监控k8s的grafana模板

    通过配置Exporters(如kube-state-metrics),可以暴露k8s内部状态的指标,使得Prometheus能够收集这些数据。 二、Grafana模板介绍 Grafana模板是一种预定义的可视化配置,它包含了一系列的图表、面板和仪表板布局...

    K8s集群部署配置文件包

    本压缩包“K8s集群部署配置文件包”提供了全面的资源,帮助用户快速构建并配置Kubernetes集群。以下将详细阐述其中涉及的关键知识点。 首先,ETCD是Kubernetes集群的核心组件,它是轻量级、分布式的键值存储系统,...

    k8s dashboard

    ### k8s Dashboard 操作手册知识点详解 #### 一、Kubernetes Dashboard 简介 Kubernetes Dashboard 是 Kubernetes 的官方 Web UI,它提供了图形化的界面来管理 Kubernetes 集群中的资源,包括部署、复制集、Pods 等...

    Kubernetes Dashboard 部署.docx

    4. **重新部署 Dashboard**:使用包含新证书的配置文件重新部署 Dashboard。 **快照后的恢复访问**: 1. **重新暴露服务端口**:修改配置文件中的服务类型为 `NodePort`,确保集群外部可以访问 Dashboard。 2. **...

    rancher-k8s

    在使用Rancher-K8s部署Kubernetes集群的过程中,可能会遇到一些常见的问题,例如部署后的Kubernetes环境无法正常访问dashboard,或是在基础架构中找不到相关的容器。这些问题通常是由于Kubernetes依赖的一些组件(如...

    k8s培训视频.zip

    目录网盘文件永久链接 01-Devops核心要点及kubernetes架构概述 02-kubernetes基础概念 ...17-kubernetes dashboard认证及分级授权 18-配置网络插件flannel 19-基于canel的网络策略 20-调度器、预选策略及优选函数 ...

    k8s-1.12.3.rar

    9. **自定义用户界面**:"k8s页面" 可能是一个自定义的 Kubernetes Dashboard 或其他监控工具,用于可视化集群状态和管理资源。 10. **故障排查**:可能包括一些常见问题的解决方案和调试脚本,帮助用户解决集群...

    k8s安装部署.zip

    5. **安装Dashboard和基本组件**:k8s Dashboard提供图形化界面,便于管理和监控集群状态。 6. **设置权限和认证**:配置RBAC(Role-Based Access Control),确保安全的访问控制。 接下来,我们来看“项目说明.pdf...

    Kubernetes (k8s) 课件三.docx

    * Ingress 服务:是 Kubernetes 集群外部请求的入口,即外部请求进入 k8s 集群必经之口,可以根据需求配置 Ingress 对象来暴露服务。 五、其他知识点 * kubectl 命令行工具:可以使用 kubectl 命令行工具管理 ...

    CentOS 7.5 安装 K8S v1.11.0 集群

    在正式安装 K8S 之前,需要做一些准备工作,包括安装 Docker-CE 和 Kubeadm,并进行必要的系统配置。 ##### 1.1 安装 Docker-CE Docker-CE 是 Kubernetes 运行容器的基础,必须首先确保 Docker-CE 已正确安装。...

    k8s-v1.8.13安装学习记录

    ### k8s-v1.8.13安装学习记录 #### 一、集群环境与组件概览 在本文档中,我们将深入探讨如何构建并安装Kubernetes 1.8.13版本的集群,以及所需的辅助组件和服务。该文档不仅记录了安装过程中的关键步骤,还介绍了...

    dashboard.zip

    "dashboard.zip" 文件是一个与 Kubernetes(简称 k8s)相关的压缩包,很可能包含了 Kubernetes Dashboard 的部署资源或相关配置。Kubernetes Dashboard 是一个图形用户界面(GUI),它允许用户通过直观的交互方式...

    如何配置kubernetes-dashboard.zip

    apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: dashboard-admin subjects: - kind: ServiceAccount name: kubernetes-dashboard namespace: kube-system roleRef: kind: ...

    k8s-v.1.14.2搭建和操作(安装-web-监控-完成)-kubernetes的kubeadmin高可用包和详细文档笔记

    6. **Web界面**:Kubernetes Dashboard是k8s的图形化管理界面,用于监控和管理集群资源。安装Dashboard后,可以通过Web访问来查看和操作Pod、Service、Deployment等对象。 7. **监控与日志**:监控是运维的关键部分...

    k8s+prometheus+grafana.zip

    在容器化领域,Kubernetes(简称k8s)已经成为管理和部署微服务应用的标准平台,而Prometheus和Grafana则是广泛使用的监控解决方案。这个“k8s+prometheus+grafana.zip”压缩包包含了实现Kubernetes集群监控所需的...

    kubernetes-dashboard-amd64.tgz

    标签 "K8S" 是 Kubernetes 的常见缩写,它是一个开源容器编排系统,用于自动化容器化应用程序的部署、扩展和管理。Kubernetes 提供了一个平台,使得开发者和操作员能够轻松地在云或本地环境中管理容器化的应用程序。...

    Kuernetes dashboard 2.0.4

    6. **安全性**:Kubernetes Dashboard 在2.0.4版本中可能会加强安全措施,例如使用 TLS 加密通信,限制默认访问权限,并支持通过服务帐户进行认证。 7. **可扩展性**:作为一款现代化的管理工具,Kubernetes ...

Global site tag (gtag.js) - Google Analytics