【问题标题】:Openshift Admin TokenOpenshift 管理员令牌
【发布时间】:2018-09-14 23:22:07
【问题描述】:

我正在尝试创建一个每 15 分钟记录一次项目资源的脚本。如何使用 Openshift API 进行身份验证?是否有我可以使用的对所有命名空间具有读取权限的令牌?如何创建可以访问所有命名空间的服务帐号?

【问题讨论】:

    标签: kubernetes openshift openshift-enterprise


    【解决方案1】:

    您需要创建一个对资源具有读取权限的 ClusterRole,并使用 ClusterRoleBinding 将 ServiceAccount 关联到该 ClusterRole。粗略的示例,未经测试,但应该可以工作:

    # creates the service account "ns-reader"
    apiVersion: v1
    kind: ServiceAccount
    metadata:
      name: ns-reader
      namespace: default
    
    ---
    kind: ClusterRole
    apiVersion: rbac.authorization.k8s.io/v1
    metadata:
      # "namespace" omitted since ClusterRoles are not namespaced
      name: global-reader
    rules:
    - apiGroups: [""]
      # add other rescources you wish to read
      resources: ["pods", "secrets"] 
      verbs: ["get", "watch", "list"]
    
    ---
    # This cluster role binding allows service account "ns-reader" to read pods in all available namespace
    kind: ClusterRoleBinding
    apiVersion: rbac.authorization.k8s.io/v1
    metadata:
      name: read-ns
    subjects:
    - kind: ServiceAccount
      name: ns-reader
      namespace: default
    roleRef:
      kind: ClusterRole
      name: global-reader
      apiGroup: rbac.authorization.k8s.io
    

    设置 ServiceAccount 时,会自动创建一些与其关联的机密。其中一些秘密持有一个令牌,然后可以在直接使用 REST API 或使用 oc 时使用。在 ServiceAccount 上使用 oc describe 以查看令牌的 Secret 名称。然后在其中一个 Secrets 上使用 oc describe 以查看令牌。

    【讨论】:

      猜你喜欢
      • 2020-05-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-05
      • 2021-09-28
      • 2021-01-24
      • 2022-06-14
      • 1970-01-01
      相关资源
      最近更新 更多