|
| 1 | +# Copyright 2021 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +# [START cloud_sql_postgres_sqlalchemy_gke_quickstart_deployment] |
| 16 | +apiVersion: apps/v1 |
| 17 | +kind: Deployment |
| 18 | +metadata: |
| 19 | + name: gke-cloud-sql-quickstart |
| 20 | +spec: |
| 21 | + selector: |
| 22 | + matchLabels: |
| 23 | + app: gke-cloud-sql-app |
| 24 | + template: |
| 25 | + metadata: |
| 26 | + labels: |
| 27 | + app: gke-cloud-sql-app |
| 28 | + spec: |
| 29 | + serviceAccountName: <YOUR-KSA-NAME> |
| 30 | + containers: |
| 31 | + - name: gke-cloud-sql-app |
| 32 | + # Replace <LOCATION> with your Artifact Registry location (e.g., us-central1). |
| 33 | + # Replace <YOUR_PROJECT_ID> with your project ID. |
| 34 | + image: <LOCATION>-docker.pkg.dev/<YOUR_PROJECT_ID>/gke-cloud-sql-repo/gke-sql:latest |
| 35 | + # This app listens on port 8080 for web traffic by default. |
| 36 | + ports: |
| 37 | + - containerPort: 8080 |
| 38 | + env: |
| 39 | + - name: PORT |
| 40 | + value: "8080" |
| 41 | + - name: DB_HOST |
| 42 | + value: "127.0.0.1" |
| 43 | + - name: DB_PORT |
| 44 | + value: "5432" |
| 45 | + - name: DB_USER |
| 46 | + valueFrom: |
| 47 | + secretKeyRef: |
| 48 | + name: <YOUR-DB-SECRET> |
| 49 | + key: username |
| 50 | + - name: DB_PASS |
| 51 | + valueFrom: |
| 52 | + secretKeyRef: |
| 53 | + name: <YOUR-DB-SECRET> |
| 54 | + key: password |
| 55 | + - name: DB_NAME |
| 56 | + valueFrom: |
| 57 | + secretKeyRef: |
| 58 | + name: <YOUR-DB-SECRET> |
| 59 | + key: database |
| 60 | + - name: cloud-sql-proxy |
| 61 | + # This uses the latest version of the Cloud SQL proxy |
| 62 | + # It is recommended to use a specific version for production environments. |
| 63 | + # See: https://github.com/GoogleCloudPlatform/cloudsql-proxy |
| 64 | + image: gcr.io/cloudsql-docker/gce-proxy:latest |
| 65 | + command: |
| 66 | + - "/cloud_sql_proxy" |
| 67 | + |
| 68 | + # If connecting from a VPC-native GKE cluster, you can use the |
| 69 | + # following flag to have the proxy connect over private IP |
| 70 | + # - "-ip_address_types=PRIVATE" |
| 71 | + |
| 72 | + # tcp should be set to the port the proxy should listen on |
| 73 | + # and should match the DB_PORT value set above. |
| 74 | + # Defaults: MySQL: 3306, Postgres: 5432, SQLServer: 1433 |
| 75 | + - "-instances=<INSTANCE_CONNECTION_NAME>=tcp:5432" |
| 76 | + securityContext: |
| 77 | + # The default Cloud SQL proxy image runs as the |
| 78 | + # "nonroot" user and group (uid: 65532) by default. |
| 79 | + runAsNonRoot: true |
| 80 | +# [END cloud_sql_postgres_sqlalchemy_gke_quickstart_deployment] |
0 commit comments