Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New samples: Kueue cohort tutorial #534

Merged
merged 8 commits into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions batch/kueue-cohort/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Deploy Kueue with Cohorts and Resource Sharing

[![Open in Cloud Shell](https://gstatic.com/cloudssh/images/open-btn.svg)](https://ssh.cloud.google.com/cloudshell/editor?cloudshell_git_repo=https://github.com/GoogleCloudPlatform/kubernetes-engine-samples&cloudshell_tutorial=README.md&cloudshell_workspace=guestbook/)

Please follow the tutorial at https://cloud.google.com/kubernetes-engine/docs/tutorials/kueue-cohort.
20 changes: 20 additions & 0 deletions batch/kueue-cohort/create_jobs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2023 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.

#!/bin/bash
while :
do
kubectl create -f ${1}
sleep ${2:-10}
done
31 changes: 31 additions & 0 deletions batch/kueue-cohort/flavors.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright 2023 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_batch_kueue_cohort_flavors]
apiVersion: kueue.x-k8s.io/v1beta1
kind: ResourceFlavor
metadata:
name: standard # This ResourceFlavor will be used for the CPU resource
spec:
nodeLabels:
cloud.google.com/gke-provisioning: standard
---
apiVersion: kueue.x-k8s.io/v1beta1
kind: ResourceFlavor
metadata:
name: spot # This ResourceFlavor will be used as added resource for the CPU resource
labels:
cloud.google.com/gke-provisioning: spot

# [END gke_batch_kueue_cohort_flavors]
33 changes: 33 additions & 0 deletions batch/kueue-cohort/spot-cq.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright 2023 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_batch_kueue_cohort_spot_cq]
apiVersion: kueue.x-k8s.io/v1beta1
kind: ClusterQueue
metadata:
name: spot-cq
spec:
cohort: all
namespaceSelector: {}
resourceGroups:
- coveredResources: ["cpu", "memory"]
flavors:
- name: spot
resources:
- name: "cpu"
nominalQuota: 40
- name: "memory"
nominalQuota: 144Gi
# [END gke_batch_kueue_cohort_spot_cq]

49 changes: 49 additions & 0 deletions batch/kueue-cohort/team-a-cq.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Copyright 2023 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_batch_kueue_cohort_team_a_cq]
apiVersion: kueue.x-k8s.io/v1beta1
kind: ClusterQueue
metadata:
name: team-a-cq
spec:
cohort: all # team-a-cq and team-b-cq share the same cohort
namespaceSelector: {}
resourceGroups:
- resources: ["cpu", "memory"]
flavors:
- name: standard
resources:
- name: "cpu"
nominalQuota: 10
borrowingLimit: 15
- name: "memory"
nominalQuota: 10Gi
borrowingLimit: 15Gi
- name: spot # This ClusterQueue doesn't have nominalQuota for spot, but it can borrow from others
resources:
- name: "cpu"
nominalQuota: 0
- name: "memory"
nominalQuota: 0
---
apiVersion: kueue.x-k8s.io/v1beta1
kind: LocalQueue
metadata:
namespace: team-a # LocalQueue under team-a namespace
name: team-a-lq
spec:
clusterQueue: team-a-cq # Point to the ClusterQueue team-a-cq
# [END gke_batch_kueue_cohort_team_a_cq]

40 changes: 40 additions & 0 deletions batch/kueue-cohort/team-a-job.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright 2023 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_batch_kueue_cohort_team_a_job]
apiVersion: batch/v1
kind: Job
metadata:
namespace: team-a # Job under team-a namespace
generateName: sample-team-a-job-
labels:
kueue.x-k8s.io/queue-name: team-a-lq # Point to the LocalQueue
spec:
ttlSecondsAfterFinished: 60 # Job will be deleted after 60 seconds
parallelism: 3 # This Job will have 3 replicas running at the same time
completions: 3 # This Job requires 3 completions
suspend: true # Set to true and allow Kueue to control the Job
template:
spec:
containers:
- name: dummy-job
image: gcr.io/k8s-staging-perf-tests/sleep:latest
args: ["10s"] # Sleep for 10 seconds
resources:
requests:
cpu: "500m"
memory: "512Mi"
restartPolicy: Never
# [END gke_batch_kueue_cohort_team_a_job]

49 changes: 49 additions & 0 deletions batch/kueue-cohort/team-b-cq.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Copyright 2023 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_batch_kueue_cohort_team_b_cq]
apiVersion: kueue.x-k8s.io/v1beta1
kind: ClusterQueue
metadata:
name: team-b-cq
spec:
cohort: all # team-a-cq and team-b-cq share the same cohort
namespaceSelector: {}
resourceGroups:
- resources: ["cpu", "memory"]
flavors:
- name: standard
resources:
- name: "cpu"
nominalQuota: 10
borrowingLimit: 15
- name: "memory"
nominalQuota: 10Gi
borrowingLimit: 15Gi
- name: spot # This ClusterQueue doesn't have nominalQuota for spot, but it can borrow from others
resources:
- name: "cpu"
nominalQuota: 0
- name: "memory"
nominalQuota: 0
---
apiVersion: kueue.x-k8s.io/v1beta1
kind: LocalQueue
metadata:
namespace: team-b # LocalQueue under team-b namespace
name: team-b-lq
spec:
clusterQueue: team-b-cq # Point to the ClusterQueue team-b-cq
# [END gke_batch_kueue_cohort_team_b_cq]

40 changes: 40 additions & 0 deletions batch/kueue-cohort/team-b-job.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright 2023 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_batch_kueue_cohort_team_b_job]
apiVersion: batch/v1
kind: Job
metadata:
namespace: team-b # Job under team-a namespace
generateName: sample-team-b-job-
labels:
kueue.scheduling.k8s.io/queue-name: team-b-lq # Point to the LocalQueue
spec:
ttlSecondsAfterFinished: 60 # Job will be deleted after 60 seconds
parallelism: 3 # This Job will have 3 replicas running at the same time
completions: 3 # This Job requires 3 completions
suspend: true # Set to true and allow Kueue to control the Job
template:
spec:
containers:
- name: dummy-job
image: gcr.io/k8s-staging-perf-tests/sleep:latest
args: ["10s"] # Sleep for 10 seconds
resources:
requests:
cpu: "500m"
memory: "512Mi"
restartPolicy: Never
# [END gke_batch_kueue_cohort_team_b_job]