【问题标题】:.kube/config how to make it available to a rest service deployed in kubernetes.kube/config 如何使其可用于部署在 kubernetes 中的休息服务
【发布时间】:2018-05-07 03:22:37
【问题描述】:

在部署在 kubernetes 上的 rest 服务中提供 .kube/config 文件的最佳方法是什么?

这将使我的服务能够(例如)使用 kuberntes 客户端 api。

R

【问题讨论】:

    标签: kubernetes


    【解决方案1】:

    创建服务帐号:

    kubectl create serviceaccount example-sa
    

    创建角色:

    kind: Role
    apiVersion: rbac.authorization.k8s.io/v1
    metadata:
      namespace: default
      name: example-role
    rules:
    - apiGroups: [""] # "" indicates the core API group
      resources: ["pods"]
      verbs: ["get", "watch", "list"]
    

    创建角色绑定:

    kind: RoleBinding
    apiVersion: rbac.authorization.k8s.io/v1alpha1
    metadata:
      name: example-role-binding
      namespace: default
    subjects:
      - kind: "ServiceAccount"
        name: example-sa
    roleRef:
      kind: Role
      name: example-role
      apiGroup: rbac.authorization.k8s.io
    

    使用example-sa创建 pod

    kind: Pod
    apiVersion: v1
    metadata:
     name: example-pod
    spec:
     serviceAccountName: example-sa
     containers:
     - name: secret-access-container
       image: example-image
    

    pod 定义中最重要的一行是serviceAccountName: example-sa。创建服务帐户并将此行添加到您的 pod 定义后,您将能够在 /var/run/secrets/kubernetes.io/serviceaccount/token 访问您的 api 访问令牌。

    Here你可以找到上面例子的更详细的版本。

    【讨论】:

      猜你喜欢
      • 2021-01-13
      • 1970-01-01
      • 2023-02-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-08
      • 2020-02-15
      • 2022-01-04
      相关资源
      最近更新 更多