Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I map a docker volume to a google compute engine persistent disk

I've gone through the steps to create a persistent disk in google compute engine and attach it to a running VM instance. I've also created a docker image with a VOLUME directive. It runs fine locally, in the docker run command, i can pass a -v option to mount a host directory as the volume. I thought there would be a similar command in kubectl, but I don't see one. How can I mount my persistent disk as the docker volume?

like image 546
slushi Avatar asked Oct 18 '22 02:10

slushi


1 Answers

In your pod spec, you may specify a Kubernetes gcePersistentDisk volume (the spec.volumes field) and where to mount that volume into containers (the spec.containers.volumeMounts field). Here's an example:

apiVersion: v1
kind: Pod
metadata:
  name: test-pd
spec:
  containers:
  - image: gcr.io/google_containers/test-webserver
    name: test-container
    volumeMounts:
    - mountPath: /test-pd
      name: test-volume
  volumes:
  - name: test-volume
    # This GCE PD must already exist.
    gcePersistentDisk:
      pdName: my-data-disk
      fsType: ext4

Read more about Kubernetes volumes: http://kubernetes.io/docs/user-guide/volumes

like image 161
janetkuo Avatar answered Nov 15 '22 05:11

janetkuo