This page shows you how to control the compute infrastructure and autoscaling behavior of Google Kubernetes Engine (GKE) clusters based on the specific needs of your workloads by using custom compute classes. You should already be familiar with the concept of custom compute classes. For details, see About custom compute classes.
This page is intended for platform administrators who want to declaratively define autoscaling profiles for nodes, and for cluster operators who want to run their workloads on specific compute classes.
About custom compute classesCustom compute classes are Kubernetes Custom Resources that let you define priorities for GKE to follow when provisioning nodes to run your workloads. You can use a custom compute class to do the following:
To understand all of the configuration options and how they interact with each other and with GKE Autopilot mode and GKE Standard mode, see About custom compute classes.
PricingThe ComputeClass
custom resource is provided at no extra cost in GKE. The following pricing considerations apply:
GKE Autopilot mode: you're billed using the node-based billing mode. For details, see Autopilot mode pricing.
GKE Standard mode: see Standard mode pricing.
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.This page presents an example scenario for which you define a custom compute class. In practice, you should consider the requirements of your specific workloads and organization, and define compute classes that meet those requirements. For full descriptions of all of the options for compute classes, and for special considerations, see About custom compute classes.
Consider the following example scenario:
Based on the example scenario, you decide that you want a compute class that does the following:
In GKE Autopilot, you define a compute class, deploy it to the cluster, and request that compute class in your workloads. GKE performs any node configuration steps, like applying labels and taints, for you.
Save the following manifest as compute-class.yaml
:
apiVersion: cloud.google.com/v1
kind: ComputeClass
metadata:
name: cost-optimized
spec:
priorities:
- machineFamily: n2
spot: true
minCores: 64
- machineFamily: n2
spot: true
- machineFamily: n2
spot: false
activeMigration:
optimizeRulePriority: true
nodePoolAutoCreation:
enabled: true
Configure a compute class in Standard mode
In GKE Standard mode clusters, you define a compute class, after which you might have to perform manual configuration to ensure that your compute class Pods schedule as expected. Manual configuration depends on whether your node pools are automatically provisioned, as follows:
Pending
state. Conversely, if you associate every node pool with a specific compute class, Pods that request a different compute class and Pods that don't request a compute class remain stuck in the Pending
state. Use compute classes with manually-created node pools
This section shows you how to define a compute class in a cluster that only uses manually-created node pools.
Save the following manifest as compute-class.yaml
:
apiVersion: cloud.google.com/v1
kind: ComputeClass
metadata:
name: cost-optimized
spec:
priorities:
- machineFamily: n2
spot: true
minCores: 64
- machineFamily: n2
spot: false
activeMigration:
optimizeRulePriority: true
Create a new autoscaled node pool that uses Spot VMs and associate it with the compute class:
gcloud container node-pools create cost-optimized-pool \
--location=LOCATION \
--cluster=CLUSTER_NAME \
--machine-type=n2-standard-64 \
--spot \
--enable-autoscaling \
--max-nodes=9 \
--node-labels="cloud.google.com/compute-class=cost-optimized" \
--node-taints="cloud.google.com/compute-class=cost-optimized:NoSchedule"
Replace the following:
LOCATION
: the location of your cluster.CLUSTER_NAME
: the name of your existing cluster.Create a new autoscaled node pool with on-demand VMs and associate it with the compute class:
gcloud container node-pools create on-demand-pool \
--location=LOCATION \
--cluster=CLUSTER_NAME \
--machine-type=n2-standard-64 \
--enable-autoscaling \
--max-nodes=9 \
--num-nodes=0 \
--node-labels="cloud.google.com/compute-class=cost-optimized" \
--node-taints="cloud.google.com/compute-class=cost-optimized:NoSchedule"
When you deploy Pods that request this compute class and new nodes need to be created, GKE prioritizes creating nodes in the cost-optimized-pool
node pool. If new nodes can't be created, GKE creates nodes in the on-demand-pool
node pool.
For more details about how manually-created node pools interact with custom compute classes, see Configure manually-created node pools for compute class use.
Use compute classes with auto-provisioned node poolsThis section shows you how to define a compute class in a cluster that uses node auto-provisioning.
Save the following manifest as compute-class.yaml
:
apiVersion: cloud.google.com/v1
kind: ComputeClass
metadata:
name: cost-optimized
spec:
priorities:
- machineFamily: n2
spot: true
minCores: 64
- machineFamily: n2
spot: true
- machineFamily: n2
spot: false
activeMigration:
optimizeRulePriority: true
nodePoolAutoCreation:
enabled: true
When you deploy Pods that request this compute class and new nodes need to be created, GKE prioritizes creating nodes in the order items in the priorities
field. If required, GKE creates new node pools that meet the hardware requirements of the compute class.
For more details about how node auto-provisioning works with custom compute classes, see Node auto-provisioning and compute classes.
Customize autoscaling thresholds for node consolidationBy default, GKE removes underutilized nodes and reschedules your workloads onto other available nodes. You can further customize the thresholds and timing after which a node becomes a candidate for removal by using the autoscalingPolicy
field in the compute class definition, like in the following example:
apiVersion: cloud.google.com/v1
kind: ComputeClass
metadata:
name: cost-optimized
spec:
priorities:
- machineFamily: n2
spot: true
minCores: 64
- machineFamily: n2
spot: true
- machineFamily: n2
spot: false
activeMigration:
optimizeRulePriority: true
autoscalingPolicy:
consolidationDelayMinutes : 5
consolidationThreshold : 70
This example makes a node become a candidate for removal if it's underutilized by 70% of its available CPU and memory capacity for more than five minutes. For a list of available parameters, see Set autoscaling parameters for node consolidation.
Deploy a compute class in a clusterAfter you define a compute class, deploy it to the cluster:
kubectl apply -f compute-class.yaml
This compute class is ready to use in the cluster. You can request the compute class in Pod specifications or, optionally, set it as the default compute class in a specific namespace.
Request a compute class in a workloadTo request a compute class in a workload, add a node selector for that compute class in your manifest.
Save the following manifest as cc-workload.yaml
:
apiVersion: apps/v1
kind: Deployment
metadata:
name: custom-workload
spec:
replicas: 2
selector:
matchLabels:
app: custom-workload
template:
metadata:
labels:
app: custom-workload
spec:
nodeSelector:
cloud.google.com/compute-class: cost-optimized
containers:
- name: test
image: gcr.io/google_containers/pause
resources:
requests:
cpu: 1.5
memory: "4Gi"
Deploy the workload:
kubectl apply -f cc-workload.yaml
When you deploy this workload, GKE automatically adds a toleration to the Pods that corresponds to the node taint for the requested compute class. This toleration ensures that only Pods that request the compute class run on compute class nodes.
Update a deployed compute classTo update a deployed compute class, modify the YAML manifest for the ComputeClass. Then, deploy the modified manifest by running the following command:
kubectl apply -f PATH_TO_FILE
Replace PATH_TO_FILE
with the path to your modified manifest. Ensure that the value in the name
field remains unchanged.
When you deploy your updated compute class, GKE uses your updated configuration to create new nodes. GKE doesn't modify any existing nodes with your updated configuration.
Over time, GKE might move existing Pods to nodes that use your updated configuration if the compute class uses active migration and if the existing Pods are eligible to migrate.
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