How can I specify persistent volumes when defining

2019-02-09 19:56发布

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?

3条回答
混吃等死
2楼-- · 2019-02-09 20:21

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/

查看更多
Luminary・发光体
3楼-- · 2019-02-09 20:37

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.

查看更多
唯我独甜
4楼-- · 2019-02-09 20:45

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.

查看更多
登录 后发表回答