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

在 Azure Kubernetes 服务 (AKS) 中,使用服务标记为 API 服务器指定允许的 IP 范围(预览版)

API 服务器授权 IP 范围的服务标记是一项预览功能,可用于使用服务标记为 Azure Kubernetes 服务(AKS)中的 API 服务器指定授权 IP 范围。 此功能允许你使用预定义的服务标记,而不是手动指定单个 IP 地址或 CIDR 范围,从而简化了授权 IP 范围的管理。

重要

AKS 预览功能可在自助服务和自愿选择的基础上启用。 预览版按“现状”和“视供应情况”提供,它们不包括在服务级别协议和有限保证范围内。 AKS 预览功能是由客户支持尽最大努力部分覆盖。 因此,这些功能并不适合用于生产。 有关详细信息,请参阅以下支持文章:

先决条件

局限性

  • 此功能与 API Server VNet 集成不兼容。
  • --api-server-authorized-ip-ranges 参数中只允许一个服务标记。 不能指定多个服务标记。

安装 aks-preview Azure CLI 扩展

  1. 使用 az extension add 命令安装 Azure CLI 预览扩展。

    az extension add --name aks-preview
    
  2. 使用 az extension update 命令更新,确保拥有最新版本的扩展。

    az extension update --name aks-preview
    

注册服务标记授权 IP 功能标志

  1. 使用 EnableServiceTagAuthorizedIPPreview 命令注册 az feature register 功能标志。 只需几分钟时间即可完成注册。

    az feature register --namespace "Microsoft.ContainerService" --name "EnableServiceTagAuthorizedIPPreview"
    

    示例输出:

    {
      "id": "/subscriptions/<subscription-id>/providers/Microsoft.ContainerService/features/EnableServiceTagAuthorizedIPPreview",
      "name": "EnableServiceTagAuthorizedIPPreview",
      "properties": {
        "state": "Registering"
      },
      "type": "Microsoft.ContainerService/features"
    }
    
  2. 当功能标志状态从Registering更改为Registered时,使用az provider register命令刷新Microsoft.ContainerService资源提供程序的注册。

    az provider register --namespace "Microsoft.ContainerService"
    
  3. 使用 az feature show 命令验证注册。

    az feature show --namespace "Microsoft.ContainerService" --name "EnableServiceTagAuthorizedIPPreview"
    

    示例输出:

    {
      "id": "/subscriptions/<subscription-id>/providers/Microsoft.ContainerService/features/EnableServiceTagAuthorizedIPPreview",
      "name": "EnableServiceTagAuthorizedIPPreview",
      "properties": {
        "state": "Registered"
      },
      "type": "Microsoft.ContainerService/features"
    }
    

创建具有服务标记授权 IP 范围的 AKS 群集

  • 使用 az aks create 命令和 --api-server-authorized-ip-ranges 参数创建具有服务标记授权 IP 范围的群集。 以下示例在 myResourceGroup 资源组中创建名为 myAKSCluster 的群集,并授权AzureCloud服务标记允许所有 Azure 服务访问 API 服务器并指定额外的 IP 地址:

    az aks create --resource-group myResourceGroup --name myAKSCluster --api-server-authorized-ip-ranges AzureCloud,20.20.20.20
    

    注释

    你应该能够从属于 AzureCloud 服务标记的 Azure 虚拟机 (VM) 或 Azure 服务中通过 curl 访问 API 服务器。