התחברות מ-Google Kubernetes Engine

בדף הזה מוסבר איך להגדיר חיבור מאפליקציה שפועלת ב-Google Kubernetes Engine‏ (GKE) למופע Cloud SQL.

הוראות מפורטות להפעלת אפליקציית אינטרנט לדוגמה של Google Kubernetes Engine שמחוברת ל-Cloud SQL זמינות במדריך לתחילת העבודה בנושא התחברות מ-Google Kubernetes Engine.

‫Cloud SQL הוא שירות מנוהל של מסד נתונים, שבעזרתו אפשר ליצור, לתחזק ולנהל מסדי נתונים רלציוניים בענן.

‫Google Kubernetes Engine היא דרך פשוטה לפרוס, לשנות את קנה המידה ולנהל את Kubernetes באופן אוטומטי.

מידע על חיבור של Google Kubernetes Engine ל-Cloud SQL

כדי לגשת למכונת Cloud SQL מאפליקציה שפועלת ב-Google Kubernetes Engine, אפשר להשתמש בשרת proxy ל-Cloud SQL Auth (עם כתובת IP ציבורית או פרטית) או להתחבר ישירות באמצעות כתובת IP פרטית.

שרת proxy ל-Cloud SQL Auth הוא הדרך המומלצת להתחבר ל-Cloud SQL, גם כשמשתמשים בכתובת IP פרטית. הסיבה לכך היא ששרת ה-proxy ל-Cloud SQL Auth מספק הצפנה חזקה ואימות באמצעות IAM, שיכולים לעזור לשמור על אבטחת מסד הנתונים.

חיבורים למסדי נתונים צורכים משאבים בשרת ובאפליקציה שמבצעת את החיבור. כדי לצמצם את טביעת הרגל של האפליקציה ולהקטין את הסיכוי לחרוג ממגבלות החיבור ב-Cloud SQL, מומלץ תמיד להשתמש בשיטות טובות לניהול חיבורים. איך מנהלים חיבורים למסדי נתונים

לפני שמתחילים

כדי להתחבר ל-Cloud SQL, צריך:

  • אשכול GKE, עם כלי שורת הפקודה kubectl מותקן ומוגדר לתקשורת עם האשכול.

    לקבלת עזרה בתחילת העבודה עם GKE, אפשר לעיין במאמר פריסת אפליקציות לאשכולות GKE.

    כדי להתחבר באמצעות כתובת IP פרטית, אשכול GKE צריך להיות VPC-native ומקושר לאותה רשת ענן וירטואלי פרטי (VPC) כמו מכונת Cloud SQL.

  • נוצרה מכונה.

    למידע נוסף על יצירת מכונה של Cloud SQL, תוכלו לקרוא את המאמר יצירת מכונות.

  • חשבון משתמש ב-SQL Server שהוגדר במופע.

    האפליקציה תשתמש בחשבון הזה כדי להתחבר למסד הנתונים. לקבלת עזרה ביצירת חשבון משתמש, אפשר לקרוא את המאמר יצירת משתמש.

מידע על Kubernetes Secrets

ב-Kubernetes, ‏ Secrets הם דרך מאובטחת להעברת פרטי הגדרה לאפליקציה. אפשר ליצור סוד עם פרטים כמו שם מסד הנתונים, המשתמש והסיסמה, שאפשר להחדיר לאפליקציה כמשתני סביבה.

יש הרבה דרכים שונות להשתמש ב-Secrets, בהתאם לסוג החיבור:

  • סוד של פרטי כניסה למסד נתונים כולל את שם משתמש מסד הנתונים שאליו מתחברים ואת הסיסמה של המשתמש למסד הנתונים.
  • אם מתחברים באמצעות שרת proxy ל-Cloud SQL Auth, אפשר להשתמש ב-Secret כדי לשמור את קובץ פרטי הכניסה של חשבון השירות.
  • אם מתחברים באמצעות כתובת IP פרטית, אפשר להשתמש ב-Secret כדי לציין את כתובת ה-IP הפרטית של מכונת Cloud SQL.

