Azure Kubernetes 服务 (AKS) 中的可持续软件工程原则Sustainable software engineering principles in Azure Kubernetes Service (AKS)

可持续软件工程原则是一组可帮助你定义、构建和运行可持续应用程序的能力。The sustainable software engineering principles are a set of competencies to help you define, build, and run sustainable applications. 总体目标是降低应用程序每个方面的碳足迹。The overall goal is to reduce your carbon footprint of every aspect of your application. 可持续软件工程的原则概述了可持续软件工程的原则。The Principles of Sustainable Software Engineering has an overview of the principles of sustainable software engineering.

可持续软件工程是优先级和重心的转移。Sustainable software engineering is a shift in priorities and focus. 在许多情况下,大多数软件的设计和运行方式都着重于高性能和低延迟。In many cases, the way most software is designed and run highlights fast performance and low latency. 可持续软件工程致力于减少尽可能多的碳排放。Meanwhile, sustainable software engineering focuses on reducing as much carbon emission as possible. 请注意以下几点:Consider:

  • 应用可持续软件工程原则可以提高性能或降低延迟,例如,降低总体网络行程就可以实现该目标。Applying sustainable software engineering principles can give you faster performance or lower latency, such as by lowering total network travel.

将可持续软件工程原则应用到应用程序之前,请查看应用程序的优先级、需求和利弊。Before applying sustainable software engineering principles to your application, review the priorities, needs, and trade-offs of your application.

度量和优化Measure and optimize

若要降低 AKS 群集的碳足迹,你需要了解群集资源的使用方式。To lower the carbon footprint of your AKS clusters, you need understand how your cluster's resources are being used. Azure Monitor 提供有关群集资源使用情况的详细信息,例如内存和 CPU 使用率。Azure Monitor provides details on your cluster's resource usage, such as memory and CPU usage. 可根据这些数据做决定,以减少群集的碳足迹并观察所做更改的效果。This data informs your decision to reduce the carbon footprint of your cluster and observes the effect of your changes.

你还可以安装 Microsoft 可持续性计算器,以查看所有 Azure 资源的碳足迹。You can also install the Microsoft Sustainability Calculator to see the carbon footprint of all your Azure resources.

提高资源利用率Increase resource utilization

减少碳足迹的一种方法是缩短空闲时间。One approach to lowering your carbon footprint is to reduce your idle time. 缩短空闲时间涉及提高计算资源的利用率。Reducing your idle time involves increasing the utilization of your compute resources. 例如:For example:

  1. 群集有四个节点,每个节点以 50% 的容量运行。You had four nodes in your cluster, each running at 50% capacity. 因此,所有四个节点都有 50% 的未使用容量保持空闲状态。So, all four of your nodes have 50% unused capacity remaining idle.
  2. 将群集减少到三个节点,则具有相同工作负载的每个节点以 67% 的容量运行。You reduced your cluster to three nodes, each running at 67% capacity with the same workload. 如果成功地将每个节点上未使用的容量减少到 33%,则可以提高利用率。You would have successfully decreased your unused capacity to 33% on each node and increased your utilization.

重要

在考虑更改群集中的资源时,请验证系统池是否具有足够的资源来维持群集的核心系统组件的稳定性。When considering changing the resources in your cluster, verify your system pools have enough resources to maintain the stability of your cluster's core system components. 永远不要将群集的资源减少到群集可能会变得不稳定的程度。Never reduce your cluster's resources to the point where your cluster may become unstable.

查看群集利用率之后,请考虑使用多节点池提供的功能:After reviewing your cluster's utilization, consider using the features offered by multiple node pools:

  • 节点大小调整Node sizing

    使用节点大小调整通过特定的 CPU 和内存配置文件定义节点池,以便根据工作负载需求定制节点。Use node sizing to define node pools with specific CPU and memory profiles, allowing you to tailor your nodes to your workload needs. 根据工作负载需求调整节点大小,你可以在运行较少节点的情况下提高利用率。By sizing your nodes to your workload needs, you can run a few nodes at higher utilization.

  • 群集缩放Cluster scaling

    配置群集的缩放方式。Configure how your cluster scales. 使用水平 Pod 自动缩放程序群集自动缩放程序基于配置自动缩放群集。Use the horizontal pod autoscaler and the cluster autoscaler to scale your cluster automatically based on your configuration. 控制群集的缩放方式,以使所有节点保持以高利用率运行,同时与对群集工作负载的更改保持同步。Control how your cluster scales to keep all your nodes running at a high utilization while staying in sync with changes to your cluster's workload.

最后在应用程序的 Kubernetes 清单中查看 CPU 和内存请求与限制 。Finally, review the CPU and memory requests and limits in the Kubernetes manifests of your applications.

  • 由于你降低了内存和 CPU 值,因此有更多的内存和 CPU 可供群集用来运行其他工作负载。As you lower memory and CPU values, more memory and CPU are available to the cluster to run other workloads.
  • 由于你以较少的 CPU 和内存运行较多的工作负载,因此可以更加密集地分配你的群集,从而提高利用率。As you run more workloads with lower CPU and memory, your cluster becomes more densely allocated, which increases your utilization.

减少应用程序的 CPU 和内存时,如果将 CPU 和内存值设置得太低,应用程序的行为可能会降级或变得不稳定。When reducing the CPU and memory for your applications, your applications' behavior may become degraded or unstable if you set CPU and memory values too low. 在更改 CPU 和内存请求以及限制之前,请运行一些基准测试以验证是否正确设置了这些值 。Before changing the CPU and memory requests and limits, run some benchmarking tests to verify if the values are set appropriately. 切勿将这些值降低到应用程序不稳定的程度。Never reduce these values to the point of application instability.

减少网络行程Reduce network travel

通过减少请求并响应往返群集的距离,可以减少联网设备的碳排放和电力消耗。By reducing requests and responses travel distance to and from your cluster, you can reduce carbon emissions and electricity consumption by networking devices. 查看网络流量后,请考虑在更靠近你的网络流量来源的区域中创建群集。After reviewing your network traffic, consider creating clusters in regions closer to the source of your network traffic. 可以使用 Azure 流量管理器将流量路由到最近的群集和邻近放置组,并缩短 Azure 资源之间的距离。You can use Azure Traffic Manager to route traffic to the closest cluster and proximity placement groups and reduce the distance between Azure resources.

重要

考虑对群集的网络进行更改时,切勿以必须满足的工作负荷要求为代价来减少网络行程。When considering making changes to your cluster's networking, never reduce network travel at the cost of meeting workload requirements.

需求调整Demand shaping

如果可能,请考虑将对群集资源的需求转移到可以使用过量容量的时间或区域。Where possible, consider shifting demand for your cluster's resources to times or regions where you can use excess capacity. 例如,考虑更改要运行的批处理作业的时间或区域。For example, consider changing the time or region for a batch job to run. 还应考虑重构你的应用程序,以使用队列来延迟运行不需要立即处理的工作负荷。Also consider refactoring your application to use a queue to defer running workloads that don't need immediate processing.

  • 更改要运行的批处理作业的时间或区域。Changing the time or region for a batch job to run.

  • 重构你的应用程序,以使用队列来延迟运行不需要立即处理的工作负载。Refactoring your application to use a queue to defer running workloads that don't need immediate processing.

后续步骤Next steps

详细了解本文中提到的 AKS 的功能:Learn more about the features of AKS mentioned in this article: