skip to Main Content

I created a private CloudSQL instance for a postgres db.
I followed the documentation at https://cloud.google.com/sql/docs/postgres/connect-kubernetes-engine and applied the yaml changes and restarted the deployment.
Added the below to my existing Yaml for deployment.
I was wondering if there is any way to test/check if the connection to the DB was successful.
EDIT – I didnt encounter any errors when the pod restarted, so thats the main reason I am asking this question.

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

2

Answers


  1. If you just to check the connection

    you can run one ubuntu or busybox container to check the connection with the Postgres database.

    kubectl run -i --tty busybox --image=busybox --restart=Never -- sh
    
    $> # ls 
    

    Once you are in the container you can run the command from the container to Postgres database connection or run any network commands to check further.

    Command to check the Postgres sql

    psql -h <REMOTE HOST> -p <REMOTE PORT> -U <DB_USER> <DB_NAME> 
    
    Login or Signup to reply.
  2. The Cloud SQL Auth proxy container also supports health checks, which can be used to check the status of the container.

    The /readiness endpoint runs a connection test to your instance, so you can poll it to verify everything is working.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search