דוגמאות מלאות לשימוש ב-Secrets מופיעות במאגרי GitHub שמפורטים בהמשך הדף.

יצירת אובייקט Secret

  1. יוצרים את אובייקטי הסוד באמצעות הפקודה kubectl create secret.

    כדי ליצור סוד של פרטי כניסה למסד נתונים:

    kubectl create secret generic <YOUR-DB-SECRET> \
      --from-literal=username=<YOUR-DATABASE-USER> \
      --from-literal=password=<YOUR-DATABASE-PASSWORD> \
      --from-literal=database=<YOUR-DATABASE-NAME>
    
  2. אחרי שיוצרים את האובייקטים, אפשר לראות אותם בקטע Configuration בדף Google Kubernetes Engine בGoogle Cloud מסוף.

התחברות ל-Cloud SQL באמצעות שרת proxy ל-Cloud SQL Auth

כשמתחברים באמצעות שרת proxy ל-Cloud SQL Auth, שרת ה-proxy ל-Cloud SQL Auth מתווסף ל-pod באמצעות תבנית מאגר sidecar. קונטיינר שרת ה-proxy ל-Cloud SQL Auth נמצא באותו פוד כמו האפליקציה, מה שמאפשר לאפליקציה להתחבר לשרת ה-proxy ל-Cloud SQL Auth באמצעות localhost, וכך לשפר את האבטחה והביצועים.

מידע נוסף על שרת proxy ל-Cloud SQL Auth זמין במאמר מידע על שרת proxy ל-Cloud SQL Auth. מידע נוסף על עבודה עם פודים זמין במאמר סקירה כללית על פודים במסמכי Kubernetes.

כדי להתחבר באמצעות שרת proxy ל-Cloud SQL Auth, צריך את הדברים הבאים:

  1. שם החיבור של המכונה של Cloud SQL.

    שם החיבור של המופע זמין בדף Cloud SQL Instance details במסוף Google Cloud או בפקודה gcloud sql instances describe INSTANCE_ID.

  2. המיקום של קובץ המפתח שמשויך לחשבון שירות עם ההרשאות המתאימות למכונה שלכם ב-Cloud SQL.

    מידע נוסף זמין במאמר יצירת חשבון שירות.

  3. ‫Cloud SQL Admin API מופעל.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the API

ציון חשבון השירות לשרת ה-proxy ל-Cloud SQL Auth

השלב הראשון בהפעלת Cloud SQL Auth Proxy ב-Google Kubernetes Engine הוא יצירת חשבון שירות של Google‏ (GSA) שייצג את האפליקציה שלכם. מומלץ ליצור חשבון שירות ייחודי לכל אפליקציה, במקום להשתמש באותו חשבון שירות בכל מקום. המודל הזה מאובטח יותר כי הוא מאפשר להגביל את ההרשאות לכל אפליקציה בנפרד.

חשבון השירות של האפליקציה צריך לעמוד בקריטריונים הבאים:

  • שייכים לפרויקט שבו מופעל Cloud SQL Admin API
  • קיבל את תפקיד הלקוח ב-IAM של Cloud SQL (או תפקיד מקביל) בפרויקט שמכיל את המופע שאליו רוצים להתחבר
  • אם מתחברים באמצעות כתובת IP פרטית, צריך להשתמש באשכול GKE מקורי של VPC, באותו VPC כמו מכונת Cloud SQL

צריך להגדיר את GKE כך שיספק את חשבון השירות ל-Cloud SQL Auth Proxy. יש שתי דרכים מומלצות לעשות זאת: Workload Identity או קובץ מפתח של חשבון שירות.

Workload Identity

