跳转至

使用 NebulaGraph Operator 安装 NebulaGraph 集群

采用 NebulaGraph Operator 安装 NebulaGraph 集群,能够实现集群管理的自动化,同时具备自动错误恢复的功能。本文介绍kubectl applyhelm两种方式来使用 NebulaGraph Operator 安装 NebulaGraph 集群。

历史版本兼容性

1.x 版本的 NebulaGraph Operator 不兼容 3.x 以下版本的 NebulaGraph 。

前提条件

使用kubectl apply

  1. 创建命名空间,用于存放 NebulaGraph 集群相关资源。例如,创建nebula命名空间。

    kubectl create namespace nebula
    
  2. 创建集群的 YAML 配置文件nebulacluster.yaml。例如,创建名为nebula的集群。

    展开查看nebula集群的示例配置
    apiVersion: apps.nebula-graph.io/v1alpha1
    kind: NebulaCluster
    metadata:
      name: nebula
      namespace: default
    spec:
      # 控制 Pod 的调度策略。
      topologySpreadConstraints:
      - topologyKey: "kubernetes.io/hostname"
        whenUnsatisfiable: "ScheduleAnyway"
      # 是否回收 PV。
      enablePVReclaim: false
      # 是否启用备份和恢复功能。
      exporter:
        image: vesoft/nebula-stats-exporter
        version: v3.3.0
        replicas: 1
        maxRequests: 20
      # 自定义 Agent 镜像,用于集群备份和恢复及日志清理。
      agent:
        image: vesoft/nebula-agent
        version: latest
        resources:
          requests:
            cpu: "100m"
            memory: "128Mi"
          limits:
            cpu: "200m"
            memory: "256Mi"  
      # 配置镜像拉取策略。
      imagePullPolicy: Always
      # 选择 Pod 被调度的节点。
      nodeSelector:
        nebula: cloud
      # 依赖的控制器名称。
      reference:
        name: statefulsets.apps
        version: v1
      # 调度器名称。
      schedulerName: default-scheduler   
      # 启动 NebulaGraph Console 服务,用于连接 Graph 服务。
      console:
        image: vesoft/nebula-console
        version: nightly
        username: "demo"
        password: "test"                 
      # Graph 服务的相关配置。 
      graphd:
      # 用于检测 Graph 服务是否正常运行。
      #  readinessProbe:
      #    failureThreshold: 3
      #    httpGet:
      #      path: /status
      #      port: 19669
      #      scheme: HTTP
      #    initialDelaySeconds: 40
      #    periodSeconds: 10
      #    successThreshold: 1
      #    timeoutSeconds: 10
        # Graph 服务的容器镜像。
        image: vesoft/nebula-graphd
        logVolumeClaim:
          resources:
            requests:
              storage: 2Gi
          # 用于存储 Graph 服务的日志的存储类名称。
          storageClassName: local-sc
        # Graph 服务的 Pod 副本数。
        replicas: 1
        # Graph 服务的资源配置。
        resources:
          limits:
            cpu: "1"
            memory: 1Gi
          requests:
            cpu: 500m
            memory: 500Mi
        # Graph 服务的版本。
        version: v3.6.0
        # 自定义 Graph 服务的 flags 配置项。
        config: {}
      # Meta 服务的相关配置。
      metad:
      #  readinessProbe:
      #    failureThreshold: 3
      #    httpGet:
      #      path: /status
      #      port: 19559
      #      scheme: HTTP
      #    initialDelaySeconds: 5
      #    periodSeconds: 5
      #    successThreshold: 1
      #   timeoutSeconds: 5
        # Meta 服务的容器镜像。
        image: vesoft/nebula-metad
        logVolumeClaim:
          resources:
            requests:
              storage: 2Gi
          storageClassName: local-sc
        dataVolumeClaim:
          resources:
            requests:
              storage: 2Gi
          storageClassName: local-sc
        replicas: 1
        resources:
          limits:
            cpu: "1"
            memory: 1Gi
          requests:
            cpu: 500m
            memory: 500Mi
        version: v3.6.0
        # 自定义 Meta 服务的 flags 配置项。
        config: {}          
      # Storage 服务的相关配置。
      storaged:
      #  readinessProbe:
      #    failureThreshold: 3
      #    httpGet:
      #      path: /status
      #      port: 19779
      #      scheme: HTTP
      #    initialDelaySeconds: 40
      #    periodSeconds: 10
      #    successThreshold: 1
      #    timeoutSeconds: 5
        # Storage 服务的容器镜像。
        image: vesoft/nebula-storaged
        logVolumeClaim:
          resources:
            requests:
              storage: 2Gi
          storageClassName: local-sc
        dataVolumeClaims:
        - resources:
            requests:
              storage: 2Gi
          storageClassName: local-sc
        replicas: 1
        resources:
          limits:
            cpu: "1"
            memory: 1Gi
          requests:
            cpu: 500m
            memory: 500Mi
        version: v3.6.0
        # 自定义 Storage 服务的 flags 配置项。
        config: {} 
    
    展开查看集群所有可配置的参数及描述
    参数 默认值 描述
    metadata.name - 创建的NebulaGraph集群名称。
    spec.console - 启动 Console 容器用于连接 Graph 服务。配置详情,参见 nebula-console.
    spec.topologySpreadConstraints - 控制 Pod 的调度策略。详情参见 Topology Spread Constraints。当topologyKey的值为kubernetes.io/zone时,whenUnsatisfiable的值需为DoNotSchedule并且spec.schedulerName的值为nebula-scheduler
    spec.graphd.replicas 1 Graphd 服务的副本数。
    spec.graphd.image vesoft/nebula-graphd Graphd 服务的容器镜像。
    spec.graphd.version v3.6.0 Graphd 服务的版本号。
    spec.graphd.service 访问 Graphd 服务的 Service 配置。
    spec.graphd.logVolumeClaim.storageClassName - Graphd 服务的日志盘存储卷的存储类名称。使用示例配置时需要将其替换为事先创建的存储类名称,参见 Storage Classes 查看创建存储类详情。
    spec.metad.replicas 1 Metad 服务的副本数。
    spec.metad.image vesoft/nebula-metad Metad 服务的容器镜像。
    spec.metad.version v3.6.0 Metad 服务的版本号。
    spec.metad.dataVolumeClaim.storageClassName - Metad 服务的数据盘存储配置。使用示例配置时需要将其替换为事先创建的存储类名称,参见 Storage Classes 查看创建存储类详情。
    spec.metad.logVolumeClaim.storageClassName - Metad 服务的日志盘存储配置。使用示例配置时需要将其替换为事先创建的存储类名称,参见 Storage Classes 查看创建存储类详情。
    spec.storaged.replicas 3 Storaged 服务的副本数。
    spec.storaged.image vesoft/nebula-storaged Storaged 服务的容器镜像。
    spec.storaged.version v3.6.0 Storaged 服务的版本号。
    spec.storaged.dataVolumeClaims.resources.requests.storage - Storaged 服务的数据盘存储大小,可指定多块数据盘存储数据。当指定多块数据盘时,路径为:/usr/local/nebula/data1/usr/local/nebula/data2等。
    spec.storaged.dataVolumeClaims.storageClassName - Storaged 服务的数据盘存储配置。使用示例配置时需要将其替换为事先创建的存储类名称,参见 Storage Classes 查看创建存储类详情。
    spec.storaged.logVolumeClaim.storageClassName - Storaged 服务的日志盘存储配置。使用示例配置时需要将其替换为事先创建的存储类名称,参见 Storage Classes 查看创建存储类详情。
    spec.<metad|storaged|graphd>.securityContext {} 定义集群容器的权限和访问控制,以控制访问和执行容器的操作。详情参见 SecurityContext
    spec.agent {} Agent 服务的配置。用于备份和恢复及日志清理功能,如果不自定义该配置,将使用默认配置。
    spec.reference.name {} 依赖的控制器名称。
    spec.schedulerName default-scheduler 调度器名称。
    spec.imagePullPolicy Always NebulaGraph镜像的拉取策略。关于拉取策略详情,请参考 Image pull policy
    spec.logRotate {} 日志轮转配置。详情参见管理集群日志
    spec.enablePVReclaim false 定义是否在删除集群后自动删除 PVC 以释放数据。详情参见回收 PV
    spec.metad.licenseManagerURL - 配置指向 LM 的 URL,由 LM 的访问地址和端口(默认端口9119)组成。例如,192.168.8.xxx:9119。仅适用于创建企业版NebulaGraph集群。
    spec.storaged.enableAutoBalance false 是否启用自动均衡。详情参见均衡扩容后的 Storage 数据
    spec.enableBR false 定义是否启用 BR 工具。详情参见备份与恢复
    spec.imagePullSecrets [] 定义拉取私有仓库中镜像所需的 Secret。
  3. 创建 NebulaGraph 集群。

    kubectl create -f apps_v1alpha1_nebulacluster.yaml -n nebula
    

    返回:

    nebulacluster.apps.nebula-graph.io/nebula created
    

    如果不通过-n指定命名空间,默认使用default命名空间。

  4. 查看 NebulaGraph 集群状态。

    kubectl get nebulaclusters nebula -n nebula
    

    返回:

    NAME      READY   GRAPHD-DESIRED   GRAPHD-READY   METAD-DESIRED   METAD-READY   STORAGED-DESIRED   STORAGED-READY   AGE
    nebula    True    1                1              1               1             1                  1                86s
    

