【问题标题】:How to setMasterUrl in Ignite XML config for Kubernetes IPFinder如何在 Ignite XML 配置中为 Kubernetes IP Finder 设置 Master Url
【发布时间】:2018-08-29 22:22:41
【问题描述】:

在 Ignite 2.4 和 k8s 1.9 中使用测试配置:

<?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:util="http://www.springframework.org/schema/util"
           xsi:schemaLocation="
            http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans.xsd
            http://www.springframework.org/schema/util
            http://www.springframework.org/schema/util/spring-util.xsd">

    <bean class="org.apache.ignite.configuration.IgniteConfiguration">
      <property name="discoverySpi">
        <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
          <property name="ipFinder">
            <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.kubernetes.TcpDiscoveryKubernetesIpFinder"/>
          </property>
        </bean>
      </property>
    </bean>
</beans>

无法在https://kubernetes.default.svc.cluster.local:443 找到 Kubernetes API 服务器 我可以在 XML 配置文件中设置 API Server URL 吗?怎么样?

【问题讨论】:

标签: kubernetes ignite


【解决方案1】:

@Denis 是对的。

Kubernetes 使用 RBAC 访问控制系统,您需要授权您的 pod 访问 API。

为此,您需要将 Service Account 添加到您的 pod。

所以,你需要这样做:

  1. 创建一个服务帐号并为其设置角色:

    apiVersion: v1
    kind: ServiceAccount
    metadata:
      name: ignite
      namespace: <Your namespace>
    
  2. 我不确定仅访问 pod 的权限对于 Ignite 是否足够,但如果不是 - 您可以根据需要添加更多权限。 Here 是具有大量权限的不同类型角色的示例。所以,现在我们为您的应用创建集群角色:

    apiVersion: rbac.authorization.k8s.io/v1beta1
    kind: ClusterRole
    metadata:
      name: ignite
      namespace: <Your namespace>
    rules:
    - apiGroups:
      - ""
      resources:
      - pods # Here is resources you can access
      verbs: # That is what you can do with them
      - get
      - list
      - watch
    
  3. 为该角色创建绑定:

    kind: ClusterRoleBinding
    apiVersion: rbac.authorization.k8s.io/v1beta1
    metadata:
      name: ignite
    roleRef:
      kind: ClusterRole
      name: ignite
      apiGroup: rbac.authorization.k8s.io
    subjects:
    - kind: ServiceAccount
      name: ignite
      namespace: <Your namespace>
    
  4. 现在,您需要将 ServiceAccount 与您的应用程序关联到 pod:

    apiVersion: extensions/v1beta1
    kind: DaemonSet
    metadata:
      ....
    spec:
      template:
        spec:
          serviceAccountName: ignite
    

之后,您的应用程序将可以访问 K8s API。附言不要忘记将 &lt;Your namespace&gt; 更改为运行 Ignition 的命名空间。

【讨论】:

  • 当我尝试运行第 4 步 kubectl create -f daemon.yaml 时,出现以下错误。 error: error validating "daemon.yaml": error validating data: ValidationError(DaemonSet.spec.template.spec): missing required field "containers" in io.k8s.api.core.v1.PodSpec; if you choose to ignore these errors, turn validation off with --validate=false
【解决方案2】:

平台版本

  • Kubernetes:v1.8
  • 点燃:v2.4

@Anton Kostenko 的设计基本上是正确的,但这里有一个精致的建议,它可以为 Ignite 授予最少访问权限

  1. 如果您使用 Deployment 来管理 Ignite,那么您的所有 Pod 都将在单个命名空间中启动。因此,您确实应该使用 RoleRoleBinding 来授予对与您的部署关联的服务帐户的 API 访问权限。

  2. TcpDiscoveryKubernetesIpFinder 只需要访问用于选择 Ignite pod 的无头服务的端点。以下 2 个清单将授予该访问权限。

    apiVersion: rbac.authorization.k8s.io/v1
    kind: Role
    metadata:
      name: ignite-endpoint-access
      namespace: <your-ns>
      labels:
        app: ignite
    rules:
      - apiGroups: [""]
        resources: ["endpoints"]
        resourceNames: ["<your-headless-svc>"]
        verbs: ["get"]
    
    ---
    apiVersion: rbac.authorization.k8s.io/v1
    kind: RoleBinding
    metadata:
      name: ignite-role-binding
      labels:
        app: ignite
    subjects:
      - kind: ServiceAccount
        name: <your-svc-account>
    roleRef:
      kind: Role
      name: ignite-endpoint-access
      apiGroup: rbac.authorization.k8s.io
    

【讨论】:

    【解决方案3】:

    看看这个帖子:http://apache-ignite-users.70518.x6.nabble.com/Unable-to-connect-ignite-pods-in-Kubernetes-using-Ip-finder-td18009.html

    403错误的问题可以通过给服务账号授予更多权限来解决。

    【讨论】:

    • 谢谢。此链接导致正确答案。在使用 clusterrole=admin fir 服务帐户创建 RoleBinding 后,我能够找到 Ignite 节点:kubectl create rolebinding igniteRoleBinding \ --clusterrole=admin \ --serviceaccount=default:ignite \ --namespace=default
    • 仍然不确定为什么需要 admin,但是对于 RBAC 和 k8s 中的权限是新的,所以我会进一步研究。
    【解决方案4】:

    测试版:

    Kubernetes:v1.8

    点燃:v2.4

    这会稍微宽松一点。

    apiVersion: rbac.authorization.k8s.io/v1beta1
    kind: ClusterRoleBinding
    metadata:
      name: ignite-rbac
    subjects:
      - kind: ServiceAccount
        name: default
        namespace: <namespace>
    roleRef:
      kind: ClusterRole
      name: cluster-admin
      apiGroup: rbac.authorization.k8s.io
    

    【讨论】:

      【解决方案5】:

      如果您获得 403 未经授权,则您的服务帐户可能没有足够的权限来获取您的资源。在确保命名空间和服务帐户以及部署/副本集完全符合您的要求后,您应该更新您的权限。

      此链接对于设置服务帐户的权限非常有帮助: https://kubernetes.io/docs/reference/access-authn-authz/rbac/#service-account-permissions

      【讨论】:

        猜你喜欢
        • 2018-04-22
        • 1970-01-01
        • 2019-03-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-06-22
        • 2018-10-18
        • 2018-03-03
        相关资源
        最近更新 更多