אם אתם משתמשים ב-Google Kubernetes Engine, השיטה המומלצת היא להשתמש בתכונה Workload Identity של GKE. השיטה הזו מאפשרת לקשר חשבון שירות של Kubernetes‏ (KSA) לחשבון שירות של Google‏ (GSA). לאחר מכן, האפליקציות יוכלו לגשת ל-GSA באמצעות ה-KSA התואם.

חשבון שירות של Google‏ (GSA) הוא זהות IAM שמייצגת את האפליקציה שלכם ב-Google Cloud. באופן דומה, חשבון שירות של Kubernetes‏ (KSA) הוא זהות שמייצגת את האפליקציה שלכם באשכול Google Kubernetes Engine.

Workload Identity מקשר בין KSA ל-GSA, כך שכל פריסה עם ה-KSA הזה תאומת כ-GSA באינטראקציות שלה עם Google Cloud.

  1. הפעלת Workload Identity באשכול
  2. בדרך כלל, לכל אפליקציה יש זהות משלה שמיוצגת על ידי צמד של KSA ו-GSA. כדי ליצור KSA לאפליקציה, מריצים את הפקודה kubectl apply -f service-account.yaml:

    apiVersion: v1
    kind: ServiceAccount
    metadata:
      name: <YOUR-KSA-NAME> # TODO(developer): replace these values
  3. מפעילים את קישור ה-IAM בין YOUR-GSA-NAME לבין YOUR-KSA-NAME:

    gcloud iam service-accounts add-iam-policy-binding \
    --role="roles/iam.workloadIdentityUser" \
    --member="serviceAccount:YOUR-GOOGLE-CLOUD-PROJECT.svc.id.goog[YOUR-K8S-NAMESPACE/YOUR-KSA-NAME]" \
    YOUR-GSA-NAME@YOUR-GOOGLE-CLOUD-PROJECT.iam.gserviceaccount.com
  4. כדי להשלים את הקישור, מוסיפים הערה ל-YOUR-KSA-NAME:

    kubectl annotate serviceaccount \
    YOUR-KSA-NAME \
    iam.gke.io/gcp-service-account=YOUR-GSA-NAME@YOUR-GOOGLE-CLOUD-PROJECT.iam.gserviceaccount.com
  5. לסיום, חשוב לציין את חשבון השירות לאובייקט k8s.

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: <YOUR-DEPLOYMENT-NAME>
    spec:
      selector:
        matchLabels:
          app: <YOUR-APPLICATION-NAME>
      template:
        metadata:
          labels:
            app: <YOUR-APPLICATION-NAME>
        spec:
          serviceAccountName: <YOUR-KSA-NAME>

קובץ מפתח של חשבון שירות

לחלופין, אם אי אפשר להשתמש ב-Workload Identity, התבנית המומלצת היא להטמיע קובץ מפתח של חשבון שירות ב-pod של Cloud SQL Auth Proxy ולהשתמש בדגל --credentials-file.

  1. יוצרים קובץ פרטי כניסה למפתח של חשבון השירות:

    gcloud iam service-accounts keys create ~/key.json \
    --iam-account=YOUR-SA-NAME@project-id.iam.gserviceaccount.com
  2. הופכים את המפתח של חשבון השירות לסוד ב-k8s:

    kubectl create secret generic YOUR-SA-SECRET \
    --from-file=service_account.json=~/key.json
  3. מציבים את הסוד כנפח מתחת ל-spec: לאובייקט k8s:

    volumes:
      - name: <YOUR-SA-SECRET-VOLUME>
        secret:
          secretName: <YOUR-SA-SECRET>
  4. פועלים לפי ההוראות בקטע הבא כדי לגשת לנפח מה-pod של Cloud SQL Auth Proxy.

הפעלת שרת proxy ל-Cloud SQL Auth בתבנית sidecar

