-
Notifications
You must be signed in to change notification settings - Fork 351
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: Update kubernetes examples to use K8s native sidecar containers. (
#2371) Running the proxy as a native sidecar container is now the preferred way to run the proxy. Using native sidecars makes the lifecycle much easier to manage: - Kubernetes will start the proxy container and wait until it is ready before it starts the application container. - Kubernetes will keep the proxy container running until the application container exits. - Kubernetes will stop the proxy container after the application container exits. - The exit status of the proxy will not impact the pod's overall exit status. This is especially important for Job and CronJob workloads. Native sidecar containers are supported by default in Kuberenetes 1.29. See K8s Sidecar Container: https://kubernetes.io/docs/concepts/workloads/pods/sidecar-containers/
- Loading branch information
Showing
11 changed files
with
108 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
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
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
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
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
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
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,77 @@ | ||
# Copyright 2025 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. | ||
# | ||
# This works in Kubernetes 1.29 and higher, demonstrating how to run the proxy | ||
# using a native side-car container. | ||
# | ||
# 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: my-application | ||
# Run your batch job command. | ||
# Then, send a HTTTP POST request to the proxy sidecar container's | ||
# /quitquitquit api. This will cause the proxy process to exit. | ||
command: | ||
- my_batch_job | ||
- --host=127.0.0.1 | ||
- --port=<DB_PORT> | ||
- --username=<DB_USER> | ||
- --dbname=<DB_NAME> | ||
image: my-application-image | ||
imagePullPolicy: IfNotPresent | ||
resources: {} | ||
terminationMessagePath: /dev/termination-log | ||
terminationMessagePolicy: File | ||
restartPolicy: Never | ||
terminationGracePeriodSeconds: 30 | ||
initContainers: | ||
- name: cloud-sql-proxy | ||
restartPolicy: Always | ||
# It is recommended to use the latest version of the Cloud SQL Auth Proxy | ||
# Make sure to update on a regular schedule! | ||
image: gcr.io/cloud-sql-connectors/cloud-sql-proxy:2.14.3 | ||
args: | ||
# Enable the admin api server on port 9091 | ||
- "--admin-port=9091" | ||
|
||
# Tell the proxy to exit gracefully if it receives a SIGTERM | ||
- "--exit-zero-on-sigterm" | ||
|
||
# Replace DB_PORT with the port the proxy should listen on | ||
- "--port=<DB_PORT>" | ||
- "<INSTANCE_CONNECTION_NAME>" | ||
securityContext: | ||
runAsNonRoot: true | ||
resources: | ||
requests: | ||
memory: "2Gi" | ||
cpu: "1" |
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
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
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
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