This page shows you how to deploy a sample app on Google Kubernetes Engine (GKE) connected to a MySQL instance using the Google Cloud console and a client application. The resources created in this quickstart typically cost less than one dollar (USD), assuming you complete the steps, including the clean up, in a
timely manner. In the Google
Cloud console, on the project selector page, select or create a Google Cloud project. Go to project selector Make sure that billing is enabled for your Cloud project. Learn how to
check if billing is enabled on a project. In the Google Cloud console, on the project selector page, select or create a Google Cloud project. Go to project selector Make sure that billing is enabled for your Cloud project. Learn how to check if billing
is enabled on a project. Click the button below to enable the APIs required for this quickstart. Enable APIs This enables the following APIs: Click the
following button to open Cloud Shell, which provides command-line access to your Google Cloud resources directly from the browser. Cloud Shell can be used to run the Open Cloud Shell Run the This command enables the following APIs: In the Google Cloud console, go to the Cloud SQL Instances page. Go to Cloud SQL
Instances
Click Create Instance and wait until the instance initializes and starts. Before running the
Optionally, modify the values for the following parameters: Run the Private IPIn the Google Cloud console, go to the Cloud SQL Instances page. Go to Cloud SQL Instances Creating an instance with a private IP address only requires configuring private services access to enable connections from other Google Cloud services, such as GKE. Before running the Optionally, modify the values for the following parameters: Run the
Run the Create a databaseIn the Google Cloud console, go to the Cloud SQL Instances page. Go to Cloud SQL Instances Run the Create a userIn the Google Cloud console, go to the Cloud SQL Instances page. Go to Cloud SQL Instances
gcloudBefore running the command as follows, replace DB_PASS with a password for your database user. Make a note of this for use in a later step of this quickstart. Run the gcloud sql users create quickstart-user \ --instance=quickstart-instance \ --password=DB_PASS User name length limits are the same for Cloud SQL as for on-premises MySQL; 32 characters for MySQL 8.0, 16 characters for earlier versions. Create a GKE clusterIn the Google Cloud console, go to the Google Kubernetes Engine
page. Go to Google Kubernetes Engine Run the Clone a Cloud SQL sample app into Cloud Shell EditorWith a Cloud SQL instance, a database, and a GKE cluster, you can now clone and configure a sample application to connect to your Cloud SQL instance. The remaining steps in this quickstart require using the In Cloud Shell Editor, open the sample app's source code. Enable the GKE clusterEnable the GKE cluster you just created as the default cluster to be used for the remaining commands in this quickstart. gcloud container clusters get-credentials command as follows to enable the GKE cluster. gcloud container clusters get-credentials gke-cloud-sql-quickstart \ --region us-central1 Set up a service accountCreate and configure a Google Cloud service account to be used by GKE so that it has the Cloud SQL Client role with permissions to connect to Cloud SQL.
Create a Kubernetes service account configured to have access to Cloud SQL by binding it to the Google Cloud service account using Workload Identity.
Configure secretsRun the kubectl create secret generic gke-cloud-sql-secrets \ --from-literal=database=quickstart_db \ --from-literal=username=quickstart-user \ --from-literal=password=DB_PASS Build the sample app
Deploy the sample appPublic IPWith the sample app configuration in place, you can now deploy the sample app.
The deployed sample app connects to your Cloud SQL instance using the Cloud SQL proxy running in a Kubernetes sidecar pattern. The sidecar pattern is accomplished by deploying a workload with an additional container that shares the same Kubernetes pod as
the sample app's container. JavaThe deployed sample app connects to your Cloud SQL instance using the Cloud SQL Java connector.
Node.jsThe deployed sample app connects to your Cloud SQL instance using the Cloud SQL proxy running in a Kubernetes sidecar pattern. The sidecar pattern is accomplished by deploying a workload with an additional container that shares the same Kubernetes pod as the sample app's container.
PythonThe deployed sample app connects to your Cloud SQL instance using the Cloud SQL proxy running in a Kubernetes sidecar pattern. The sidecar pattern is accomplished by deploying a workload with an additional container that shares the same Kubernetes pod as the sample app's container.
Private IPWith the sample app configuration in place, you can now deploy the sample app. The deployed sample app connects to your Cloud SQL instance using the
Cloud SQL proxy running in a Kubernetes sidecar pattern. The sidecar pattern is accomplished by deploying a workload with an additional container that shares the same Kubernetes pod as the sample app's container. JavaThe deployed sample app connects to your Cloud SQL instance using the Cloud SQL Java connector.
Node.jsThe deployed sample app connects to your Cloud SQL instance using the Cloud SQL proxy running in a Kubernetes sidecar pattern. The sidecar pattern is accomplished by deploying a workload with an additional container that shares the same Kubernetes pod as the sample app's container.
PythonThe deployed sample app connects to your Cloud SQL instance using the Cloud SQL proxy running in a Kubernetes sidecar pattern. The sidecar pattern is accomplished by deploying a workload with an additional container that shares the same Kubernetes pod as the sample app's container.
Clean upTo avoid incurring charges to your Google Cloud account for the resources used on this page, follow these steps.
Optional cleanup stepsIf you're not using the Google Cloud service account you created for this quickstart, you can remove it.
If you're not using the APIs that were enabled as part of this quickstart, you can disable them.
What's nextBased on your needs, you can learn more about creating Cloud SQL instances.You also can learn about creating MySQL users and databases for your Cloud SQL instance. Also see the Cloud SQL pricing information. Learn more about:
Additionally, you can learn about connecting to a Cloud SQL instance from other Google Cloud applications:
How do I connect to MySQL database in Kubernetes?To connect to a MySQL instance from outside of your Kubernetes cluster, you must configure the Kubernetes service for the instance to be of type LoadBalancer . To access the MySQL server from an external IP address: Create a database user to use for the external connection.
How do I connect to a MySQL container?Step 1: Pull the Docker Image for MySQL. Step 2: Deploy and Start the MySQL Container. Step 3: Connect with the Docker MySQL Container.
What is MySQL operator for Kubernetes?MySQL Operator for Kubernetes manages MySQL InnoDB Cluster setups inside a Kubernetes Cluster. MySQL Operator for Kubernetes manages the full lifecycle with setup and maintenance including automating upgrades and backups.
Can you run database on Kubernetes?Canonical charmed database operator
Canonical develops multiple open-source operators so developers can confidently and efficiently run databases on Kubernetes in a production environment.
|