Skip to content

Commit

Permalink
docs: Add example job that shuts down proxy containers on completion.
Browse files Browse the repository at this point in the history
  • Loading branch information
hessjcg committed Sep 20, 2023
1 parent ae858e5 commit 04427d4
Showing 1 changed file with 81 additions and 0 deletions.
81 changes: 81 additions & 0 deletions docs/examples/job-mysql.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 04427d4

Please sign in to comment.