how to connect a cloud sql instance to an sql cluster?

7/17/2019

i have the deployment yaml file on the cluster and the connection name of the sql instance and the public ip address, so what should i add and where in order for me to connect the intance and cluster? i wanna be able to add something to the sql cluster and it gets automatically saved to the instance and vice-versa.

this is the deployment code:

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      annotations:
        deployment.kubernetes.io/revision: "1"
      creationTimestamp: 
      generation: 1
      labels:
        app: mysql
      name: mysql
      namespace: default
      resourceVersion: "1420"
      selfLink: 
      uid: 
    spec:
      progressDeadlineSeconds: 600
      replicas: 1
      revisionHistoryLimit: 10
      selector:
        matchLabels:
          app: mysql
      strategy:
        rollingUpdate:
          maxSurge: 25%
          maxUnavailable: 25%
        type: RollingUpdate
      template:
        metadata:
          creationTimestamp: null
          labels:
            app: mysql
        spec:
          containers:
          - env:
            - name: 
              valueFrom:
                secretKeyRef:
                  key: 
                  name: mysql
            image: mysql:5.6
            imagePullPolicy: IfNotPresent
            name: mysql
            ports:
            - containerPort: 3306
              name: mysql
              protocol: TCP
            resources: {}
            terminationMessagePath: /dev/termination-log
            terminationMessagePolicy: File
            volumeMounts:
            - mountPath: /var/lib/mysql
              name: 
          dnsPolicy: ClusterFirst
          restartPolicy: Always
          schedulerName: default-scheduler
          securityContext: {}
          terminationGracePeriodSeconds: 30
          volumes:
          - name: 
            persistentVolumeClaim:
              claimName: 
    status:
      availableReplicas: 1
      conditions:
      - lastTransitionTime: 
        lastUpdateTime: 
        message: Deployment has minimum availability.
        reason: MinimumReplicasAvailable
        status: "True"
        type: Available
      - lastTransitionTime: 
        lastUpdateTime: 
        message: ReplicaSet "mysql" has successfully progressed.
        reason: NewReplicaSetAvailable
        status: "True"
        type: Progressing
      observedGeneration: 1
      readyReplicas: 1
      replicas: 1
      updatedReplicas: 1
-- marwa karaki
google-cloud-sql
google-kubernetes-engine
mysql
sql

1 Answer

7/17/2019

You should use the Cloud SQL proxy and add it as a sidecar to your application making queries to the Cloud SQL instance. Google has a suggested best practice found here.

-- Patrick W
Source: StackOverflow