你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

快速入门:使用 Azure CLI 部署具有机密计算 Intel SGX 代理节点的 AKS 群集

在本快速入门中,我们将使用 Azure CLI 部署具有 Enclave 感知 (DCsv2/DCSv3) VM 节点的 Azure Kubernetes 服务 (AKS) 群集。 然后,在 enclave 中运行一个简单的 Hello World 应用程序。 你还可通过 Azure 门户预配群集并添加机密计算节点,但本快速入门重点介绍 Azure CLI。

AKS 是一种使开发人员或群集操作员能够快速部署和管理群集的托管 Kubernetes 服务。 要了解详细信息,请参阅 AKS 简介AKS 机密节点概述

机密计算节点的功能包括:

  • 支持 Linux 容器的 Linux 工作器节点。
  • 带有 Ubuntu 18.04 虚拟机 (VM) 节点的第 2 代 VM。
  • 支持 Intel SGX 的 CPU,它利用加密页高速缓存 (EPC) 来帮助在受机密性保护的 enclave 中运行容器。 有关详细信息,请参阅 Azure 机密计算常见问题解答
  • 在机密计算节点上预装了 Intel SGX DCAP 驱动程序。 有关详细信息,请参阅 Azure 机密计算常见问题解答

注意

DCsv2/DCsv3 VM 使用可用性取决于区域的专用硬件。 有关详细信息,请参阅可用的 SKU 和受支持的区域

先决条件

本快速入门需要:

  • 你的订阅中最少有八个 DCsv2/DCSv3/DCdsv3 核心可供使用。

    默认情况下,Azure 订阅的 Intel SGX VM 大小没有预先分配的配额。 你应按照这些说明来为你的订阅请求 VM 核心配额。

创建具有 Enclave 意识的机密计算节点和 Intel SGX 加载项的 AKS 群集

根据以下说明创建启用了 Intel SGX 加载项的 AKS 群集,向群集中添加节点池,并使用 hello world enclave 应用程序验证你创建的内容。

创建具有系统节点池和 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 群集

运行以下命令,在 AKS 群集中添加大小为 Standard_DC4s_v3 且具有三个节点的用户节点池。 可以从受支持的 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 命令验证是否正确创建了节点,以及与 SGX 相关的 DaemonSet 是否在 DCsv2 节点池上运行:

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

如果输出与前面的代码匹配,那 AKS 群集现在就可以运行机密应用程序了。

你可以转到本快速入门的通过独立的 enclave 应用程序部署 Hello World 部分,在 enclave 中测试应用。 或根据以下说明在 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 群集现在就可以运行机密应用程序了。

通过独立的 enclave 应用程序部署 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 命令创建一个将在安全 enclave 中打开的示例作业,如以下示例输出所示:

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

可运行以下命令来确认工作负载是否已成功创建受信任执行环境 (enclave):

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

后续步骤