共用方式為


附加您的應用程式

本文假設您已建立永續性磁碟區 (PV) 和永續性磁碟區宣告 (PVC)。 如需建立 PV 的相關資訊,請參閱建立永續性磁碟區。 如需建立 PVC 的相關資訊,請參閱建立永續性磁碟區宣告

將快取磁碟區新增至 aio-dp-runner-worker-0 Pod

這些 Pod 是 statefulSet 的一部分。 您不能就地編輯 statefulSet 來新增掛接點。 請改為遵循此程序:

  1. 將 statefulSet 傾印至 yaml:

    kubectl get statefulset -o yaml -n azure-iot-operations aio-dp-runner-worker > stateful_worker.yaml
    
  2. 編輯 statefulSet,在 volumeMounts 和 volumes 中納入快取磁碟區的新掛接:

    volumeMounts: 
    - mountPath: /etc/bluefin/config 
      name: config-volume 
      readOnly: true 
    - mountPath: /var/lib/bluefin/registry 
      name: nfs-volume 
    - mountPath: /var/lib/bluefin/local 
      name: runner-local
      ### Add the next 2 lines ###
    - mountPath: /mnt/esa 
      name: esa4 
    
    volumes: 
    - configMap: 
        defaultMode: 420 
        name: file-config 
      name: config-volume 
    - name: nfs-volume 
    persistentVolumeClaim: 
      claimName: nfs-provisioner
      ### Add the next 3 lines ### 
    - name: esa4 
      persistentVolumeClaim: 
        claimName: esa4
    
  3. 刪除現有的 statefulSet:

    kubectl delete statefulset -n azure-iot-operations aio-dp-runner-worker
    

    這會刪除所有 aio-dp-runner-worker-n Pod。 這是一個中斷層級事件。

  4. 使用快取磁碟區掛接建立 aio-dp-runner-worker 的新 statefulSet:

    kubectl apply -f stateful_worker.yaml -n azure-iot-operations
    

    aio-dp-runner-worker-n Pod 啟動時,即會將掛接納入快取磁碟區。 PVC 應該會以狀態傳達此情況。

  5. 重新設定資料處理器背景工作角色以存取快取磁碟區後,您必須手動更新管線設定,以使用與背景工作角色 POD 上快取磁碟區掛接位置相對應的本機路徑。

    若要修改管線,請使用 kubectl edit pipeline <name of your pipeline>。 在該管線中,使用下列 YAML 來取代輸出階段:

    output:
      batch:
        path: .payload
        time: 60s
      description: An example file output stage
      displayName: Sample File output
      filePath: '{{{instanceId}}}/{{{pipelineId}}}/{{{partitionId}}}/{{{YYYY}}}/{{{MM}}}/{{{DD}}}/{{{HH}}}/{{{mm}}}/{{{fileNumber}}}'
      format:
        type: jsonStream
      rootDirectory: /mnt/esa
      type: output/file@v1
    

設定 Kubernetes 原生應用程式

  1. 若要針對永續性磁碟區宣告 (PVC) 設定一般單一 Pod (Kubernetes 原生應用程式),請建立名為 configPod.yaml 的檔案,其中包含下列內容:

    kind: Deployment
    apiVersion: apps/v1
    metadata:
      name: example-static
      labels:
        app: example-static
      ### Uncomment the next line and add your namespace only if you are not using the default namespace (if you are using azure-iot-operations) as specified from Line 6 of your pvc.yaml. If you are not using the default namespace, all future kubectl commands require "-n YOUR_NAMESPACE" to be added to the end of your command.
      # namespace: YOUR_NAMESPACE
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: example-static
      template:
        metadata:
          labels:
            app: example-static
        spec:
          containers:
            - image: mcr.microsoft.com/cbl-mariner/base/core:2.0
              name: mariner
              command:
                - sleep
                - infinity
              volumeMounts:
                ### This name must match the 'volumes.name' attribute in the next section. ###
                - name: blob
                  ### This mountPath is where the PVC is attached to the pod's filesystem. ###
                  mountPath: "/mnt/blob"
          volumes:
            ### User-defined 'name' that's used to link the volumeMounts. This name must match 'volumeMounts.name' as specified in the previous section. ###
            - name: blob
              persistentVolumeClaim:
                ### This claimName must refer to the PVC resource 'name' as defined in the PVC config. This name must match what your PVC resource was actually named. ###
                claimName: YOUR_CLAIM_NAME_FROM_YOUR_PVC
    

    注意

    如果您使用自己的命名空間,則所有未來的 kubectl 命令都必須在命令中附加 -n YOUR_NAMESPACE。 例如,您必須使用 kubectl get pods -n YOUR_NAMESPACE,而不是標準 kubectl get pods

  2. 若要套用這個 .yaml 檔案,請執行下列命令:

    kubectl apply -f "configPod.yaml"
    
  3. 使用 kubectl get pods 來尋找 Pod 的名稱。 複製此名稱,因為您在下一步驟中需要用到此名稱。

  4. 執行下列命令,並使用您在上一步中複製的值來取代 POD_NAME_HERE

    kubectl exec -it POD_NAME_HERE -- bash
    
  5. 將目錄變更為 configPod.yaml 中指定的 /mnt/blob 掛接路徑。

  6. 例如,若要寫入檔案,請執行 touch file.txt

  7. 在 Azure 入口網站中,瀏覽至您的儲存體帳戶並尋找容器。 這是您在 pv.yaml 檔案中指定的相同容器。 當您選取容器時,會看到該容器中已填入 file.txt

下一步

完成這些步驟之後,請使用 Azure 監視器和 Kubernetes 監視功能或使用第三方監視功能搭配 Prometheus 和 Grafana 開始監視部署:

第三方監視