-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example for custom compute classes reservations. (#1542)
- Loading branch information
Showing
10 changed files
with
348 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Custom compute classes reservations example | ||
|
||
[](https://ssh.cloud.google.com/cloudshell/editor?cloudshell_git_repo=https://github.com/GoogleCloudPlatform/kubernetes-engine-samples&cloudshell_workspace=autoscaling/custom-compute-classes/reservations) | ||
|
||
This example shows how to utilize custom compute classes in order to consume reservation capacity for the workloads. | ||
Learn more about custom compute classes - https://cloud.google.com/kubernetes-engine/docs/concepts/about-custom-compute-classes |
30 changes: 30 additions & 0 deletions
30
autoscaling/custom-compute-classes/reservations/ccc-any-reservation.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Copyright 2024 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# [START gke_autoscaling_ccc_any_reservation] | ||
apiVersion: cloud.google.com/v1 | ||
kind: ComputeClass | ||
metadata: | ||
name: ccc-reservations | ||
spec: | ||
nodePoolAutoCreation: | ||
enabled: true | ||
priorities: | ||
- machineType: ${MACHINE_TYPE} | ||
reservations: | ||
affinity: AnyBestEffort | ||
whenUnsatisfiable: DoNotScaleUp | ||
# [END gke_autoscaling_ccc_any_reservation] | ||
--- | ||
|
35 changes: 35 additions & 0 deletions
35
autoscaling/custom-compute-classes/reservations/ccc-gpu-reservation.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Copyright 2024 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# [START gke_autoscaling_ccc_gpu_reservation] | ||
apiVersion: cloud.google.com/v1 | ||
kind: ComputeClass | ||
metadata: | ||
name: ccc-reservations | ||
spec: | ||
nodePoolAutoCreation: | ||
enabled: true | ||
priorities: | ||
- machineType: ${MACHINE_TYPE} | ||
gpu: | ||
type: ${ACCELERATOR_TYPE} | ||
count: ${ACCELERATOR_COUNT} | ||
reservations: | ||
specific: | ||
- name: ${RESERVATION_NAME} | ||
affinity: Specific | ||
whenUnsatisfiable: DoNotScaleUp | ||
# [END gke_autoscaling_ccc_gpu_reservation] | ||
--- | ||
|
40 changes: 40 additions & 0 deletions
40
autoscaling/custom-compute-classes/reservations/ccc-local-shared-spot.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Copyright 2024 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# [START gke_autoscaling_ccc_local_shared_spot] | ||
apiVersion: cloud.google.com/v1 | ||
kind: ComputeClass | ||
metadata: | ||
name: ccc-reservations | ||
spec: | ||
nodePoolAutoCreation: | ||
enabled: true | ||
priorities: | ||
- machineType: ${MACHINE_TYPE} | ||
reservations: | ||
specific: | ||
- name: ${RESERVATION_NAME} | ||
affinity: Specific | ||
- machineType: ${MACHINE_TYPE} | ||
reservations: | ||
specific: | ||
- name: ${SHARED_RESERVATION_NAME | ||
project: ${SHARED_RESERVATION_PROJECT} | ||
affinity: Specific | ||
- machineType: ${MACHINE_TYPE} | ||
spot: true | ||
whenUnsatisfiable: DoNotScaleUp | ||
# [END gke_autoscaling_ccc_local_shared_spot] | ||
--- | ||
|
34 changes: 34 additions & 0 deletions
34
autoscaling/custom-compute-classes/reservations/ccc-specific-reservation.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Copyright 2024 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# [START gke_autoscaling_ccc_specific_reservation] | ||
apiVersion: cloud.google.com/v1 | ||
kind: ComputeClass | ||
metadata: | ||
name: ccc-reservations | ||
spec: | ||
nodePoolAutoCreation: | ||
enabled: true | ||
priorities: | ||
- machineType: ${MACHINE_TYPE} | ||
reservations: | ||
specific: | ||
- name: ${RESERVATION_NAME} | ||
- name: ${SHARED_RESERVATION_NAME | ||
project: ${SHARED_RESERVATION_PROJECT | ||
affinity: Specific | ||
whenUnsatisfiable: DoNotScaleUp | ||
# [END gke_autoscaling_ccc_specific_reservation] | ||
--- | ||
|
34 changes: 34 additions & 0 deletions
34
autoscaling/custom-compute-classes/reservations/ccc-ssd-reservation.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Copyright 2024 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# [START gke_autoscaling_ccc_ssd_reservation] | ||
apiVersion: cloud.google.com/v1 | ||
kind: ComputeClass | ||
metadata: | ||
name: ccc-reservations | ||
spec: | ||
nodePoolAutoCreation: | ||
enabled: true | ||
priorities: | ||
- machineType: ${MACHINE_TYPE} | ||
storage: | ||
localSSDCount: ${LOCAL_SSD_COUNT} | ||
reservations: | ||
specific: | ||
- name: ${RESERVATION_NAME} | ||
affinity: Specific | ||
whenUnsatisfiable: DoNotScaleUp | ||
# [END gke_autoscaling_ccc_ssd_reservation] | ||
--- | ||
|
56 changes: 56 additions & 0 deletions
56
autoscaling/custom-compute-classes/reservations/deployment-gpu.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Copyright 2024 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# [START gke_autoscaling_ccc_reservations_deployment_gpu] | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: ccc-reservations | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: ccc-reservations | ||
template: | ||
metadata: | ||
labels: | ||
app: ccc-reservations | ||
spec: | ||
nodeSelector: | ||
cloud.google.com/compute-class: ccc-reservations | ||
containers: | ||
- name: ccc-reservations | ||
image: us-docker.pkg.dev/google-samples/containers/gke/hello-app:1.0 | ||
resources: | ||
requests: | ||
cpu: 500m | ||
memory: 500Mi | ||
nvidia.com/gpu: ${ACCELERATOR_QUANTITY} | ||
limits: | ||
cpu: 500m | ||
memory: 500Mi | ||
nvidia.com/gpu: ${ACCELERATOR_QUANTITY} | ||
affinity: | ||
podAntiAffinity: | ||
requiredDuringSchedulingIgnoredDuringExecution: | ||
- labelSelector: | ||
matchExpressions: | ||
- key: app | ||
operator: In | ||
values: | ||
- ccc-reservations | ||
topologyKey: "kubernetes.io/hostname" | ||
# [END gke_autoscaling_ccc_reservations_deployment_gpu] | ||
--- | ||
|
54 changes: 54 additions & 0 deletions
54
autoscaling/custom-compute-classes/reservations/deployment.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Copyright 2024 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# [START gke_autoscaling_ccc_reservations_deployment] | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: ccc-reservations | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: ccc-reservations | ||
template: | ||
metadata: | ||
labels: | ||
app: ccc-reservations | ||
spec: | ||
nodeSelector: | ||
cloud.google.com/compute-class: ccc-reservations | ||
containers: | ||
- name: ccc-reservations | ||
image: us-docker.pkg.dev/google-samples/containers/gke/hello-app:1.0 | ||
resources: | ||
requests: | ||
cpu: 500m | ||
memory: 500Mi | ||
limits: | ||
cpu: 500m | ||
memory: 500Mi | ||
affinity: | ||
podAntiAffinity: | ||
requiredDuringSchedulingIgnoredDuringExecution: | ||
- labelSelector: | ||
matchExpressions: | ||
- key: app | ||
operator: In | ||
values: | ||
- ccc-reservations | ||
topologyKey: "kubernetes.io/hostname" | ||
# [END gke_autoscaling_ccc_reservations_deployment] | ||
--- | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# Copyright 2024 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
set -euo pipefail | ||
|
||
DEPLOYMENT_MANIFEST="${2:-deployment.yaml}" | ||
|
||
echo "Removing deployment at ${DEPLOYMENT_MANIFEST}" | ||
kubectl delete -f "${DEPLOYMENT_MANIFEST}" --ignore-not-found=true | ||
echo "Waiting for nodes to get downscaled..." | ||
kubectl wait --for=delete node -l cloud.google.com/compute-class=ccc-reservations --timeout=1h |
35 changes: 35 additions & 0 deletions
35
autoscaling/custom-compute-classes/reservations/schedule.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# Copyright 2024 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
set -euo pipefail | ||
|
||
COMPUTECLASS_MANIFEST="${1}" | ||
DEPLOYMENT_MANIFEST="${2}" | ||
SCALE_UP_TIMEOUT="${3:-300s}" | ||
SCALE_UP_BATCH="${4:-1}" | ||
|
||
echo "Going to use deployment at ${DEPLOYMENT_MANIFEST}, compute class at ${COMPUTECLASS_MANIFEST} with batch scale up size of ${SCALE_UP_BATCH} and timeout: ${SCALE_UP_TIMEOUT}" | ||
|
||
kubectl apply -f "${COMPUTECLASS_MANIFEST}" | ||
kubectl apply -f "${DEPLOYMENT_MANIFEST}" | ||
|
||
while :; do | ||
kubectl rollout status -f "${DEPLOYMENT_MANIFEST}" --timeout "${SCALE_UP_TIMEOUT}" | ||
replicas=$(kubectl get -f "${DEPLOYMENT_MANIFEST}" -o "jsonpath={.status.replicas}") | ||
newReplicas=$(expr "${replicas}" + "${SCALE_UP_BATCH}") | ||
echo "Scaling up deployment from ${replicas} to ${newReplicas}" | ||
kubectl scale -f "${DEPLOYMENT_MANIFEST}" --current-replicas="${replicas}" --replicas="${newReplicas}" | ||
done |