Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I am trying to use gcs bucket as the volume in gke pod

I am getting the error:

error validating "mysql.yaml": error validating data: ValidationError(Deployment.spec.template.spec.volumes[0]): unknown field "path" in io.k8s.kubernetes.pkg.api.v1.Volume; )

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: mysql
  labels:
    app: mysql
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mysql
  template:
    metadata:
      labels:
        app: mysql
    spec:
      containers:
        - image: mysql:5.6
          name: mysql
          env:
            - name: MYSQL_ROOT_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: mysql
                  key: password
          ports:
            - containerPort: 3306
              name: mysql
          volumeMounts:
            - name: mapping-sandbox-test
              mountPath: /var/lib/mysql
      volumes:
        - name: mapping-sandbox-test
          path: gs://<bucket-name>
like image 314
Ram Avatar asked Jan 12 '18 09:01

Ram


People also ask

How do I mount a GCP bucket inside a container?

To mount the GCP bucket inside the container, run the container in privileged mode. For a container to start the deployment the file should contain required configuration with a Google Cloud Storage bucket mounted in a given path.

Which of these can be used as volumes in Kubernetes?

Kubernetes supports many types of volumes. A Pod can use any number of volume types simultaneously. Ephemeral volume types have a lifetime of a pod, but persistent volumes exist beyond the lifetime of a pod.

How do you check the volume of a pod on Kubernetes?

You can get the volumes mounted on the pod using the output of kubectl describe pod which has the Mounts section in each container's spec . You can then exec into the pod using kubectl exec and the cd to the directory you want to write data to.


1 Answers

Your Deployment object looks correct using name and path as keys. You can see an example on how to mount a GCS bucket on kubernetes here

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: gcsfuse-test
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: gcsfuse-test
    spec:
      containers:
        - name: gcsfuse-test
          image: gcr.io/some-repo/gcs-fuse:latest
          securityContext:
            privileged: true
            capabilities:
              add:
                - SYS_ADMIN
          lifecycle:
            postStart:
              exec:
                command: ["gcsfuse", "-o", "nonempty", "some-bucket", "/mnt/some-bucket"]
            preStop:
              exec:
                command: ["fusermount", "-u", "/mnt/some-bucket"]

This Stack Overflow question might help too.

like image 173
Jose Armesto Avatar answered Oct 11 '22 17:10

Jose Armesto