How to connect a persistent drive to a container volume?

I have been playing around with Google's virtual machine support feature and found that you can create interesting settings quite easily. However, I have yet to figure out if persistent disks can be used to mount a volume in a container and does not seem to have a limitation on this feature, the usefulness of managed VMs for stateful containers such as databases.

So the question is, how do you mount the persistent drive Google created for the Compute kernel instance into a container volume?

+3


source to share


3 answers


Attaching a persistent drive to a Google Compute Engine instance

Follow the official persistent drive :

  • Create disk
  • Attach to an instance during instantiation or to a running instance
  • Use the tool /usr/share/google/safe_format_and_mount

    to install the device file/dev/disk/by-id/google-...

  • As Faizan pointed out, use docker run -v /mnt/persistent_disk:/container/target/path

    to include a volume in a docker container


Permanent Drive Link in Google Container Engine

In this method, you specify the volume declaratively (after initializing it as above ...) in the replication controller or in signatures. Below is a minimal excerpt from the JSON declaration of a replication controller. Note that the volume must be declared read-only because no more than two instances can write to the persistent disk at a time.

{
    "id": "<id>",
    "kind": "ReplicationController",
    "apiVersion": "v1beta1",
    "desiredState": {
        "replicas": 3,
        "replicaSelector": {
            "name": "<id>"
        },
        "podTemplate": {
            "desiredState": {
                "manifest": {
                    "version": "v1beta1",
                    "id": "<id>",
                    "containers": [
                        {
                            "name": "<id>",
                            "image": "<docker_image>",
                            "volumeMounts": [
                                {
                                    "name": "persistent_disk",
                                    "mountPath": "/pd",
                                    "readOnly": true
                                }
                            ],
                            ...
                        }
                    ],
                    "volumes": [
                        {
                            "name": "persistent_disk",
                            "source": {
                                "persistentDisk": {
                                    "pdName": "<persistend_disk>",
                                    "fsType": "ext4",
                                    "readOnly": true
                                }
                            }
                        }
                    ]
                }
            },
            "labels": {
                "name": "<id>"
            }
        }
    },
    "labels": {
        "name": "<id>"
    }
}

      

+1


source


If your persistent drive is connected and already mounted to the instance, I believe you can use it as a data volume in a docker container. I was able to find documentation that explains the steps for managing data in containers.



0


source


I'm sure this is not currently supported. There might be a way to reattach the disk after the instance is inserted, but it will be quite fragile.

For example, when deploying a new version, there is usually a period of time during which there are two virtual machines, one of which starts the old version and starts the new version; but you can only connect the drive to one of the two, so you will have to manually disconnect and disconnect the drive from the old version, and then reconnect and connect it to the new version ...

The setup I would recommend if your database needs to write to persistent disk is a separate database server on the Compute Engine.

0


source







All Articles