部署到 Azure Kubernetes 服务Deploy to Azure Kubernetes Service

本文提供将 Azure API 管理的自承载网关组件部署到 Azure Kubernetes 服务的步骤。This article provides the steps for deploying self-hosted gateway component of Azure API Management to Azure Kubernetes Service. 若要了解如何将自承载网关部署到 Kubernetes 群集,请参阅此文档For deploying self-hosted gateway to a Kubernetes cluster see thisdocument.

先决条件Prerequisites

将自承载网关部署到 AKSDeploy the self-hosted gateway to AKS

  1. 在“设置”下选择“网关”。 Select Gateways from under Settings.
  2. 选择要部署的自承载网关资源。Select the self-hosted gateway resource you intend to deploy.
  3. 选择“部署”。Select Deployment.
  4. 请注意,“令牌”文本框中已自动生成使用默认“过期时间”和“机密密钥”值的新令牌。 Note that a new token in the Token text box was autogenerated for you using the default Expiry and Secret Key values. 根据需要调整其中的一个或两个值,然后选择“生成”以创建新令牌。Adjust either or both if desired and select Generate to create a new token.
  5. 确保在“部署脚本”下选择“Kubernetes”。 Make sure Kubernetes is selected under Deployment scripts.
  6. 选择“部署”旁边的“<网关名称>.yml”文件链接以下载该文件。 Select .yml file link next to Deployment to download the file.
  7. 在该 yml 文件中根据需要调整端口映射和容器名称。Adjust the port mappings and container name in the yml file as needed.
  8. 根据你的方案,你可能需要更改服务类型Depending on your scenario, you might need to change the service type. 默认值为 NodePortThe default value is NodePort.
  9. 选择“部署”文本框右侧的“复制”图标,将 kubectl 命令保存到剪贴板。 Select the copy icon located at the right end of the Deploy text box to save the kubectl command to clipboard.
  10. 将该命令粘贴到终端(或命令)窗口。Paste the command to the terminal (or command) window. 请注意,该命令要求下载的环境文件位于当前目录中。Note that the command expects the downloaded environment file to be present in the current directory.
    kubectl apply -f <gateway-name>.yaml
  1. 执行命令。Execute the command. 该命令指示 AKS 群集使用从 Microsoft 容器注册表下载的自承载网关映像运行容器,并将该容器配置为公开 HTTP (8080) 和 HTTPS (443) 端口。The command instructs your AKS cluster to run the container, using self-hosted gateway's image downloaded from the Microsoft Container Registry, and to configure the container to expose HTTP (8080) and HTTPS (443) ports.
  2. 运行以下命令来检查网关 pod 是否正在运行。Run the below command to check the gateway pod is running. 请注意,你的 pod 名称与此不同。Note that your pod name will be different.
kubectl get pods
NAME                                   READY     STATUS    RESTARTS   AGE
contoso-apim-gateway-59f5fb94c-s9stz   1/1       Running   0          1m
  1. 运行以下命令来检查网关服务是否正在运行。Run the below command to check the gateway service is running. 请注意,你的服务名称和 IP 地址与此不同。Note that your service name and IP addresses will be different.
kubectl get services
NAME             TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)                      AGE
contosogateway   NodePort    10.110.230.87   <none>        80:32504/TCP,443:30043/TCP   1m
  1. 返回 Azure 门户,确认刚刚部署的网关节点是否报告正常状态。Go back to the Azure portal and confirm that gateway node you just deployed is reporting healthy status.

提示

使用 kubectl logs 命令查看自承载网关日志的快照。Use kubectl logs command to view a snapshot of self-hosted gateway log.

后续步骤Next steps