Kubernetes 有状态集复制

发布于 2025-01-17 19:06:07 字数 1570 浏览 5 评论 0原文

我正在为我的 mongodb 和 influxdb 使用 kubernetes statefulset。

在此处输入图像描述

总之,与 Deployment 对象相比,StatefulSet 具有以下优势: 每个 Pod 的有序编号。第一个 Pod 可以是主 Pod,这使其成为创建处理读取和写入的复制数据库设置时的不错选择。其他 Pod 充当副本。

但是,当我为 mongodb 和 influxdb 部署有 3 个副本的 statefulset 时,只有一个 pod(第一个 pod,即 mondodb-0 和 influxdb-0)正在存储数据,而不是剩余的数据Pod 正在克隆第一个 Pod 中的数据。

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: influxdb
  labels:
    app: influxdb
spec:
  selector:
    matchLabels:
      app: influxdb
  serviceName: influxdb
  replicas: 3
  template:
    metadata:
      labels:
        app: influxdb
    spec:
      terminationGracePeriodSeconds: 10
      containers:
      - name: influxdb
        image: influxdb:1.8.10
        command:
                # - influx
                # - --bind_ip_all
        ports:
        - containerPort: 8086
        env:
         - name: INFLUXDB_USERNAME
           valueFrom:
             secretKeyRef:
               name: influxdb-secret
               key: influxdb-username
         - name: INFLUXDB_PASSWORD
           valueFrom:
             secretKeyRef:
               name: influxdb-secret
               key: influxdb-password
        volumeMounts:
        - name: influxdb-volume
          mountPath: /data/db
  volumeClaimTemplates:
  - metadata:
      name: influxdb-volume
    spec:
      accessModes: [ ReadWriteOnce ]
      resources:
        requests:
          storage: 25Gi

我正在尝试使用上述 yaml 文件,但无法将数据从第一个 pod 克隆到其余 pod。只有一个 pod 正在获取数据。

I am using kubernetes statefulset for my mongodb and influxdb.

enter image description here

In summary, StatefulSets provide the following advantages when compared to Deployment objects: Ordered numbers for each Pod. The first Pod can be a primary, which makes it a good choice when creating a replicated database setup, which handles both reading and writing. Other Pods act as replicas.

But while i am deploying statefulset for both mongodb and influxdb with 3 replicas, only one pod (first pod, i.e. mondodb-0 and influxdb-0) is storing the data, non of the remaining pods are cloning the data from the first pod.

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: influxdb
  labels:
    app: influxdb
spec:
  selector:
    matchLabels:
      app: influxdb
  serviceName: influxdb
  replicas: 3
  template:
    metadata:
      labels:
        app: influxdb
    spec:
      terminationGracePeriodSeconds: 10
      containers:
      - name: influxdb
        image: influxdb:1.8.10
        command:
                # - influx
                # - --bind_ip_all
        ports:
        - containerPort: 8086
        env:
         - name: INFLUXDB_USERNAME
           valueFrom:
             secretKeyRef:
               name: influxdb-secret
               key: influxdb-username
         - name: INFLUXDB_PASSWORD
           valueFrom:
             secretKeyRef:
               name: influxdb-secret
               key: influxdb-password
        volumeMounts:
        - name: influxdb-volume
          mountPath: /data/db
  volumeClaimTemplates:
  - metadata:
      name: influxdb-volume
    spec:
      accessModes: [ ReadWriteOnce ]
      resources:
        requests:
          storage: 25Gi

I am trying with the above yaml file, but i am unable to clone the data from first pod to the remaining pods. only one pod is getting the data.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月亮坠入山谷 2025-01-24 19:06:07

在有状态集中,每个实例独立运行。因此,在您的模板中,influxdb-0influxdb-1influxdb-2 分别运行 **influxdb:1.8。 10**
以及您提供的凭据。如果您需要预填充数据库或从快照中恢复,它不应该依赖于以前的 Pod,但它应该是有状态集的每个实例的一部分(例如,通过 initContainer 或配置或连接的应用程序中的脚本)到数据库并提供必要的数据(如果需要)

In statefulset, each instance runs independently. So in your template, influxdb-0, influxdb-1, and influxdb-2 individually runs the **influxdb:1.8.10**
with the credentials you provided. If you need to pre-fill the database or recover from a snapshot it shouldn't be dependant on the previous pods but it should be part of each instance of the statefulset (e.g., through initContainer or a script in your configs or app that connects to db and provide neccassary data if it's needed)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文