מומלץ להפעיל את שרת ה-proxy ל-Cloud SQL Auth בתבנית sidecar (כמאגר נוסף שמשתף פוד עם האפליקציה). אנחנו ממליצים על האפשרות הזו במקום להפעיל את התוסף כשירות נפרד, מכמה סיבות:

  • מונע חשיפה מקומית של תעבורת ה-SQL. שרת ה-proxy ל-Cloud SQL Auth מספק הצפנה בחיבורים יוצאים, אבל צריך להגביל את החשיפה בחיבורים נכנסים.
  • מונעים נקודת כשל יחידה. הגישה של כל אפליקציה למסד הנתונים שלכם היא נפרדת מהגישה של האפליקציות האחרות, ולכן המערכת עמידה יותר.
  • הגישה לשרת ה-proxy ל-Cloud SQL Auth מוגבלת, כך שאתם יכולים להשתמש בהרשאות IAM לכל אפליקציה במקום לחשוף את מסד הנתונים לכל האשכול.
  • התבנית הזו מאפשרת לכם להגדיר את היקף הבקשות למשאבים בצורה מדויקת יותר, כי Cloud SQL Auth Proxy צורך משאבים באופן לינארי בהתאם לשימוש. כך תוכלו להגדיר את היקף הבקשות למשאבים בהתאם לאפליקציות שלכם, ככל שהאפליקציה תגדל.

  • מוסיפים את שרת ה-proxy ל-Cloud SQL Auth להגדרת ה-pod בקטע initContainers, אלא אם אתם משתמשים ב-Cloud Service Mesh או ב-Istio.

    אם אתם משתמשים ב-Cloud Service Mesh או ב-Istio, צריך להוסיף את שרת ה-proxy ל-Cloud SQL Auth בקטע containers.

    initContainers

    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.1
        args:
          # If connecting from a VPC-native GKE cluster, you can use the
          # following flag to have the proxy connect over private IP
          # - "--private-ip"
    
          # If you are not connecting with Automatic IAM, you can delete
          # the following flag.
          - "--auto-iam-authn"
    
          # Enable structured logging with LogEntry format:
          - "--structured-logs"
    
          # Replace DB_PORT with the port the proxy should listen on
          - "--port=<DB_PORT>"
          - "<INSTANCE_CONNECTION_NAME>"
    
        securityContext:
          # The default Cloud SQL Auth Proxy image runs as the
          # "nonroot" user and group (uid: 65532) by default.
          runAsNonRoot: true
        # You should use resource requests/limits as a best practice to prevent
        # pods from consuming too many resources and affecting the execution of
        # other pods. You should adjust the following values based on what your
        # application needs. For details, see
        # https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
        resources:
          requests:
            # The proxy's memory use scales linearly with the number of active
            # connections. Fewer open connections will use less memory. Adjust
            # this value based on your application's requirements.
            memory: "2Gi"
            # The proxy's CPU use scales linearly with the amount of IO between
            # the database and the application. Adjust this value based on your
            # application's requirements.
            cpu: "1"

    containers

    - name: cloud-sql-proxy
      # 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.1
      args:
        # If connecting from a VPC-native GKE cluster, you can use the
        # following flag to have the proxy connect over private IP
        # - "--private-ip"
    
        # If you are not connecting with Automatic IAM, you can delete
        # the following flag.
        - "--auto-iam-authn"
    
        # Enable structured logging with LogEntry format:
        - "--structured-logs"
    
        # Replace DB_PORT with the port the proxy should listen on
        - "--port=<DB_PORT>"
        - "<INSTANCE_CONNECTION_NAME>"
    
      securityContext:
        # The default Cloud SQL Auth Proxy image runs as the
        # "nonroot" user and group (uid: 65532) by default.
        runAsNonRoot: true
      # You should use resource requests/limits as a best practice to prevent
      # pods from consuming too many resources and affecting the execution of
      # other pods. You should adjust the following values based on what your
      # application needs. For details, see
      # https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
      resources:
        requests:
          # The proxy's memory use scales linearly with the number of active
          # connections. Fewer open connections will use less memory. Adjust
          # this value based on your application's requirements.
          memory: "2Gi"
          # The proxy's CPU use scales linearly with the amount of IO between
          # the database and the application. Adjust this value based on your
          # application's requirements.
          cpu: "1"
  • אם אתם משתמשים במפתח של חשבון שירות, צריך לציין את נפח הסוד ולהוסיף את הדגל --credentials-file לפקודה:

      # This flag specifies where the service account key can be found
      - "--credentials-file=/secrets/service_account.json"
    securityContext:
      # The default Cloud SQL Auth Proxy image runs as the
      # "nonroot" user and group (uid: 65532) by default.
      runAsNonRoot: true
    volumeMounts:
      - name: <YOUR-SA-SECRET-VOLUME>
        mountPath: /secrets/
        readOnly: true
  • לבסוף, מגדירים את האפליקציה להתחבר באמצעות 127.0.0.1 בכל DB_PORT שהוגדר בקטע הפקודה.

