חיבור מ-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, אפשר להשתמש ב-Cloud SQL Auth Proxy (עם כתובת IP ציבורית או פרטית) או להתחבר ישירות באמצעות כתובת IP פרטית.

מומלץ להתחבר ל-Cloud SQL באמצעות שרת proxy ל-Cloud SQL Auth, גם כשמשתמשים בכתובת 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 שהוגדר במופע.

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

מידע על סודות (Secrets) ב-Kubernetes

ב-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 באמצעות Cloud SQL Auth Proxy

כשמתחברים באמצעות שרת 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. מידע נוסף על עבודה עם pods זמין במאמר Pod Overview (סקירה כללית על pods) במסמכי 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 מופעל.

    תפקידים שנדרשים להפעלת ממשקי API

    כדי להפעיל ממשקי API, צריך את תפקיד ה-IAM 'אדמין של Service Usage' (roles/serviceusage.serviceUsageAdmin), שכולל את ההרשאה serviceusage.services.enable. איך מקצים תפקידים

    להפעלת ה-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 (כמאגר נוסף שמשתף pod עם האפליקציה). מומלץ להשתמש בשיטה הזו במקום להפעיל את התוסף כשירות נפרד, מכמה סיבות:

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

  • מוסיפים את שרת ה-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 Auth

אפשר להתחבר מאשכול 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.

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