-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: Add example job that shuts down proxy containers on completion.
- Loading branch information
Showing
1 changed file
with
71 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,71 @@ | ||
### | ||
# 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: busybox | ||
spec: | ||
template: | ||
metadata: | ||
creationTimestamp: null | ||
labels: | ||
app: busybox | ||
spec: | ||
containers: | ||
- name: busybox | ||
# 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 | ||
- > | ||
psql --host=$DB_HOST --port=$DB_PORT --username=$DB_USER '--command=select 1' --echo-queries --dbname=$DB_NAME | ||
for url in $CSQL_QUIT_URLS ; do | ||
wget --post-data '' $url | ||
done | ||
image: busybox | ||
imagePullPolicy: IfNotPresent | ||
resources: {} | ||
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: busybox |