קובצי הגדרות לדוגמה מלאים:

Workload Identity

# Copyright 2021 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.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: <YOUR-DEPLOYMENT-NAME>
spec:
  selector:
    matchLabels:
      app: <YOUR-APPLICATION-NAME>
  template:
    metadata:
      labels:
        app: <YOUR-APPLICATION-NAME>
    spec:
      serviceAccountName: <YOUR-KSA-NAME>
      containers:
        - name: <YOUR-APPLICATION-NAME>
          # ... other container configuration
          env:
            - name: DB_USER
              valueFrom:
                secretKeyRef:
                  name: <YOUR-DB-SECRET>
                  key: username
            - name: DB_PASS
              valueFrom:
                secretKeyRef:
                  name: <YOUR-DB-SECRET>
                  key: password
            - name: DB_NAME
              valueFrom:
                secretKeyRef:
                  name: <YOUR-DB-SECRET>
                  key: database
      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.1
          args:
            # If connecting from a VPC-native GKE cluster, you can use the
            # following flag to have the proxy connect over private IP
            # - "--private-ip"

            # If you are not connecting with Automatic IAM, you can delete
            # the following flag.
            - "--auto-iam-authn"

            # Enable structured logging with LogEntry format:
            - "--structured-logs"

            # Replace DB_PORT with the port the proxy should listen on
            - "--port=<DB_PORT>"
            - "<INSTANCE_CONNECTION_NAME>"

          securityContext:
            # The default Cloud SQL Auth Proxy image runs as the
            # "nonroot" user and group (uid: 65532) by default.
            runAsNonRoot: true
          # You should use resource requests/limits as a best practice to prevent
          # pods from consuming too many resources and affecting the execution of
          # other pods. You should adjust the following values based on what your
          # application needs. For details, see
          # https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
          resources:
            requests:
              # The proxy's memory use scales linearly with the number of active
              # connections. Fewer open connections will use less memory. Adjust
              # this value based on your application's requirements.
              memory: "2Gi"
              # The proxy's CPU use scales linearly with the amount of IO between
              # the database and the application. Adjust this value based on your
              # application's requirements.
              cpu: "1"

מפתח לחשבון השירות

