将 Azure Kubernetes 服务与 Azure Database for PostgreSQL - 单一服务器连接Connecting Azure Kubernetes Service and Azure Database for PostgreSQL - Single Server

Azure Kubernetes 服务 (AKS) 提供可在 Azure 中使用的托管 Kubernetes 群集。Azure Kubernetes Service (AKS) provides a managed Kubernetes cluster you can use in Azure. 下面是将 AKS 和 Azure Database for PostgreSQL 一起使用以创建应用程序时要考虑的一些选项。Below are some options to consider when using AKS and Azure Database for PostgreSQL together to create an application.

加速网络Accelerated networking

在 AKS 群集中使用支持加速网络的底层 VM。Use accelerated networking-enabled underlying VMs in your AKS cluster. 在 VM 上启用加速网络时,可以降低延迟、降低抖动和降低 VM 上的 CPU 利用率。When accelerated networking is enabled on a VM, there is lower latency, reduced jitter, and decreased CPU utilization on the VM. 详细了解加速网络的工作原理、支持的 OS 版本以及 Linux 支持的 VM 实例。Learn more about how accelerated networking works, the supported OS versions, and supported VM instances for Linux.

从 2018 年 11 月起,AKS 支持在这些受支持的 VM 实例上启用加速网络。From November 2018, AKS supports accelerated networking on those supported VM instances. 默认情况下,加速网络已在使用这些 VM 的新 AKS 群集上启用。Accelerated networking is enabled by default on new AKS clusters that use those VMs.

可以确认 AKS 群集是否已加速了网络:You can confirm whether your AKS cluster has accelerated networking:

  1. 转到 Azure 门户并选择 AKS 群集。Go to the Azure portal and select your AKS cluster.
  2. 选择“属性”选项卡。Select the Properties tab.
  3. 复制基础结构资源组的名称。Copy the name of the Infrastructure Resource Group.
  4. 使用门户搜索栏找到并打开基础结构资源组。Use the portal search bar to locate and open the infrastructure resource group.
  5. 在该资源组中选择一个 VM。Select a VM in that resource group.
  6. 转到 VM 的“网络” 选项卡。Go to the VM's Networking tab.
  7. 确认是否已启用加速网络Confirm whether Accelerated networking is 'Enabled.'

也可以通过 Azure CLI 使用以下两个命令:Or through the Azure CLI using the following two commands:

az aks show --resource-group myResourceGroup --name myAKSCluster --query "nodeResourceGroup"

输出将是 AKS 创建的包含网络接口的生成资源组。The output will be the generated resource group that AKS creates containing the network interface. 获取“nodeResourceGroup”名称并在下一个命令中使用它。Take the "nodeResourceGroup" name and use it in the next command. EnableAcceleratedNetworking 将是 true 或 false:EnableAcceleratedNetworking will either be true or false:

az network nic list --resource-group nodeResourceGroup -o table

连接池Connection pooling

在创建和关闭到数据库的新连接时,连接池程序可以尽量减少相关的成本和时间。A connection pooler minimizes the cost and time associated with creating and closing new connections to the database. 该池是可以重复使用的连接的集合。The pool is a collection of connections that can be reused.

可以将多个连接池程序与 PostgreSQL 配合使用。There are multiple connection poolers you can use with PostgreSQL. 其中一个是 PgBouncerOne of these is PgBouncer. 在 Microsoft 容器注册表中,我们提供一个轻量型容器化 PgBouncer,它可以在挎斗中用来池化从 AKS 到 Azure Database for PostgreSQL 的连接。In the Microsoft Container Registry, we provide a lightweight containerized PgBouncer that can be used in a sidecar to pool connections from AKS to Azure Database for PostgreSQL. 请访问 Docker 中心页,了解如何访问并使用此映像。Visit the docker hub page to learn how to access and use this image.

后续步骤Next steps