GCP Classroom notes 16/Oct/2024

Connecting to CloudSQL (Postgres) from Google kubernetes Engine

  • For guided creation watch classroom recording
  • Create a Service account
apiVersion: v1
kind: ServiceAccount
metadata:
  name: ksa-cloud-sql
  • deployment yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: gke-simplelib
spec:
  replicas: 1
  selector:
    matchLabels:
      app: simplelib
  template:
    metadata:
      labels:
        app: simplelib
    spec:
      containers:
      - name: simplelib
        image: shaikkhajaibrahim/simplelibrary:1
        resources:
          requests:
            memory: "128Mi"
            cpu: "250m"
          limits:
            memory: "256Mi"
            cpu: "1000m"
        env:
        - name: DATABASE_URL
          valueFrom:
            secretKeyRef:
              name: gke-cloud-sql-secrets 
              key: DATABASE_URL
        ports:
        - containerPort: 8000
      - name: cloud-sql-proxy
        # This uses the latest version of the Cloud SQL proxy
        # It is recommended to use a specific version for production environments.
        # See: https://github.com/GoogleCloudPlatform/cloudsql-proxy 
        image: gcr.io/cloud-sql-connectors/cloud-sql-proxy:latest
        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"

          # tcp should be set to the port the proxy should listen on
          # and should match the DB_PORT value set above.
          # Defaults: MySQL: 3306, Postgres: 5432, SQLServer: 1433
          - "--port=5432"
          - "peak-responder-438809-q5:us-central1:library-instance"
        resources:
          requests:
            memory: "128Mi"
            cpu: "250m"
          limits:
            memory: "256Mi"
            cpu: "1000m"
        securityContext:
          # The default Cloud SQL proxy image runs as the
          # "nonroot" user and group (uid: 65532) by default.
          runAsNonRoot: true

Published
Categorized as Uncategorized Tagged

By continuous learner

devops & cloud enthusiastic learner

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Please turn AdBlock off
Social Network Integration by Acurax Social Media Branding Company

Discover more from Direct DevOps from Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading

Visit Us On FacebookVisit Us On LinkedinVisit Us On Youtube