Create Kubernetes cluster on Google Kubernetes Engine (GKE)¶
Prerequisites¶
All commands from this guide can be run either in the Google Cloud shell or in your local shell.
To use Google Cloud shell, you need nothing but a modern web browser.
If you would like to use your local shell, install the following:
-
gcloud. This tool is part of the Google Cloud SDK. To install it, select your operating system on the official Google Cloud SDK documentation page and then follow the instructions.
-
kubectl. It is the Kubernetes command-line tool you will use to manage and deploy applications. To install the tool, run the following command:
$ gcloud auth login $ gcloud components install kubectl
Create and configure the GKE cluster¶
Important
To run a 3-node pxc cluster, you will need at least a 3-node cluster with 2vCPUs available. The database will not be created if you attempt to create a database cluster in a Kubernetes cluster without sufficient resources.
You can configure the settings using the gcloud
tool. You can run it either in
the Cloud Shell or in your
local shell (if you have installed Google Cloud SDK locally on the previous
step). The following command will create a cluster named my-cluster-name
:
$ gcloud container clusters create my-cluster-name --project <project name> --zone us-central1-a --cluster-version 1.25 --machine-type n1-standard-4 --num-nodes=3
Note
You must edit the previous command and other command-line statements to
replace the <project name>
placeholder with your project name. You may
also be required to edit the zone location, which is set to us-central1
in the above example. Other parameters specify that we are creating a
cluster with 3 nodes and with machine type of 4 vCPUs.
You may wait a few minutes for the cluster to be generated.
When the process is over, you can see it listed in the Google Cloud console
Select Kubernetes Engine → Clusters in the left menu panel:
Now you should configure the command-line access to your newly created cluster
to make kubectl
be able to use it.
In the Google Cloud Console, select your cluster and then click the Connect shown on the above image. You will see the connect statement which configures the command-line access. After you have edited the statement, you may run the command in your local shell:
$ gcloud container clusters get-credentials my-cluster-name --zone us-central1-a --project <project name>
Finally, use your Cloud Identity and Access Management (Cloud IAM) to control access to the cluster. The following command will give you the ability to create Roles and RoleBindings:
kubectl create clusterrolebinding cluster-admin-binding --clusterrole cluster-admin --user $(gcloud config get-value core/account)
Expected output
clusterrolebinding.rbac.authorization.k8s.io/cluster-admin-binding created
Remove the GKE cluster¶
You can clean up the cluster with the gcloud
command as follows:
$ gcloud container clusters delete <cluster name>
The return statement requests your confirmation of the deletion. Type y
to confirm.
Also, you can delete your cluster via the Google Cloud console
Just click the Delete
popup menu item in the clusters list:
The cluster deletion may take time.
Warning
After deleting the cluster, all data stored in it will be lost!
Get expert help¶
If you need assistance, visit the community forum for comprehensive and free database knowledge, or contact our Percona Database Experts for professional support and services.