装载外部卷

本主题说明如何向使用 Migrate for Anthos 迁移的工作负载装载其他卷。如果您的工作负载依赖于未复制到永久性卷的外部卷,则可能需要执行此操作。

如需将外部卷添加到 Migrate for Anthos 工作负载,请执行以下操作:

  1. 将卷添加到 spec.containers.volumeMounts 中的 StatefulSet。如需了解详情,请参阅 Kubernetes 卷
  2. 将容器中的卷装载到您所需的装载点。这取决于容器的操作系统。
  3. 将装载点添加到工作负载的 YAML 中的 HC_FORWARD_MOUNTS 环境变量。

以下示例将卷 emptydir 装载到 /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