简体   繁体   English

如何将使用持久卷声明的 Kubernetes 部署扩展到 2 个 Pod?

[英]How to scale a Kubernetes deployment which uses a Persistent Volume Claim to 2 Pods?

I have a Kubernetes deployment (apache flume to be exact) which needs to store persistent data.我有一个需要存储持久数据的 Kubernetes 部署(确切地说是 apache 水槽)。 It has a PVC set up and bind to a path, which works without problem.它有一个 PVC 设置并绑定到一个路径,它可以正常工作。

When I simply increase the scale of the deployment through kubernetes dashboard, it gives me an error saying multiple pods are trying to attach the same persistent volume.当我通过 kubernetes 仪表板简单地增加部署规模时,它给了我一个错误,说多个 pod 正在尝试附加相同的持久卷。 My deployment description is something like this (I tried to remove irrelevant parts)我的部署描述是这样的(我试图删除不相关的部分)

{
    "kind": "Deployment",
    "apiVersion": "extensions/v1beta1",
    "metadata": {
        "name": "myapp-deployment",    
        "labels": {
          "app": "myapp",
          "name": "myapp-master"
        },    
    "spec": {
    "replicas": 1,
    "selector": {
      "matchLabels": {
        "app": "myapp",
        "name": "myapp-master"
      }
    },
    "template": {
      "spec": {
        "volumes": [
          {
            "name": "myapp-data",
            "persistentVolumeClaim": {
              "claimName": "myapp-pvc"
            }
          }
        ],
        "containers": [
          {
            "name": "myapp",
            "resources": {},
            "volumeMounts": [
              {
                "name": "ingestor-data",
                "mountPath": "/data"
              }
            ]
          }
        ]
      }
    },...

Each pod should get its own persistent space (but with same pathname), so one doesn't mess with the others'.每个 pod 都应该有自己的持久空间(但具有相同的路径名),因此不会与其他 pod 混淆。 I tried to add a new volume in the volume array above, and a volume mount in the volume mount array, but it didn't work (I guess it meant "bind two volumes to a single container")我尝试在上面的卷阵列中添加一个新卷,并在卷挂载阵列中添加一个卷挂载,但它不起作用(我猜这意味着“将两个卷绑定到一个容器”)

What should I change to have 2 pods with separate persistent volumes?我应该改变什么来拥有 2 个具有单独持久卷的 pod? What should I change to have N number of pods and N number of PVC's so I can freely scale the deployment up and down?我应该改变什么来拥有 N 个 Pod 和 N 个 PVC,这样我就可以自由地向上和向下扩展部署?

Note: I saw a similar question here which explains N number of pods cannot be done using deployments.注意:我在这里看到了一个类似的问题,它解释了 N 个 Pod 无法使用部署完成。 Is it possible to do what I want with only 2 pods?是否可以只用 2 个 pod 做我想做的事?

You should use a StatefulSet for that.您应该为此使用StatefulSet This is for pods with persistent data that should survive a pod restart.这适用于具有持久数据的 pod,这些数据应该能够在 pod 重启后继续存在。 Replicas have a certain order and are named in that way (my-app-0, my-app-1, ...).副本具有一定的顺序并以这种方式命名(my-app-0,my-app-1,...)。 They are stopped and restarted in this order and will mount the same volume after a restart/update.它们按此顺序停止和重新启动,并将在重新启动/更新后安装相同的卷。

With the StatefulSet you can use a volumeClaimTemplates to dynamically create new PersistentVolumes with the creation of a new pod.使用StatefulSet ,您可以使用volumeClaimTemplates通过创建新 pod 来动态创建新的PersistentVolumes So every time a pod is created a volume get provisioned by your storage class.因此,每次创建 pod 时,您的存储 class 都会配置一个卷。

From docs:来自文档:

The volumeClaimTemplates will provide stable storage using PersistentVolumes provisioned by a PersistentVolume Provisioner volumeClaimTemplates 将使用 PersistentVolume Provisioner 提供的 PersistentVolumes 提供稳定的存储

volumeClaimTemplates:
  - metadata:
      name: www
    spec:
      accessModes: [ "ReadWriteOnce" ]
      storageClassName: "my-storage-class"
      resources:
        requests:
          storage: 1Gi

See docs for more details: https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#components有关更多详细信息,请参阅文档: https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#components

Each pod should get its own persistent space (but with same pathname), so one doesn't mess with the others'.每个 pod 都应该有自己的持久空间(但具有相同的路径名),因此不会与其他 pod 混淆。

For this reason, use a StatefulSet instead.因此,请改用StatefulSet Most things will work the same way, except that each Pod will get its own unique Persistent Volume.大多数事情都会以相同的方式工作,除了每个 Pod 将获得自己独特的 Persistent Volume。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Google Cloud Kubernetes Persistent Volume Claim 部署中的错误 Yaml - Google Cloud Kubernetes Persistent Volume Claim error in deployment Yaml 如何使用 client-go 库列出与持久卷声明关联的 Pod? - How to list Pods which are associated with persistent volume claim using client-go library? Kubernetes 持久卷声明 FileSystemResizePending - Kubernetes Persistent Volume Claim FileSystemResizePending 持久卷和持久卷声明在 kubernetes 中如何相互绑定 - How persistent volume and persistence volume claim bound each other in kubernetes MySQL 对 Kubernetes 的持久卷声明 - MySQL with Persistent Volume Claim on Kubernetes Kubernetes - 扩展部署 Pod 时未安装卷 - Kubernetes - Volume not getting mounted when I scale the deployment pods GCE Kubernetes:永久磁盘和永久卷声明 - GCE Kubernetes: Persistent disk and Persistent Volume claim 将新卷附加到持久卷声明 (Kubernetes) - Attaching New Volume to Persistent Volume Claim (Kubernetes) 如何为kubernetes中的软件安装提供永久批量声明 - How to provision persistent volume claim for software install in kubernetes 如何在 Kubernetes 持久卷中声明和配置 Bitnami Docker 话语数据? - How to claim & configure Bitnami Docker Discourse data in Kubernetes Persistent volume?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM