This page shows you how get key spending insights to inform your resource allocation and cost optimization decisions using Google Kubernetes Engine (GKE) cost allocation. Learn about the difference between GKE cost allocation and cluster usage metering, limitations of GKE cost allocation, how to activate GKE cost allocation on both new and existing clusters, and how to filter and query your Cloud Billing BigQuery export.
This page is for Operators, Cloud architects, Developers, and Data administrators who need to manage costs as they create and configure clusters and deploy workloads in GKE. To learn more about common roles, see Common GKE user roles and tasks.
Before reading this page, you might want to familiarize yourself with Best practices for running cost-optimized Kubernetes applications on GKE
Potential data volume increaseEnabling GKE cost allocation can increase your storage and querying costs in BigQuery. The exact increase depends on the number of distinct label and namespace combinations you use across Pods and clusters.
Enabling GKE cost allocation does not change the total cost of your GKE usage. The sum of the cost line items in your export is the same and existing queries and reports you have built on the billing export return the same values.
GKE cost allocation and cluster usage meteringGKE cost allocation is different from cluster usage metering in the following ways:
Before you start, make sure that you have performed the following tasks:
gcloud components update
. Note: For existing gcloud CLI installations, make sure to set the compute/region
property. If you use primarily zonal clusters, set the compute/zone
instead. By setting a default location, you can avoid errors in the gcloud CLI like the following: One of [--zone, --region] must be supplied: Please specify location
. You might need to specify the location in certain commands if the location of your cluster differs from the default that you set.PersistentVolume
resources provisioned dynamically through PersistentVolumeClaims
or Generic Ephemeral Volumes.PersistentVolume
resources provisioned by the Compute Engine persistent disk CSI driver or with the deprecated kubernetes.io/gce-pd
storage plugin with ReadWriteOnce
or ReadWriteOncePod
access mode.When you enable GKE cost allocation, the cluster name and namespace of your GKE workloads appear in the labels
field of the billing export to BigQuery:
labels.key
) Resource label value (labels.value
) Description Kubernetes labels have the following format: k8s-label/${k8s-label-key}
, where ${k8s-label-key}
is the key of the Pod's Kubernetes label. The billing label k8s-label/${k8s-label-key}
has the same value as the corresponding Kubernetes Pod label. If a Kubernetes label key collides with a VM label key, the Kubernetes label value overrides the VM label value. Cluster and node pool resource labels are applied to resources using the following priority from highest to lowest:
goog-k8s-cluster-name
[cluster-name] Namespace k8s-namespace
[namespace] Workload type k8s-workload-type
[workload-type]
apps/v1-Deployment
,apps/v1-StatefulSet
,apps/v1-DaemonSet
,apps/v1-ReplicaSet
,batch/v1-Job
,batch/v1-CronJob
,core/v1-Pod
) Workload name k8s-workload-name
[workload-name]
For more information, see Schema of the detailed usage cost data.
Additionally, the following namespaces are used to track overhead and unallocated resources:
kube:system-overhead
: This accounts for node resources that are not available to Pods. These resources are set aside by the system for running the Kubernetes framework (including but not limited to kubelet, kube-proxy, containerd). This is the difference between the Node's capacity and allocatable resources.kube:unallocated
: Resources are neither requested by workloads nor requested for system overhead.If GKE cannot determine the cost allocation for a resource, the export includes one of the following values:
goog-k8s-unknown
: Cloud Billing couldn't process the SKU. This can occur when a new Compute Engine instance is being provisioned. You can expect some goog-k8s-unknown
values during node startup and shutdown, for example when GKE autoscales a cluster.goog-k8s-unsupported-sku
: GKE cost allocation does not support this SKU. Treat this the same as <blank>
/NULL
. There is no guarantee that a SKU is always labeled with this value.<blank>
/NULL
: GKE cost allocation does not track this resource. This can occur when GKE cost allocation is not enabled, or the resource does not belong to a GKE managed cluster.Costs for Persistent Disks are tracked when the Persistent Disk's backing PersistentVolumeClaims
are claimed by Pods. The Persistent Disk costs inherit all of the metadata, such as Pod labels and namespaces, of the claiming Pod, until their PersistentVolumeClaims
are deleted. For PersistentVolumeClaims
that are deleted but retain PersistentVolumes
according to the reclaim policy, costs of the Persistent Disks are tracked as unallocated.
Labels applied directly to PersistentVolumeClaims
do not appear in the Cloud Billing section of the Google Cloud console or the Cloud Billing detailed export.
For Extended RAM, the same proportion of total cost is allocated to a workload for both the Regular RAM and Extended RAM SKUs based on the resource requested.
Enable GKE cost allocationYou can enable GKE cost allocation on a new or existing cluster using the gcloud CLI or the Google Cloud console.
gcloudUpdate a cluster using the --enable-cost-allocation
flag:
gcloud container clusters update CLUSTER_NAME \
--enable-cost-allocation
Replace CLUSTER_NAME
with the name of the cluster.
You can also use the --enable-cost-allocation
flag when you create a new cluster by using the gcloud container clusters create
command.
To enable GKE cost allocation on an existing cluster, do the following:
Describe the cluster:
gcloud container clusters describe CLUSTER_NAME
The output is similar to the following:
...
costManagementConfig:
enabled: true
...
In this output, costManagementConfig
indicates that GKE cost allocation is enabled.
To check if GKE cost allocation is enabled on an existing cluster, do the following:
The following example queries show you how to filter and group your GKE costs for supported resource types by cluster name, namespace, and label.
Get costs after credits by namespaceSELECT labels.value as namespace, SUM(cost) + SUM(IFNULL((SELECT SUM(c.amount) FROM UNNEST(credits) c), 0)) AS cost_after_credits, FROM `project-ID.dataset.gcp_billing_export_resource_v1_XXXXXX-XXXXXX-XXXXXX` LEFT JOIN UNNEST(labels) as labels ON labels.key = "k8s-namespace" GROUP BY namespace ;Get cluster costs before credits
SELECT SUM(cost) AS cost_before_credits, labels.value AS cluster_name FROM `project-ID.dataset.gcp_billing_export_resource_v1_XXXXXX-XXXXXX-XXXXXX` LEFT JOIN UNNEST(labels) as labels ON labels.key = "goog-k8s-cluster-name" GROUP BY labels.value ;
SELECT project.id AS project_id, labels.value AS cluster_name, sku.id AS sku_id, sku.description AS sku_description, SUM(cost) AS cost FROM `project-ID.dataset.gcp_billing_export_resource_v1_XXXXXX-XXXXXX-XXXXXX` JOIN UNNEST(labels) AS labels ON labels.key = "goog-k8s-cluster-name" GROUP BY cluster_name, project_id, sku_description, sku_id ;
Replace BILLING_DATASET_TABLE
with the name of the dataset that you created in BigQuery.
The table name is similar to gcp_billing_export_resource_v1_<BILLING_ACCOUNT_ID>
.
To avoid incurring charges to your Google Cloud account for the resources used in this page, disable GKE cost allocation for the cluster:
gcloud container clusters update CLUSTER_NAME \
--no-enable-cost-allocation
You can also delete the cluster that you created.
What's nextRetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4