diff --git a/docs/examples/job-mysql.yaml b/docs/examples/job-mysql.yaml new file mode 100644 index 00000000..65efe15d --- /dev/null +++ b/docs/examples/job-mysql.yaml @@ -0,0 +1,81 @@ +# 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 +# +# http://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. + +### +# This demonstrates how to configure a batch job so that it shuts down +# the proxy containers when it has finished processing. +# +# The operator will set an environment variable called CSQL_QUIT_URLS +# with a space-separated list of URLs to each proxy container's /quitquitquit +# endpoint. In most cases, your job will only have one proxy container attached, +# so the value of CSQL_QUIT_URLS will be something like +# "http://localhost:9091/quitquitquit" +# +# The main job container should send a POST request each URL when the job +# container process finishes. This will cause the proxy side-car containers +# to shut down. +# +# In Kubernetes 1.28, side-car containers will be properly supported. When +# That happens, we will update the operator to use the built-in side-car +# mechanism for workloads on clusters version 1.28 and higher. +# +# See https://github.com/kubernetes/enhancements/issues/753 +# and https://github.com/GoogleCloudPlatform/cloud-sql-proxy-operator/issues/381 +apiVersion: batch/v1 +kind: Job +metadata: + name: job + labels: + app: myBatchJob +spec: + template: + metadata: + creationTimestamp: null + labels: + app: myBatchJob + spec: + containers: + - name: myBatchJob + # Run your batch job command. + # Then, Iterate through the attached proxy shutdown hooks + # set by the operator in $CSQL_QUIT_URLS. Call each proxy's shutdown + # hook HTTP endpoint. + command: + - sh + - -c + - > + batchJobCommand --host=$DB_HOST --port=$DB_PORT --username=$DB_USER --dbname=$DB_NAME + for url in $CSQL_QUIT_URLS ; do + curl $url + done + image: myBatchJobImage + terminationMessagePath: /dev/termination-log + terminationMessagePolicy: File + restartPolicy: Never + terminationGracePeriodSeconds: 30 +--- +apiVersion: cloudsql.cloud.google.com/v1 +kind: AuthProxyWorkload +metadata: + name: job-proxy +spec: + instances: + - connectionString: project:region:instancename + hostEnvName: DB_HOST + portEnvName: DB_PORT + workloadSelector: + kind: Job + selector: + matchLabels: + app: myBatchJob