使用helm

  1. 添加 NebulaGraph Operator Helm 仓库(如果已添加,执行下步骤)。

    helm repo add nebula-operator https://vesoft-inc.github.io/nebula-operator/charts
    
  2. 更新 Helm 仓库,拉取最新仓库资源。

    helm repo update nebula-operator
    
  3. 为安装集群所需的配置参数设置环境变量。

    export NEBULA_CLUSTER_NAME=nebula         # NebulaGraph 集群的名字。
    export NEBULA_CLUSTER_NAMESPACE=nebula    # NebulaGraph 集群所处的命名空间的名字。
    export STORAGE_CLASS_NAME=local-sc         # NebulaGraph 集群的 StorageClass。
    
  4. 为 NebulaGraph 集群创建命名空间(如已创建,略过此步)。

    kubectl create namespace "${NEBULA_CLUSTER_NAMESPACE}"
    
  5. 查看创建集群时,nebula-operatornebula-cluster chart 的可自定义的配置项。

    • 执行以下命令查看所有可以配置的参数。

      helm show values nebula-operator/nebula-cluster
      
      展开查看返回结果
      nebula:
        version: v3.6.0
        imagePullPolicy: Always
        storageClassName: ""
        enablePVReclaim: false
        enableBR: false
        enableForceUpdate: false
        schedulerName: default-scheduler 
        topologySpreadConstraints:
        - topologyKey: "kubernetes.io/hostname"
          whenUnsatisfiable: "ScheduleAnyway"
        logRotate: {}
        reference:
          name: statefulsets.apps
          version: v1
        graphd:
          image: vesoft/nebula-graphd
          replicas: 2
          serviceType: NodePort
          env: []
          config: {}
          resources:
            requests:
              cpu: "500m"
              memory: "500Mi"
            limits:
              cpu: "1"
              memory: "500Mi"
          logVolume:
            enable: true
            storage: "500Mi"
          podLabels: {}
          podAnnotations: {}
          securityContext: {}
          nodeSelector: {}
          tolerations: []
          affinity: {}
          readinessProbe: {}
          livenessProbe: {}
          initContainers: []
          sidecarContainers: []
          volumes: []
          volumeMounts: []
      
        metad:
          image: vesoft/nebula-metad
          replicas: 3
          env: []
          config: {}
          resources:
            requests:
              cpu: "500m"
              memory: "500Mi"
            limits:
              cpu: "1"
              memory: "1Gi"
          logVolume:
            enable: true
            storage: "500Mi"
          dataVolume:
            storage: "2Gi"
          licenseManagerURL: ""
          license: {}
          podLabels: {}
          podAnnotations: {}
          securityContext: {}
          nodeSelector: {}
          tolerations: []
          affinity: {}
          readinessProbe: {}
          livenessProbe: {}
          initContainers: []
          sidecarContainers: []
          volumes: []
          volumeMounts: []
      
        storaged:
          image: vesoft/nebula-storaged
          replicas: 3
          env: []
          config: {}
          resources:
            requests:
              cpu: "500m"
              memory: "500Mi"
            limits:
              cpu: "1"
              memory: "1Gi"
          logVolume:
            enable: true
            storage: "500Mi"
          dataVolumes:
          - storage: "10Gi"
          enableAutoBalance: false
          podLabels: {}
          podAnnotations: {}
          securityContext: {}
          nodeSelector: {}
          tolerations: []
          affinity: {}
          readinessProbe: {}
          livenessProbe: {}
          initContainers: []
          sidecarContainers: []
          volumes: []
          volumeMounts: []
      
        exporter:
          image: vesoft/nebula-stats-exporter
          version: v3.3.0
          replicas: 1
          env: []
          resources:
            requests:
              cpu: "100m"
              memory: "128Mi"
            limits:
              cpu: "200m"
              memory: "256Mi"
          podLabels: {}
          podAnnotations: {}
          securityContext: {}
          nodeSelector: {}
          tolerations: []
          affinity: {}
          readinessProbe: {}
          livenessProbe: {}
          initContainers: []
          sidecarContainers: []
          volumes: []
          volumeMounts: []
          maxRequests: 20
      
        agent:
          image: vesoft/nebula-agent
          version: latest
          resources:
            requests:
              cpu: "100m"
              memory: "128Mi"
            limits:
              cpu: "200m"
              memory: "256Mi"
      
        console:
          username: root
          password: nebula
          image: vesoft/nebula-console
          version: latest
          nodeSelector: {}
      
        alpineImage: ""
      
      imagePullSecrets: []
      nameOverride: ""
      fullnameOverride: "" 
      
      展开查看可配置的参数描述
      字段 默认值 描述
      nebula.version v3.6.0 集群的版本。
      nebula.imagePullPolicy Always 容器镜像拉取策略。Always表示总是尝试从远程拉取最新的镜像。
      nebula.storageClassName "" Kubernetes 存储类的名称,用于动态分配持久卷。
      nebula.enablePVReclaim false 是否启用持久卷回收功能。详情参见回收 PV
      nebula.enableBR false 是否启用备份和恢复功能。详情参见使用 NebulaGraph Operator 备份和恢复数据
      nebula.enableForceUpdate false 是否不迁移分片 Leader 副本而强制更新 Storage 服务。详情参见优化滚动更新中的 Leader 分布
      nebula.schedulerName default-scheduler Kubernetes 调度器的名称。使用 Zone 功能时,必须配置为nebula-scheduler
      nebula.topologySpreadConstraints [] 用于控制 Pod 在集群中的分布。
      nebula.logRotate {} 日志轮替配置。详情参见管理集群日志
      nebula.reference {"name": "statefulsets.apps", "version": "v1"} 被NebulaGraph引用的工作负载。
      nebula.graphd.image vesoft/nebula-graphd Graph 服务的容器镜像。
      nebula.graphd.replicas 2 Graph 服务的副本数量。
      nebula.graphd.serviceType NodePort Graph 服务的 Service 类型。用来定义访问 Graph 服务的方式。详情参见连接集群
      nebula.graphd.env [] Graph 服务的容器环境变量。
      nebula.graphd.config {} Graph 服务的配置。详情参见更新集群的配置
      nebula.graphd.resources {"resources":{"requests":{"cpu":"500m","memory":"500Mi"},"limits":{"cpu":"1","memory":"500Mi"}}} Graph 服务的资源限制和请求。
      nebula.graphd.logVolume {"logVolume": {"enable": true,"storage": "500Mi"}} Graph 服务的日志存储配置。当enablefalse时,不启用日志卷。
      nebula.metad.image vesoft/nebula-metad Meta 服务的容器镜像。
      nebula.metad.replicas 3 Meta 服务的副本数量。
      nebula.metad.env [] Meta 服务的容器环境变量。
      nebula.metad.config {} Meta 服务的配置。详情参见更新集群的配置
      nebula.metad.resources {"resources":{"requests":{"cpu":"500m","memory":"500Mi"},"limits":{"cpu":"1","memory":"1Gi"}}} Meta 服务的资源限制和请求。
      nebula.metad.logVolume {"logVolume": {"enable": true,"storage": "500Mi"}} Meta 服务的日志存储配置。当enablefalse时,不启用日志卷。
      nebula.metad.dataVolume {"dataVolume": {"storage": "2Gi"}} Meta 服务的数据存储配置。
      nebula.metad.licenseManagerURL "" LM 访问地址和端口号,用于获取 License 信息。仅适用于创建企业版NebulaGraph集群。
      nebula.storaged.image vesoft/nebula-storaged Storage 服务的容器镜像。
      nebula.storaged.replicas 3 Storage 服务的副本数量。
      nebula.storaged.env [] Storage 服务的容器环境变量。
      nebula.storaged.config {} Storage 服务的配置。详情参见更新集群的配置
      nebula.storaged.resources {"resources":{"requests":{"cpu":"500m","memory":"500Mi"},"limits":{"cpu":"1","memory":"1Gi"}}} Storage 服务的资源限制和请求。
      nebula.storaged.logVolume {"logVolume": {"enable": true,"storage": "500Mi"}} Storage 服务的日志存储配置。当enablefalse时,不启用日志卷。
      nebula.storaged.dataVolumes {"dataVolumes": [{"storage": "10Gi"}]} Storage 服务的数据存储配置。支持指定多个数据盘。
      nebula.storaged.enableAutoBalance false 是否启用自动均衡。详情参见均衡扩容后的 Storage 数据
      nebula.exporter.image vesoft/nebula-stats-exporter Exporter 服务的容器镜像。
      nebula.exporter.version v3.3.0 Exporter 服务的版本。
      nebula.exporter.replicas 1 Exporter 服务的副本数量。
      nebula.exporter.env [] Exporter 服务的环境变量。
      nebula.exporter.resources {"resources":{"requests":{"cpu":"100m","memory":"128Mi"},"limits":{"cpu":"200m","memory":"256Mi"}}} Exporter 服务的资源限制和请求。
      nebula.agent.image vesoft/nebula-agent Agent 服务的配置。用于备份和恢复及日志清理功能。
      nebula.agent.version latest Agent 服务的版本。
      nebula.agent.resources {"resources":{"requests":{"cpu":"100m","memory":"128Mi"},"limits":{"cpu":"200m","memory":"256Mi"}}} Agent 服务的资源限制和请求。
      nebula.console.username root NebulaGraph命令行客户端的用户名。详情参见连接集群
      nebula.console.password nebula NebulaGraph命令行客户端的密码。
      nebula.console.image vesoft/nebula-console NebulaGraph命令行客户端的容器镜像。
      nebula.console.version latest NebulaGraph命令行客户端的版本。
      nebula.alpineImage "" Alpine Linux 容器镜像,用于获取节点所在 Zone 信息。
      imagePullSecrets [] 拉取私有镜像的 Secret 名称。
      nameOverride "" 集群名称。
      fullnameOverride "" 发布的实例名称。
      nebula.<graphd|metad|storaged|exporter>.podLabels {} 用于添加到 Pod 上的额外标签。
      nebula.<graphd|metad|storaged|exporter>.podAnnotations {} 用于添加到 Pod 上的额外注解。
      nebula.<graphd|metad|storaged|exporter>.securityContext {} 用于设置 Pod 的安全上下文。这可以包括运行 Pod 或容器的用户 ID、组 ID、Linux Capabilities 等。
      nebula.<graphd|metad|storaged|exporter>.nodeSelector {} 用于确定 Pod 应该在哪些节点上运行的标签选择器。
      nebula.<graphd|metad|storaged|exporter>.tolerations [] 用于允许 Pod 调度到具有特定 taints 的节点上。
      nebula.<graphd|metad|storaged|exporter>.affinity {} 用于设置 Pod 的亲和性规则,包括节点亲和性、Pod 亲和性和 Pod 反亲和性。
      nebula.<graphd|metad|storaged|exporter>.readinessProbe {} 用于检查容器是否已准备好处理服务请求。当探测器返回成功时,流量可以路由到该容器。
      nebula.<graphd|metad|storaged|exporter>.livenessProbe {} 用于检查容器是否仍在运行。如果探测器返回失败,Kubernetes 将杀死并重启容器。
      nebula.<graphd|metad|storaged|exporter>.initContainers [] 在应用容器启动之前运行的特殊容器,通常用于设置环境或初始化数据。
      nebula.<graphd|metad|storaged|exporter>.sidecarContainers [] 与主应用容器并行运行的容器,通常用于处理辅助任务,如日志处理、监控等。
      nebula.<graphd|metad|storaged|exporter>.volumes [] 定义需要附加到服务 Pod 的存储卷。
      nebula.<graphd|metad|storaged|exporter>.volumeMounts [] 指定容器内挂载存储卷的位置。
  6. 创建 NebulaGraph 集群。

    通过--set参数自定义 NebulaGraph 集群配置项的默认值,例如,--set nebula.storaged.replicas=3可设置 NebulaGraph 集群中 Storage 服务的副本数为 3。

    helm install "${NEBULA_CLUSTER_NAME}" nebula-operator/nebula-cluster \
    
        # 指定集群 chart 的版本,不指定则默认安装最新版本 chart。
        # 执行 helm search repo -l nebula-operator/nebula-cluster 命令可查看所有 chart 版本。
        --version=1.8.0 \
        # 指定 NebulaGraph 集群所处的命名空间。
        --namespace="${NEBULA_CLUSTER_NAMESPACE}" \
        # 自定义集群名称。
        --set nameOverride="${NEBULA_CLUSTER_NAME}" \
        --set nebula.storageClassName="${STORAGE_CLASS_NAME}" \
        # 指定 NebulaGraph 集群的版本。
        --set nebula.version=v3.6.0 
    
  7. 查看 NebulaGraph 集群 Pod 的启动状态。

    kubectl -n "${NEBULA_CLUSTER_NAMESPACE}" get pod -l "app.kubernetes.io/cluster=${NEBULA_CLUSTER_NAME}"
    

    返回:

    NAME                               READY   STATUS    RESTARTS   AGE
    nebula-exporter-854c76989c-mp725   1/1     Running   0          14h
    nebula-graphd-0                    1/1     Running   0          14h
    nebula-graphd-1                    1/1     Running   0          14h
    nebula-metad-0                     1/1     Running   0          14h
    nebula-metad-1                     1/1     Running   0          14h
    nebula-metad-2                     1/1     Running   0          14h
    nebula-storaged-0                  1/1     Running   0          14h
    nebula-storaged-1                  1/1     Running   0          14h
    nebula-storaged-2                  1/1     Running   0          14h
    

最后更新: April 19, 2024