简体   繁体   中英

Kubernetes - Volume not getting mounted when I scale the deployment pods

I have got a deployment.yaml and it uses a persistentvolumeclaim like so

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: mautic-pvc
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 5Gi
  storageClassName: standard

I am trying to scale my deployment horizontally using (Horizontal Pod Scheduler) but when I scale my deployment, the rest of the pods are in ContainerCreating process and this is the error I get when I describe the pod

Unable to attach or mount volumes: unmounted volume

What am I doing wrong here?

Using Deployment is great if your app can scale horizontally . However, using aPersistent Volume with a PersistentVolumeClaim can be challenging when scaling horizontally .

Persistent Volume Claim - Access Modes

A PersistentVolumeClaim can be requested for a few different Access Modes :

  • ReadWriteOnce (most common)
  • ReadOnlyMany
  • ReadWriteMany

Where ReadWriteOnce is the most commonly available and is typical behavior for a local disk. But to scale your app horizontally - you need a volume that is available from multiple nodes at the same time, so only ReadOnlyMany and ReadWriteMany is viable options. You need to check what what access modes are available for your storage system .

In addition, you use a regional cluster from a cloud provider, it spans over three Availability Zones and a volume typically only live in one Availability Zone , so even if you use ReadOnlyMany or ReadWriteMany access modes, it makes your volume available on multiple nodes in the same AZ, but not available in all three AZs in your cluster. You might consider using a storage class from your cloud provider that is replicated to multiple Availability Zones , but it typically costs more and is slower.

Alternatives

Since only ReadWriteOnce is commonly available, you might look for better alternatives for your app.

Object Storage

Object Storage, or Buckets, is a common way to handle file storage in the cloud instead of using filesystem volumes. With Object Storage you access you files via an API over HTTP. See eg AWS S3 or Google Cloud Storage .

StatefulSet

You could also consider StatefulSet where each instance of your app get its own volume. This makes your app distributed but typically not horizontally scalable . Here, your app typically needs to implement replication of data, typically using Raft and is a more advanced alterantive.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM