Share via


快速入門:使用 Azure CLI 部署具有機密運算 Intel SGX 代理程式節點的 AKS 叢集

本快速入門將引導您使用 Azure CLI 來部署具有記憶體保護區感知 (DCsv2/DCSv3) VM 節點的 Azure Kubernetes Service (AKS) 叢集。 接著,在記憶體保護區中執行簡單的 Hello World 應用程式。 也可以在 Azure 入口網站中佈建叢集並新增機密運算節點,但本快速入門只說明透過 Azure CLI 的方式。

AKS 是受控 Kubernetes 服務,可讓開發人員或叢集操作員快速部署和管理叢集。 若要深入了解,請參閱 AKS 簡介AKS 機密節點概觀

機密運算節點的功能包含:

  • 支援 Linux 容器的 Linux 背景工作角色節點。
  • 具有 Ubuntu 18.04 VM 節點的 Generation 2 虛擬機器。
  • 支援 Intel SGX 的 CPU 可利用加密頁面快取記憶體 (EPC) 在機密保護的記憶體保護區中執行容器。 如需詳細資訊,請參閱 Azure 機密運算的常見問題集
  • 機密運算節點會預先安裝 Intel SGX DCAP 驅動程式。 如需詳細資訊,請參閱 Azure 機密運算的常見問題集

注意

DCsv2/DCsv3 VM 使用受區域可用性限制的專用硬體。 如需詳細資訊,請參閱可用 SKU 和支援區域

必要條件

本快速入門需要:

  • 您的訂用帳戶中至少要有八個 DCsv2/DCSv3/DCdsv3 核心可供使用。

    根據預設,Azure 訂用帳戶的 Intel SGX VM 大小沒有預先指派的配額。 請依照這些指示,索取訂用帳戶的 VM 核心配額。

建立具有記憶體保護區感知機密運算節點和 Intel SGX 附加元件的 AKS 叢集

使用下列指示建立已啟用 Intel SGX 附加元件的 AKS 叢集、將節點集區新增至叢集,並驗證您使用 hello world 記憶體保護區應用程式建立的內容。

使用系統節點集區和 AKS Intel SGX 附加元件建立 AKS 叢集

注意

如果您已有符合上述需求的 AKS 叢集,請跳至下一節以新增機密運算節點集區。

Intel SGX AKS 附加元件「confcom」會向容器顯示 Intel SGX 裝置驅動程式,避免再變更 pod yaml。

首先,使用 az group create 命令來建立叢集的資源群組。 下列範例會在 eastus2 區域建立名為 myResourceGroup 的資源群組:

az group create --name myResourceGroup --location eastus2

現在,使用 az aks create 命令,建立已啟用機密運算附加元件的 AKS 叢集:

az aks create -g myResourceGroup --name myAKSCluster --generate-ssh-keys --enable-addons confcom

上述命令會部署具有非機密運算節點系統節點集區的新 AKS 叢集。 系統節點集區不建議使用機密運算 Intel SGX 節點。

將具有機密運算功能的使用者節點集區新增至 AKS 叢集

執行下列命令將具有三個節點 Standard_DC4s_v3 大小的使用者節點集區新增至 AKS 叢集。 您可以從支援的 DCsv2/DCsv3 SKU 和區域清單中選擇另一個較大的 SKU。

az aks nodepool add --cluster-name myAKSCluster --name confcompool1 --resource-group myResourceGroup --node-vm-size Standard_DC4s_v3 --node-count 2

執行命令之後,具有 DCsv3 的新節點集區應該可以透過機密運算附加元件 DaemonSet (SGX 裝置外掛程式) 查看。

確認節點集區與附加元件

使用 az aks get-credentials 命令取得您 AKS 叢集的認證:

az aks get-credentials --resource-group myResourceGroup --name myAKSCluster

使用 kubectl get pods 命令,確認已正確建立節點,且已在 DCsv2 節點集區上執行 SGX 的相關 DaemonSet:

kubectl get pods --all-namespaces
kube-system     sgx-device-plugin-xxxx     1/1     Running

如果輸出符合上述程式碼,表示您的 AKS 叢集現已做好執行機密應用程式的準備。

您可以依照本快速入門中的透過隔離的記憶體保護區應用程式部署 Hello World 一節,在記憶體保護區中測試應用程式。 或依照下列指示在 AKS 中新增更多節點集區。 (AKS 支援混合 SGX 節點集區和非 SGX 節點集區。)

將機密運算節點集區新增至現有的 AKS 叢集

本節假設您已執行本快速入門稍早列出的必要 AKS 叢集。

在現有的叢集上啟用機密運算 AKS 附加元件

執行下列命令,啟用機密運算附加元件:

az aks enable-addons --addons confcom --name MyManagedCluster --resource-group MyResourceGroup

將 DCsv3 使用者節點集區新增至叢集

注意

若要使用機密運算功能,您的現有 AKS 叢集必須至少有一個以 DCsv2/DCsv3 VM SKU 為基礎的節點集區。 若要深入了解用於機密運算的 DCs-v2/Dcs-v3 VM SKU,請參閱可用的 SKU 和支援的區域

執行下列命令來建立節點集區:

az aks nodepool add --cluster-name myAKSCluster --name confcompool1 --resource-group myResourceGroup --node-count 2 --node-vm-size Standard_DC4s_v3

確認已建立名稱為 confcompool1 的新節點集區:

az aks nodepool list --cluster-name myAKSCluster --resource-group myResourceGroup

確認 DaemonSet 已在機密節點集區上執行

登入現有 AKS 叢集,執行下列驗證:

kubectl get nodes

輸出應該會顯示 AKS 叢集上新增的 confcompool1 集區。 可能也會看到其他 DaemonSet。

kubectl get pods --all-namespaces
kube-system     sgx-device-plugin-xxxx     1/1     Running

如果輸出符合上述程式碼,表示您的 AKS 叢集現已做好執行機密應用程式的準備。

從隔離的記憶體保護區應用程式 部署 Hello World

您現在已準備好部署測試應用程式。

建立名為 hello-world-enclave.yaml 的檔案,並在下列 YAML 資訊清單中貼上。 您可以在 Open Enclave 專案中找到此應用程式範例程式碼。 此部署假設您已部署 confcom 附加元件;

注意

下列範例會從 Docker Hub 提取公用容器映像。 建議您設定提取祕密,以使用 Docker Hub 帳戶進行驗證,而不是發出匿名提取要求。 若要改善使用公用內容時的可靠性,請在私人 Azure 容器登錄中匯入和管理映像。 深入了解使用公用映像

apiVersion: batch/v1
kind: Job
metadata:
  name: oe-helloworld
  namespace: default
spec:
  template:
    metadata:
      labels:
        app: oe-helloworld
    spec:
      containers:
      - name: oe-helloworld
        image: mcr.microsoft.com/acc/samples/oe-helloworld:latest
        resources:
          limits:
            sgx.intel.com/epc: "10Mi"
          requests:
            sgx.intel.com/epc: "10Mi"
        volumeMounts:
        - name: var-run-aesmd
          mountPath: /var/run/aesmd
      restartPolicy: "Never"
      volumes:
      - name: var-run-aesmd
        hostPath:
          path: /var/run/aesmd
  backoffLimit: 0

也可依下方所示,為容器部署執行節點集區選取範圍部署

apiVersion: batch/v1
kind: Job
metadata:
  name: oe-helloworld
  namespace: default
spec:
  template:
    metadata:
      labels:
        app: oe-helloworld
    spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: agentpool
                operator: In
                values:
                - acc # this is the name of your confidential computing nodel pool
                - acc_second # this is the name of your confidential computing nodel pool
      containers:
      - name: oe-helloworld
        image: mcr.microsoft.com/acc/samples/oe-helloworld:latest
        resources:
          limits:
            sgx.intel.com/epc: "10Mi"
          requests:
            sgx.intel.com/epc: "10Mi"
        volumeMounts:
        - name: var-run-aesmd
          mountPath: /var/run/aesmd
      restartPolicy: "Never"
      volumes:
      - name: var-run-aesmd
        hostPath:
          path: /var/run/aesmd
  backoffLimit: 0

現在,使用 kubectl apply 命令,建立將在安全記憶體保護區中開啟的範例作業,如下列範例輸出所示:

kubectl apply -f hello-world-enclave.yaml
job "oe-helloworld" created

您可以執行下列命令,以確認工作負載已成功建立受信任執行環境 (記憶體保護區):

kubectl get jobs -l app=oe-helloworld
NAME       COMPLETIONS   DURATION   AGE
oe-helloworld   1/1           1s         23s
kubectl get pods -l app=oe-helloworld
NAME             READY   STATUS      RESTARTS   AGE
oe-helloworld-rchvg   0/1     Completed   0          25s
kubectl logs -l app=oe-helloworld
Hello world from the enclave
Enclave called into host to print: Hello World!

清除資源

若要移除在本快速入門中建立的機密運算節點集區,請運用下列命令:

az aks nodepool delete --cluster-name myAKSCluster --name confcompool1 --resource-group myResourceGroup

若要刪除 AKS 叢集,請使用下列命令:

az aks delete --resource-group myResourceGroup --cluster-name myAKSCluster

下一步