Mounting External Volumes

This topic explains how to mount additional volumes to a workload migrated with Migrate for Anthos. You might want to do this when your workload depends on an external volume that is not copied to a Persistent Volume.

To add external volumes to a Migrate for Anthos workload:

  1. Add the volume to the StatefulSet in spec.containers.volumeMounts. See Kubernetes Volumes for more information.
  2. Mount the volume in the container at the mount point you would like. This will vary depending on the container's operating system.
  3. Add the mount point to the HC_FORWARD_MOUNTS environment variable in the workload's YAML.

The example below mounts the volume emptydir to /tmp.

apiVersion: apps/v1
kind: StatefulSet
metadata:
  creationTimestamp: null
  labels:
    app: app-my-vm-instance-1
    migrate-for-anthos-type: workload
  name: app-my-vm-instance-1
spec:
  replicas: 1
  selector:
    matchLabels:
      app: app-my-vm-instance-1
      migrate-for-anthos-type: workload
  serviceName: app-my-vm-instance-1
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: app-my-vm-instance-1
        migrate-for-anthos-type: workload
    spec:
      containers:
      - image: gcr.io/my-project/my-vm-instance-1:v1.0.0
        name: app-my-vm-instance-1
        readinessProbe:
          exec:
            command:
            - /code/ready.sh
        resources: {}
        securityContext:
          privileged: true
        volumeMounts:
        - name: emptydir
          mountPath: /tmp
        - mountPath: /sys/fs/cgroup
          name: cgroups
        - mountPath: /code/config/logs/
          name: logs-config
        - mountPath: /<folder>
          name: pvc-my-vm-instance-1
          subPath: <folder>
      volumes:
      - name: emptydir
        emptyDir: {}
      - hostPath:
          path: /sys/fs/cgroup
          type: Directory
        name: cgroups
      - configMap:
          name: app-my-vm-instance-1
        name: logs-config
      - name: pvc-my-vm-instance-1
        persistentVolumeClaim:
          claimName: pvc-my-vm-instance-1
  updateStrategy: {}
status:
  replicas: 0