gcloud-sqlproxy

by rimusz

Helm chartv0.25.6App 2.6.0

Google Cloud SQL Proxy

About this chart

GCP SQL Proxy

sql-proxy The Cloud SQL Proxy provides secure access to your Cloud SQL Postgres/MySQL instances without having to whitelist IP addresses or configure SSL.

Accessing your Cloud SQL instance using the Cloud SQL Proxy offers these advantages:

  • Secure connections: The proxy automatically encrypts traffic to and from the database; SSL certificates are used to verify client and server identities.
  • Easier connection management: The proxy handles authentication with Google Cloud SQL, removing the need to provide static IP addresses of your GKE/GCE Kubernetes nodes.

Introduction

This chart creates a Google Cloud SQL proxy deployment and service on a Kubernetes cluster using the Helm package manager. You need to enable Cloud SQL Administration API and create a service account for the proxy as per these instructions.

Prerequisites

  • Kubernetes cluster on Google Container Engine (GKE)
  • Kubernetes cluster on Google Compute Engine (GCE)
  • Cloud SQL Administration API enabled
  • GCP Service account for the proxy with Cloud SQL Client role

Installing the Chart

Install from remote URL with the release name pg-sqlproxy into namespace sqlproxy, set GCP service account and SQL instances and ports:

$ helm upgrade --install pg-sqlproxy rimusz/gcloud-sqlproxy --namespace sqlproxy \
    --set serviceAccountKey="$(cat service-account.json | base64 | tr -d '\n')" \
    --set cloudsql.instances[0].instance=INSTANCE \
    --set cloudsql.instances[0].project=PROJECT \
    --set cloudsql.instances[0].region=REGION \
    --set cloudsql.instances[0].port=5432 -i

Replace Postgres/MySQL host with: if access is from the same namespace with pg-sqlproxy-gcloud-sqlproxy or if it is from a different namespace with pg-sqlproxy-gcloud-sqlproxy.sqlproxy, the rest database connections settings do not have to be changed.

Tip: List all releases using helm list

Tip: If you encounter a YAML parse error on gcloud-sqlproxy/templates/secrets.yaml, you might need to set -w 0 option to base64 command.

Tip: If you are using a MySQL instance, you may want to replace pg-sqlproxy with mysql-sqlproxy and 5432 with 3306.

Tip: Because of limitations on the length of port names, the instance value for each of the instances must be unique for the first 15 characters.

Tip: If you wish to source some cloussql.instances[] parameter values from ConfigMaps or Secrets, you may fetch them via env parameter and refer to them via $() interpolation syntax, e.g.: cloudsql.instances[0].region=$(REGION)

Uninstalling the Chart

To uninstall/delete the my-release-name deployment:

$ helm delete my-release-name

The command removes all the Kubernetes components associated with the chart and deletes the release.

Configuration

The following table lists the configurable parameters of the gcloud-sqlproxy chart and their default values.

ParameterDescriptionDefault
imageSQLProxy imagegcr.io/cloudsql-docker/gce-proxy
image.tagSQLProxy image tagAppVersion: 1.30.1
imagePullPolicyImage pull policyIfNotPresent
replicasCountReplicas count1
deploymentStrategyDeployment strategy for pods{}
commonLabelsCommon labels for all K8S objects
serviceAccountKeyService account key JSON fileMust be provided and base64 encoded when no existing secret is used, in this case a new secret will be created holding this service account
existingSecretName of an existing secret to be used for the cloud-sql credentials""
existingSecretKeyThe key to use in the provided existing secret""
usingGCPControllerenable the use of the GCP Service Account Controller""
serviceAccountNamespecify a service account name to use with GCP Controller""
cloudsql.instancesList of PostgreSQL/MySQL instances[{instance: instance, project: project, region: region, port: 5432}] must be provided
resourcesCPU/Memory resource requests/limitsMemory: 100/150Mi, CPU: 100/150m
envExtra environment variables for container{}
lifecycleHooksContainer lifecycle hooks{}
autoscaling.enabledEnable CPU/Memory horizontal pod autoscalerfalse
autoscaling.minReplicasAutoscaler minimum pod replica count1
autoscaling.maxReplicasAutoscaler maximum pod replica count3
autoscaling.targetCPUUtilizationPercentageScaling target for CPU Utilization Percentage50
autoscaling.targetMemoryUtilizationPercentageScaling target for Memory Utilization Percentage50
terminationGracePeriodSeconds# of seconds to wait before pod killed30 (Kubernetes default)
podAnnotationsPod Annotations
podLabelsPod Labels
priorityClassNamePriority Class Name""
nodeSelectorNode Selector
podDisruptionBudgetPod disruption budgetmaxUnavailable: 1 if replicasCount > 1, does not create the PDB otherwise
service.enabledToggle Service Creationtrue
service.typeKubernetes LoadBalancer typeClusterIP
service.internalLBCreate service with cloud.google.com/load-balancer-type: "Internal"Default false, when set to true you have to set also service.type=LoadBalancer
service.loadBalancerIPSet custom Load Balancer IP""
service.annotationsSet custom service annotations""
rbac.createCreate RBAC configuration w/ SAfalse
serviceAccount.createCreate a service accounttrue
serviceAccount.annotationsAnnotations for the service account{}
serviceAccount.nameService account nameGenerated using the fullname template
networkPolicy.enabledEnable NetworkPolicytrue
networkPolicy.ingress.fromList of sources which should be able to access the pods selected for this rule. If empty, allows all sources.[]
extraArgsAdditional container arguments{}
extraFlagsAdditional container flags[]
podSecurityContextConfigure Pod Security Context{}
containerSecurityContextConfigure Container Security Context{}
httpPortProbeThe port to check liveness, readiness & startup probe9090
livenessProbe.enabledWould you like a livenessProbe to be enabledfalse
livenessProbe.portThe port which will be checked by the probe9090
livenessProbe.initialDelaySecondsDelay before liveness probe is initiated30
livenessProbe.periodSecondsHow often to perform the probe10
livenessProbe.timeoutSecondsWhen the probe times out5
livenessProbe.failureThresholdMinimum consecutive failures for the probe to be considered failed after having succeeded.18
livenessProbe.successThresholdMinimum consecutive successes for the probe to be considered successful after having failed1
readinessProbe.enabledwould you like a readinessProbe to be enabledfalse
readinessProbe.portThe port which will be checked by the probe9090
readinessProbe.initialDelaySecondsDelay before readiness probe is initiated5
readinessProbe.periodSecondsHow often to perform the probe10
readinessProbe.timeoutSecondsWhen the probe times out5
readinessProbe.failureThresholdMinimum consecutive failures for the probe to be considered failed after having succeeded.6
readinessProbe.successThresholdMinimum consecutive successes for the probe to be considered successful after having failed1
startupProbe.enabledwould you like a startupProbe to be enabledfalse
startupProbe.portThe port which will be checked by the probe9090
startupProbe.initialDelaySecondsDelay before startup probe is initiated5
startupProbe.periodSecondsHow often to perform the probe10
startupProbe.timeoutSecondsWhen the probe times out5
startupProbe.failureThresholdMinimum consecutive failures for the probe to be considered failed after having succeeded.1
startupProbe.successThresholdMinimum consecu

Deploy gcloud-sqlproxy with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has gcloud-sqlproxy on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.

  1. Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
  2. Place the chartgcloud-sqlproxy is pinned at v0.25.6 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
  3. ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below
opentenant validate opentenant.yaml
terraform init && terraform apply