本機共用邊緣磁碟區

本文說明本機共用邊緣磁碟區的設定 (高可用性的耐久本機儲存體)。

什麼是本機共用邊緣磁碟區?

本機共用邊緣磁碟區功能可提供高可用性、可容錯移轉的儲存體 (在 Kubernetes 叢集的本機)。 此共用儲存體類型會與雲端基礎結構保持不相依的狀態,因此非常適合用於暫存空間、暫存儲存體,以及可能不適合雲端目的地的本機永續性資料。

建立本機共用邊緣磁碟區永續性磁碟區宣告 (PVC),並針對 PVC 設定 Pod

  1. 建立名為 localSharedPVC.yaml 的檔案,包含以下內容。 使用永續性磁碟區宣告的名稱來修改 metadata.name 值。 然後,在第 8 行中,指定符合您預期之取用 Pod 的命名空間。 在下一個步驟中,deploymentExample.yaml 的最後一行會參考 metadata.name 值。 spec.resources.requests.storage 參數會決定永續性磁碟區的大小。 在此範例中為 2 GB,但可以修改以符合您的需求:

    注意

    請只使用小寫字母和數字。 如需詳細資訊,請參閱 Kubernetes 物件命名文件

    kind: PersistentVolumeClaim
    apiVersion: v1
    metadata:
      ### Create a name for your PVC ###
      name: <create-a-pvc-name-here>
      ### Use a namespace that matches your intended consuming pod, or "default" ###
      namespace: <intended-consuming-pod-or-default-here>
    spec:
      accessModes:
        - ReadWriteMany
      resources:
        requests:
          storage: 2Gi
      storageClassName: unbacked-sc
    
  2. 建立名為 deploymentExample.yaml 的檔案,包含以下內容。 為 containers.namevolumes.persistentVolumeClaim.claimName 新增值。 spec.replicas 參數會決定要建立的複本 Pod 數目。 在此範例中有 2 個,但可以修改以符合您的需求:

    注意

    請只使用小寫字母和數字。 如需詳細資訊,請參閱 Kubernetes 物件命名文件

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: localsharededgevol-deployment ### This will need to be unique for every volume you choose to create
    spec:
      replicas: 2
      selector:
        matchLabels:
          name: wyvern-testclientdeployment
      template:
        metadata:
          name: wyvern-testclientdeployment
          labels:
            name: wyvern-testclientdeployment
        spec:
          affinity:
            podAntiAffinity:
              requiredDuringSchedulingIgnoredDuringExecution:
                - labelSelector:
                    matchExpressions:
                      - key: app
                        operator: In
                        values:
                          - wyvern-testclientdeployment
                  topologyKey: kubernetes.io/hostname
          containers:
            ### Specify the container in which to launch the busy box. ###
            - name: <create-a-container-name-here>
              image: 'mcr.microsoft.com/mirror/docker/library/busybox:1.35'
              command:
                - "/bin/sh"
                - "-c"
                - "dd if=/dev/urandom of=/data/acsalocalsharedtestfile count=16 bs=1M && while true; do ls /data &>/dev/null || break; sleep 1; done"
              volumeMounts:
                ### This name must match the following volumes::name attribute ###
                - name: wyvern-volume
                  ### This mountPath is where the PVC will be attached to the pod's filesystem ###
                  mountPath: /data
          volumes:
            ### User-defined name that is used to link the volumeMounts. This name must match volumeMounts::name as previously specified. ###
            - name: wyvern-volume
              persistentVolumeClaim:
                ### This claimName must refer to your PVC metadata::name from lsevPVC.yaml.
                claimName: <your-pvc-metadata-name-from-line-5-of-pvc-yaml>
    
  3. 若要套用這些 YAML 檔案,請執行:

    kubectl apply -f "localSharedPVC.yaml"
    kubectl apply -f "deploymentExample.yaml"
    
  4. 執行 kubectl get pods 以尋找 Pod 的名稱。 複製此名稱,因為下一個步驟需要用到。

    注意

    由於 deploymentExample.yaml 中的 spec::replicas 已指定為 2,因此使用 kubectl get pods 會出現兩個 Pod。 您可以選擇任一 Pod 名稱以供下一個步驟使用。

  5. 執行下列命令,並將 POD_NAME_HERE 取代為您從上一個步驟複製的值:

    kubectl exec -it pod_name_here -- sh
    
  6. 將目錄變更為 /data 掛接路徑,如 deploymentExample.yaml 中所指定。

  7. 例如,建立名為 file1.txt 的檔案,並使用 echo "Hello World" > file1.txt 寫入其中。

完成上述步驟後,請使用 Azure 監視器和 Kubernetes 監視,或使用具有 Prometheus 和 Grafana 的第三方監視,開始監視您的部署。

下一步

監視您的部署