How can I specify persistent volumes when defining a Kubernetes replication controller in Google Cloud?

7/17/2015

I see in the docs how do do this for pods, but I want to use a replication controller to manage my pods, ensuring that there is always one up at all times.

  1. How can I define a replication controller where the pod being run has a persistent volume?

  2. How is this related to Kubernetes persistentVolumes and persistentVolumeClaims?

-- Eric
google-cloud-platform
kubernetes
storage

3 Answers

2/6/2019

Here is a mongo-db replication controller that uses gce persistent volume :

apiVersion: v1
kind: ReplicationController
metadata:
  labels:
    name: mongo
  name: mongo-controller
spec:
  replicas: 1
  template:
    metadata:
      labels:
        name: mongo
    spec:
      containers:
      - image: mongo
        name: mongo
        ports:
        - name: mongo
          containerPort: 27017
          hostPort: 27017
        volumeMounts:
            - name: mongo-persistent-storage
              mountPath: /data/db
      volumes:
        - name: mongo-persistent-storage
          gcePersistentDisk:
            pdName: mongo-disk
            fsType: ext4

for creating disks in gce use:

gcloud compute disks create mongo-disk --size=3GB --zone=any_zone

notice that zone of disk must be same as your cluster.

-- shubham_asati
Source: StackOverflow

9/10/2015

Using a persistent volume in a Replication Controller works great for shared storage. You include a persistentVolumeClaim in the RC's pod template. Each pod will use the same claim, which means it's shared storage. This also works for read-only access in gcloud if your Replica count > 1.

If you wanted distinct volumes per pod, you currently have to create many RCs with Replicas=1 and with distinct persistentVolumeClaims.

We're working out a design for scaling storage through an RC where each pod gets its own volume instead of sharing the same claim.

-- Mark Turansky
Source: StackOverflow

7/20/2015

Please note that persistent volumes are linked to a node, they are not shared throughout the cluster. That is probably the reason you didn't find information about the replication controller with persistent volumes. Because replication controllers are not limited to running one node.

If you are using the Google Cloud, look into GCEPersistentVolume https://github.com/GoogleCloudPlatform/kubernetes/tree/master/docs/user-guide/persistent-volumes

Another option, though not production ready is: https://clusterhq.com/2015/04/24/data-migration-kubernetes-flocker/

-- PJong
Source: StackOverflow