3.2. 创建缓存服务节点


默认情况下,Data Grid Operator 使用缓存服务节点创建 Data Grid 集群。

流程

  1. 创建 Infinispan CR。

    apiVersion: infinispan.org/v1
    kind: Infinispan
    metadata:
      name: example-infinispan
    spec:
      replicas: 2
      service:
        type: Cache 
    1
    Copy to Clipboard Toggle word wrap
    1
    创建节点缓存服务节点。这是 Infinispan CR 的默认设置。
  2. 应用 Infinispan CR 以创建集群。

3.2.1. 配置自动扩展

如果您使用缓存服务节点创建集群,Data Grid Operator 可以根据默认缓存的内存用量自动扩展或缩减节点。

Data Grid Operator 监控缓存服务节点上的默认缓存。当您向缓存中添加数据时,内存用量会增加。当检测到集群需要额外的容量时,Data Grid Operator 会创建新节点而不是撤离条目。同样,如果它检测到内存用量低于特定阈值,则 Data Grid Operator 会关闭节点。

重要

自动扩展仅适用于默认缓存。如果您计划在集群中添加其他缓存,则不应在 Infinispan CR 中包含 autoscale 字段。在这种情况下,您应该使用驱除来控制每个节点上的数据容器的大小。

流程

  1. spec.autoscale 资源添加到 Infinispan CR 中,以启用自动扩展。
  2. 使用 autoscale 字段为集群配置内存用量阈值和节点数。

    spec:
      ...
      service:
        type: Cache
      autoscale:
        maxMemUsagePercent: 70 
    1
    
        maxReplicas: 5 
    2
    
        minMemUsagePercent: 30 
    3
    
        minReplicas: 2 
    4
    Copy to Clipboard Toggle word wrap
    1
    配置每个节点上的内存用量的最大阈值(百分比)。当 Data Grid Operator 检测到集群中的任何节点都达到阈值时,它会创建一个新节点(如果可能)。如果 Data Grid Operator 无法创建新节点,则它在内存用量达到 100% 时执行驱除。
    2
    定义集群的最大节点数。
    3
    将最小阈值(百分比)配置为集群中内存用量。当 Data Grid Operator 检测到内存用量低于最小值时,它会关闭节点。
    4
    定义集群的最小节点数。
  3. 应用更改。

3.2.2. 配置所有者数

所有者数量控制每个缓存条目在 Data Grid 集群中复制多少个副本。Cache 服务节点的默认值为两个,它会复制每个条目以防止数据丢失。

流程

  1. Infinispan CR 中使用 spec.service.replicationFactor 资源指定所有者数量,如下所示:

    spec:
      ...
      service:
        type: Cache
        replicationFactor: 3 
    1
    Copy to Clipboard Toggle word wrap
    1
    为每个缓存条目配置三个副本。
  2. 应用更改。

3.2.3. 缓存服务资源

apiVersion: infinispan.org/v1
kind: Infinispan
metadata:
  # Names the cluster.
  name: example-infinispan
spec:
  # Specifies the number of nodes in the cluster.
  replicas: 4
  service:
    # Configures the service type as Cache.
    type: Cache
    # Sets the number of replicas for each entry across the cluster.
    replicationFactor: 2
  # Enables and configures automatic scaling.
  autoscale:
    maxMemUsagePercent: 70
    maxReplicas: 5
    minMemUsagePercent: 30
    minReplicas: 2
  # Configures authentication and encryption.
  security:
    # Defines a secret with custom credentials.
    endpointSecretName: endpoint-identities
    # Adds a custom TLS certificate to encrypt client connections.
    endpointEncryption:
        type: Secret
        certSecretName: tls-secret
  # Sets container resources.
  container:
    extraJvmOpts: "-XX:NativeMemoryTracking=summary"
    cpu: "2000m"
    memory: 1Gi
  # Configures logging levels.
  logging:
    categories:
      org.infinispan: trace
      org.jgroups: trace
  # Configures how the cluster is exposed on the network.
  expose:
    type: LoadBalancer
  affinity:
    podAntiAffinity:
      preferredDuringSchedulingIgnoredDuringExecution:
      - weight: 100
        podAffinityTerm:
          labelSelector:
            matchLabels:
              app: infinispan-pod
              clusterName: example-infinispan
              infinispan_cr: example-infinispan
          topologyKey: "kubernetes.io/hostname"
Copy to Clipboard Toggle word wrap
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2026 Red Hat
返回顶部