编程知识 cdmana.com

Visible cost! A tool to realize k8s resource cost monitoring visualization

This article is from Rancher Labs

Pay attention to our , First time to acquire technology dry goods

Calculation Kubernetes The complexity of the cost

use Kubernetes And a service-based architecture can bring many benefits to the enterprise , For example, teams can migrate faster and applications can be expanded more easily . But this shift also brings some complexity , For example, the visibility of cloud costs . This is because applications and their resource requirements are often dynamic , And the team shares core resources without transparent pricing tied to the workload . Besides , Be fully aware of Kubernetes The advantages of the enterprise will usually run resources on different types of machines , It even runs on multiple cloud providers .

In this paper , We'll learn about how to do business for showback/chargeback The best practice and different implementation methods of project cost monitoring , And how to empower users to take action on this information . We will first understand Kubecost, It provides an open source way to ensure that across all Kubernetes Consistent and accurate visibility of the workload .

Let's learn more about best practices , To accurately allocate and monitor Kubernetes The cost of the workload and related hosting services .

Cost allocation

The precise allocation of resource costs is in Kubernetes The first step in creating cost visibility and efficient cost utilization in the environment .

To do this correctly , You need to allocate costs through a single container at the workload level . When the workload allocation is complete , By aggregating different sets of workloads , Costs can be properly allocated to teams 、 Departments and even individual developers . The cost allocation framework at the workload level is as follows :

Let's take this framework apart a little bit .

The average amount of resources consumed by Kubernetes scheduler For computing or provided by cloud providers , It depends on the specific resource being measured . We suggest that according to request and usage To calculate the maximum of memory and CPU Distribute . In this way, it can be reflected by Kubernetes scheduler The amount of resources reserved by itself . On the other hand , Resources such as load balancers and persistent volumes are strictly based on the amount provided by the provider .

Kubernetes API You can directly calculate the time period of resource consumption . It's up to resources ( Such as memory 、CPU and GPU etc. ) stay Running The time taken by the state determines . To get data to the cloud chargeback It's accurate enough , We suggest that the team combine this data with specific cloud resources provided by cloud providers ( Such as node ) The time taken to coordinate , bring into correspondence with . We'll talk more about this later .

Resource prices are determined by looking at the cost of each particular resource in the environment . for example ,us-east-1 AWS In the region m5.xlarge spot Example of CPU The hourly price is different from the on-demand price of the same instance .

Using this framework, costs can be allocated appropriately between workloads , Then they can pass through any Kubernetes Concept ( Such as namespace 、 label 、 Notes or controller) Easy aggregation .

Kubernetes Cost monitoring

adopt Kubernetes Concept ( Such as pod or controller) Allocated costs , You can start mapping expenditures accurately to any internal business level , Like a team 、 product 、 Department or cost center . The usual way for enterprises is through Kubernetes Namespace to divide the team workload , Others may use Kubernetes Tags or comments to identify which team the workload belongs to .

In different applications 、 Another key factor in cost monitoring between teams, etc. is to determine who should pay for idle capacity . Specifically, it refers to the unused cluster resources that are still being charged to the enterprise . Usually , These costs are either charged to the central infrastructure cost center , Or to the application team on a pro rata basis . Allocate these costs to the team responsible for supply decisions , Adjust incentives to have an efficient scale cluster , So it has a positive effect .

Check the cloud Bill

Kubernetes Provides a lot of real-time data . This gives developers direct access to cost metrics . Although these real-time data are usually accurate , But it may not be completely consistent with the billing data of the cloud provider . for example , In determining AWS spot The hourly rate of the node , Users need to wait Spot Data sources or costs and use reports to determine accurate rates . For billing and charging purposes , You should check the data against the actual Bill .

adopt Kubecost Get better visibility and Governance

We've learned how to look at data to calculate Kubernetes The cost of the workload . Another way is to use Kubecost, This is a cost and capacity management solution based on open source , Provide for the whole of Kubernetes Visibility of the environment .Kubecost by Kubernetes Workloads and the associated management services they consume ( Such as S3 or RDS) Provide cost visibility and insight . This product collects Kubernetes Real-time data , And check with your cloud billing data , To reflect the actual price you paid .

With the image Kubecost Such a solution , You can empower application engineers to make smart real-time decisions , It's an immediate and long-term practice , To optimize and govern cloud spending . This includes cost optimization without compromising performance 、 The implementation of Kubernetes Budget and alert 、showback/chargeback Projects are even cost based automation .

Kubecost The Community Edition is free to use , And it has all the above functions . You can Rancher Find... In the app store Kubecost Helm chart, Deploy easily . With the help of Rancher, You can get Kubernetes Cluster visualization and excellent control experience , meanwhile Kubecost Provides you with a direct view of spending and how to optimize costs . They work together for use Kubernetes The team provided a complete cost management solution .

版权声明
本文为[RancherLabs]所创,转载请带上原文链接,感谢

Scroll to Top