Instructions et exigences de configuration de l'atelier
Protégez votre compte et votre progression. Utilisez toujours une fenêtre de navigation privée et les identifiants de l'atelier pour exécuter cet atelier.

Running Databases in GKE

Atelier 1 heure universal_currency_alt 5 crédits show_chart Intermédiaire
info Cet atelier peut intégrer des outils d'IA pour vous accompagner dans votre apprentissage.
Ce contenu n'est pas encore optimisé pour les appareils mobiles.
Pour une expérience optimale, veuillez accéder à notre site sur un ordinateur de bureau en utilisant un lien envoyé par e-mail.

Overview

In this lab, you create a Google Kubernetes Engine (GKE) cluster, and then deploy databases into it. You see two ways to deploy the databases: first using your own configuration code, and then using a Kubernetes package manager called Helm.

Objectives

In this lab, you learn how to perform the following tasks:

  • Create a GKE cluster.
  • Deploy MySQL on the cluster.
  • Use Helm to deploy MySQL on the cluster.

Setup

In this task, you perform initialization steps for your lab.

For each lab, you get a new Google Cloud project and set of resources for a fixed time at no cost.

  1. Sign in to Google Skills using an incognito window.

  2. Note the lab's access time (for example, 1:15:00), and make sure you can finish within that time. There is no pause feature. You can restart if needed, but you have to start at the beginning.

  3. When ready, click Start lab.

  4. Note your lab credentials (Username and Password). You will use them to sign in to the Google Cloud Console.

  5. Click Open Google Console.

  6. Click Use another account and copy/paste credentials for this lab into the prompts. If you use other credentials, you'll receive errors or incur charges.

  7. Accept the terms and skip the recovery resource page.

Task 1. Create a GKE cluster

  1. Open a new web browser window and navigate to the Google Cloud Console (console.cloud.google.com). Use the project selector to choose the first project with a leading name of 'qwiklabs-gcp.'

  2. On the Navigation menu (Navigation menu icon), click Kubernetes Engine > Clusters.

  3. Click Create.

  4. You can see Standard: You manage your cluster inside Create a cluster pop-up.

  5. Click Configure next to Standard: You manage your cluster.

  6. For Location type, select Zonal.

  7. Accept all defaults and click Create. It will take a couple minutes for the cluster to be ready.

  8. When the cluster is ready, click Connect from the Actions menu.

The Connect option selected in the expanded More actions menu

The command for connecting to the cluster is specified.

  1. To open Cloud Shell with the command entered, click Run in Cloud Shell, and if prompted click Continue.

The Run in CLoud Shell button highlighted on the Command-line access page

  1. Press ENTER to run the command. If prompted click Authorize.

You are connected to the cluster and ready to deploy a program.

  1. Test the connection with the following kubectl command:
kubectl get nodes

This command returns a list of the three virtual machines that make up this cluster.

Click Check my progress to verify the objective. Create a Kubernetes cluster

Review

You just created a Kubernetes cluster. Next, you configure and deploy MySQL to run in it.

Task 2. Deploy MySQL on the cluster

You need a root password for the database. You store the password as a Kubernetes secret. The secret is a key-value pair. In this case, the key is ROOT_PASSWORD and the value is password.

  1. To create the secret, enter the following command:
kubectl create secret generic mysql-secrets --from-literal=ROOT_PASSWORD="password"
  1. Create a folder for the configuration files you create, and change to it:
mkdir mysql-gke cd mysql-gke
  1. Create the Kubernetes configuration files. In Cloud Shell, click Open Editor.

The Open Editor button highlighted in the UI

  1. Select the mysql-gke folder on the left.

The mysql-gke folder highlighted in the Explorer

  1. Right click the mysql-gke folder, and then click New File.

  2. For name, type volume.yaml.

  3. Enter the following YAML code and save the file:

apiVersion: v1 kind: PersistentVolumeClaim metadata: name: mysql-data-disk spec: accessModes: - ReadWriteOnce resources: requests: storage: 1Gi

This reserves 1 gigabyte of disk space for the MySQL database. Note the name mysql-data-disk. This name will be used in the next file.

  1. To configure the MySQL database, create another new file in the mysql-gke folder, name it deployment.yaml, and paste the following code into it:
apiVersion: apps/v1 kind: Deployment metadata: name: mysql-deployment labels: app: mysql spec: replicas: 1 selector: matchLabels: app: mysql template: metadata: labels: app: mysql spec: containers: - name: mysql image: mysql:8.0 ports: - containerPort: 3306 volumeMounts: - mountPath: "/var/lib/mysql" subPath: "mysql" name: mysql-data env: - name: MYSQL_ROOT_PASSWORD valueFrom: secretKeyRef: name: mysql-secrets key: ROOT_PASSWORD - name: MYSQL_USER value: testuser - name: MYSQL_PASSWORD value: password volumes: - name: mysql-data persistentVolumeClaim: claimName: mysql-data-disk

Notes:

  • On line 19, the MySQL docker image is specified.
  • Starting at line 26, an environment variable is created for the database root password using the secret you created earlier. There are also variables to create a test user with a simple password.
  • On the last line, the disk space you allocated in the previous file is used.

The database needs a service so it can be accessed.

  1. Create a third file in the mysql-gke folder, name it service.yaml, and paste the following code into it:
apiVersion: v1 kind: Service metadata: name: mysql-service spec: selector: app: mysql ports: - protocol: TCP port: 3306 targetPort: 3306 Note: This creates a service that provides access to the database from within the cluster that forwards requests to the MySQL database.
  1. In Cloud Shell, click Open Terminal to return to the command line. Make sure you are in the correct folder and type ls to verify that you have your three YAML files.

  2. To deploy your database, enter the following kubectl commands:

kubectl apply -f volume.yaml kubectl apply -f deployment.yaml kubectl apply -f service.yaml
  1. Wait a minute for the resources to be created, and then enter the following command:
kubectl get pods

The pod that has your database installed should be running. If it is not running yet, wait a little while and try again.

Note: At this point, there are no client applications and the database is only accessible from inside the cluster. In the next step, you access the database from inside the pod where it is running.

Click Check my progress to verify the objective. Deploy MySQL on the cluster

  1. Copy the name of the pod obtained from the last command to the clipboard. It will begin with mysql-deployment- followed by a unique string.

  2. Enter the following command but < replace the pod name > with your pod's name:

kubectl exec -it <mysql-deployment-76fdc44468-rfhbp> -- /bin/bash

Now you're at a bash prompt within the MySQL pod.

  1. To log in to MySQL, enter the following:
mysql -u root -p
  1. When prompted, enter the password password. This gives you a mysql prompt.

  2. Run the following command:

show databases;
  1. Create a new database:
create database pets;
  1. To confirm that your database was created, enter:
show databases;
  1. Type exit to exit MySQL.

  2. Type exit again to return to the Cloud Shell command prompt.

  3. To remove everything that was created, enter the following commands:

kubectl delete -f service.yaml kubectl delete -f deployment.yaml kubectl delete -f volume.yaml

Review

You deployed a MySQL database to a Kubernetes cluster using Kubernetes configuration files.

Helm is a package manager for Kubernetes. It can make deploying databases and other applications easier on a Kubernetes cluster. You use it next.

Task 3. Use Helm to deploy MySQL on the cluster

You should still be in Cloud Shell, connected to your Kubernetes cluster.

  1. To add the Bitnami Helm repository to your cluster, enter the following command:
helm repo add bitnami https://charts.bitnami.com/bitnami
  1. To update the Helm packages, enter the following command:
helm repo update
  1. Install a MySQL named mydb using Helm:
helm install mydb bitnami/mysql

Click Check my progress to verify the objective. Use Helm to deploy MySQL on the cluster

  1. Read the output from the Helm install command and connect to your database using the instructions provided.

  2. When you are connected to the database, exit to return to the Cloud Shell command prompt.

  3. To see your Helm deployment, enter the following command:

helm ls

Notice that the deployment has the name mydb specified in the install command.

  1. To delete the deployment, enter the following command:
helm delete mydb

Congratulations! You have created a Kubernetes cluster and then deployed MySQL databases into it, first using your own configuration code, and then using Helm.

End your lab

When you have completed your lab, click End Lab. Google Skills removes the resources you’ve used and cleans the account for you.

You will be given an opportunity to rate the lab experience. Select the applicable number of stars, type a comment, and then click Submit.

The number of stars indicates the following:

  • 1 star = Very dissatisfied
  • 2 stars = Dissatisfied
  • 3 stars = Neutral
  • 4 stars = Satisfied
  • 5 stars = Very satisfied

You can close the dialog box if you don't want to provide feedback.

For feedback, suggestions, or corrections, please use the Support tab.

Copyright 2026 Google LLC All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.

Avant de commencer

  1. Les ateliers créent un projet Google Cloud et des ressources pour une durée déterminée.
  2. Les ateliers doivent être effectués dans le délai imparti et ne peuvent pas être mis en pause. Si vous quittez l'atelier, vous devrez le recommencer depuis le début.
  3. En haut à gauche de l'écran, cliquez sur Démarrer l'atelier pour commencer.

Utilisez la navigation privée

  1. Copiez le nom d'utilisateur et le mot de passe fournis pour l'atelier
  2. Cliquez sur Ouvrir la console en navigation privée

Connectez-vous à la console

  1. Connectez-vous à l'aide des identifiants qui vous ont été attribués pour l'atelier. L'utilisation d'autres identifiants peut entraîner des erreurs ou des frais.
  2. Acceptez les conditions d'utilisation et ignorez la page concernant les ressources de récupération des données.
  3. Ne cliquez pas sur Terminer l'atelier, à moins que vous n'ayez terminé l'atelier ou que vous ne vouliez le recommencer, car cela effacera votre travail et supprimera le projet.

Ce contenu n'est pas disponible pour le moment

Nous vous préviendrons par e-mail lorsqu'il sera disponible

Parfait !

Nous vous contacterons par e-mail s'il devient disponible

Un atelier à la fois

Confirmez pour mettre fin à tous les ateliers existants et démarrer celui-ci

Utilisez la navigation privée pour effectuer l'atelier

Le meilleur moyen d'exécuter cet atelier consiste à utiliser une fenêtre de navigation privée. Vous éviterez ainsi les conflits entre votre compte personnel et le compte temporaire de participant, qui pourraient entraîner des frais supplémentaires facturés sur votre compte personnel.