简体   繁体   中英

Storing the Cassandra data using Stateful set

I have been reading about the ways in which I can push the database on kubernetes. Initially, I attached the data to the docker image and deployed the service and deployment files. But the issue was that when the container/pod restarts the data gets lost. I, then, came across the concept of persistent volume claim. I found ( https://www.magalix.com/blog/kubernetes-and-database ) and ( https://kubernetes.io/docs/tutorials/stateful-application/cassandra/ ) very useful. I have few questions regarding them though:

PVC:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mysql-pv-claim
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 20Gi

PV:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: mysql-pv-volume
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 20Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/mnt/data"
  1. How does the PVC get the storage from PV in the cluster? If I am running my service using Amazon cloud, what are the steps for the same, if any.

PVCs will consume the PV resources you've provisioned. There a more detailed explanation in the Kubernetes docs onPersistent Volumes including the lifecycle of volumes and PV claims.

As a side note in case you weren't already aware, there are several Cassandra operators readily available which makes it easier for you to deploy a cluster on Kubernetes including Instaclustr's , Orange's CassKop and DataStax's cass-operator .

The DataStax cass-operator allows you to deploy either a DSE cluster or an Apache Cassandra cluster. You can find out more at the official docs site here . You can also reach out directly to the authors of the cass-operator at https://community.datastax.com if you have any questions. Cheers!

Persistent Volume :

PV is a piece of storage in the cluster that has been provisioned by an administrator or dynamically provisioned using Storage Classes . Persistent Volume Claim PVC is a request for storage by a user. It is similar to a Pod. Pods consume node resources and PVCs consume PV resources.

If you want to bound PV and PVC you can chose between two Provisioning ways:

  • Static

A cluster administrator creates a number of PVs . They carry the details of the real storage, which is available for use by cluster users. They exist in the Kubernetes API and are available for consumption.

  • Dynamic

When none of the static PVs the administrator created match a user's PersistentVolumeClaim , the cluster may try to dynamically provision a volume specially for the PVC . This provisioning is based on StorageClasses: the PVC must request a storage class and the administrator must have created and configured that class for dynamic provisioning to occur. Claims that request the class "" effectively disable dynamic provisioning for themselves.

In short, if you are using Static provisioning, for each PVC you need to create PV , as they are bounding 1:1 relationship.

You can find more useful details in this thread .

As you are using Cloud environment (Amazon) which supports Dynamic Volume Provisioning you can just use PVC . Dynamic Provisioning will create PV with PVC requirements.

When you are using Statefulset and you need to ensure that each pod will have own PV , you can use VolumeClaimTemplate like in documentation example .

Regarding main question:

How does the PVC get the storage from PV in the cluster? If I am running my service using Amazon cloud, what are the steps for the same, if any.

  • If you want to use static provisioning, you will need to create PV and PVC for each pod.

  • As most of the cloud provideres supports Dynamic Provisioning you can just create PVC and Cloud Provisioner will automatically creates PV with PVC requirements. In addition, the most common way to create PV and PVC for pods in statefulset is to use VolumeClaimTemplate , where you can specify storageclass , storage and more other parameters:

     volumeClaimTemplates: - metadata: name: cassandra-data spec: accessModes: [ "ReadWriteOnce" ] storageClassName: fast resources: requests: storage: 1Gi

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