# Copyright 2021 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.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: <YOUR-DEPLOYMENT-NAME>
spec:
  selector:
    matchLabels:
      app: <YOUR-APPLICATION-NAME>
  template:
    metadata:
      labels:
        app: <YOUR-APPLICATION-NAME>
    spec:
      containers:
        - name: <YOUR-APPLICATION-NAME>
          # ... other container configuration
          env:
            - name: DB_USER
              valueFrom:
                secretKeyRef:
                  name: <YOUR-DB-SECRET>
                  key: username
            - name: DB_PASS
              valueFrom:
                secretKeyRef:
                  name: <YOUR-DB-SECRET>
                  key: password
            - name: DB_NAME
              valueFrom:
                secretKeyRef:
                  name: <YOUR-DB-SECRET>
                  key: database
      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.1
          args:
            # If connecting from a VPC-native GKE cluster, you can use the
            # following flag to have the proxy connect over private IP
            # - "--private-ip"

            # If you are not connecting with Automatic IAM AuthN, you can delete
            # the following flag.
            - "--auto-iam-authn"

            # Enable structured logging with LogEntry format:
            - "--structured-logs"

            # Replace DB_PORT with the port the proxy should listen on
            - "--port=<DB_PORT>"
            - "<INSTANCE_CONNECTION_NAME>"

            # This flag specifies where the service account key can be found
            - "--credentials-file=/secrets/service_account.json"
          securityContext:
            # The default Cloud SQL Auth Proxy image runs as the
            # "nonroot" user and group (uid: 65532) by default.
            runAsNonRoot: true
          volumeMounts:
            - name: <YOUR-SA-SECRET-VOLUME>
              mountPath: /secrets/
              readOnly: true
          # Resource configuration depends on an application's requirements. You
          # should adjust the following values based on what your application
          # needs. For details, see https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
          resources:
            requests:
              # The proxy's memory use scales linearly with the number of active
              # connections. Fewer open connections will use less memory. Adjust
              # this value based on your application's requirements.
              memory: "2Gi"
              # The proxy's CPU use scales linearly with the amount of IO between
              # the database and the application. Adjust this value based on your
              # application's requirements.
              cpu: "1"
      volumes:
        - name: <YOUR-SA-SECRET-VOLUME>
          secret:
            secretName: <YOUR-SA-SECRET>

התחברות ל-Cloud SQL בלי שרת proxy לאימות של Cloud SQL

אפשר להתחבר מאשכול GKE מקורי של VPC למכונת Cloud SQL באותו VPC באמצעות כתובת IP פרטית ללא שרת proxy ל-Cloud SQL Auth, אבל זה פחות מאובטח.

  1. יוצרים סוד עם כתובת ה-IP הפרטית של המכונה:

    kubectl create secret generic <YOUR-PRIVATE-IP-SECRET> \
        --from-literal=db_host=<YOUR-PRIVATE-IP-ADDRESS>
    
  2. לאחר מכן, מוסיפים את הסוד למאגר התגים של האפליקציה:

    - name: DB_HOST
      valueFrom:
        secretKeyRef:
          name: <YOUR-PRIVATE-IP-SECRET>
          key: db_host
  3. לבסוף, מגדירים את האפליקציה להתחבר באמצעות כתובת ה-IP מתוך משתנה הסביבה DB_HOST. תצטרכו להשתמש ביציאה הנכונה עבור SQL Server: ‏ 1433

קובץ תצורה לדוגמה מלא:

כתובת IP פרטית

# Copyright 2021 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.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: <YOUR-DEPLOYMENT-NAME>
spec:
  selector:
    matchLabels:
      app: <YOUR-APPLICATION-NAME>
  template:
    metadata:
      labels:
        app: <YOUR-APPLICATION-NAME>
    spec:
      containers:
      - name: <YOUR-APPLICATION-NAME>
        # ... other container configuration
        env:
        - name: DB_USER
          valueFrom:
            secretKeyRef:
              name: <YOUR-DB-SECRET>
              key: username
        - name: DB_PASS
          valueFrom:
            secretKeyRef:
              name: <YOUR-DB-SECRET>
              key: password
        - name: DB_NAME
          valueFrom:
            secretKeyRef:
              name: <YOUR-DB-SECRET>
              key: database
        - name: DB_HOST
          valueFrom:
            secretKeyRef:
              name: <YOUR-PRIVATE-IP-SECRET>
              key: db_host

פתרון בעיות

דרושה לך עזרה? לקבלת עזרה בפתרון בעיות בשרת ה-proxy, אפשר לעיין במאמר בנושא פתרון בעיות בחיבורים של שרת proxy ל-Cloud SQL Auth או בדף תמיכה ב-Cloud SQL.

המאמרים הבאים