Install Percona Distribution for MySQL on Amazon Elastic Kubernetes Service (EKS)¶
This guide shows you how to deploy Percona Operator for MySQL on Amazon Elastic Kubernetes Service (EKS). The document assumes some experience with Amazon EKS. For more information on the EKS, see the Amazon EKS official documentation .
Prerequisites¶
The following tools are used in this guide and therefore should be preinstalled:
-
AWS Command Line Interface (AWS CLI) for interacting with the different parts of AWS. You can install it following the official installation instructions for your system .
-
eksctl to simplify cluster creation on EKS. It can be installed along its installation notes on GitHub .
-
kubectl to manage and deploy applications on Kubernetes. Install it following the official installation instructions .
Also, you need to configure AWS CLI with your credentials according to the official guide .
Create the EKS cluster¶
-
To create your cluster, you will need the following data:
- name of your EKS cluster,
- AWS region in which you wish to deploy your cluster,
- the amount of nodes you would like tho have,
- the desired ratio between on-demand and spot instances in the total number of nodes.
Note
spot instances are not recommended for production environment, but may be useful e.g. for testing purposes.
After you have settled all the needed details, create your EKS cluster following the official cluster creation instructions .
-
After you have created the EKS cluster, you also need to install the Amazon EBS CSI driver on your cluster. See the official documentation on adding it as an Amazon EKS add-on.
Install the Operator and deploy your MySQL cluster¶
-
Create a namespace and set the context for the namespace. The resource names must be unique within the namespace and provide a way to divide cluster resources between users spread across multiple projects.
So, create the namespace and save it in the namespace context for subsequent commands as follows (replace the
<namespace name>
placeholder with some descriptive name):$ kubectl create namespace <namespace name> $ kubectl config set-context $(kubectl config current-context) --namespace=<namespace name>
At success, you will see the message that namespace/
was created, and the context was modified. -
Use the following
git clone
command to download the correct branch of the percona-server-mysql-operator repository:$ git clone -b v0.10.0 https://github.com/percona/percona-server-mysql-operator
After the repository is downloaded, change the directory to run the rest of the commands in this document:
$ cd percona-server-mysql-operator
-
Deploy the Operator using the following command:
$ kubectl apply --server-side -f deploy/bundle.yaml
The following confirmation is returned:
customresourcedefinition.apiextensions.k8s.io/perconaserverformysqlbackups.ps.percona.com created customresourcedefinition.apiextensions.k8s.io/perconaserverformysqlrestores.ps.percona.com created customresourcedefinition.apiextensions.k8s.io/perconaserverformysqls.ps.percona.com created serviceaccount/percona-server-for-mysql-operator created role.rbac.authorization.k8s.io/percona-server-for-mysql-operator-leader-election-role created role.rbac.authorization.k8s.io/percona-server-for-mysql-operator-role created rolebinding.rbac.authorization.k8s.io/percona-server-for-mysql-operator-leader-election-rolebinding created rolebinding.rbac.authorization.k8s.io/percona-server-for-mysql-operator-rolebinding created configmap/percona-server-for-mysql-operator-config created deployment.apps/percona-server-for-mysql-operator created
-
The operator has been started, and you can create the Percona Distribution for MySQL cluster:
$ kubectl apply -f deploy/cr.yaml
The process could take some time. The return statement confirms the creation:
perconaserverformysql.ps.percona.com/cluster1 created
Verify the cluster operation¶
To connect to Percona Server for MySQL you will need the password for the root user. Passwords are stored in the Secrets object, which was generated during the previous steps.
Here’s how to get it:
-
List the Secrets objects.
It will show you the list of Secrets objects (by default the Secrets object you are interested in has$ kubectl get secrets
cluster1-secrets
name). -
Use the following command to get the password of the
root
user. Substitutecluster1
with your value, if needed:$ kubectl get secret cluster1-secrets -o yaml
The command returns the YAML file with generated Secrets, including the
root
password, which should look as follows:... data: ... root: <base64-encoded-password>
-
The actual password is base64-encoded. Use the following command to bring it back to a human-readable form:
$ echo '<base64-encoded-password>' | base64 --decode
-
Run a container with
mysql
tool and connect its console output to your terminal. The following command will do this, naming the new Podpercona-client
:$ kubectl run -i --rm --tty percona-client --image=percona:8.0 --restart=Never -- bash -il
It may require some time to execute the command and deploy the correspondent Pod.
-
Now run
mysql
tool in thepercona-client
command shell using the password obtained from the Secret instead of the<root password>
placeholder. The command will look different depending on whether the cluster uses load balancing with HAProxy (the default behavior) or uses MySQL Router (can be used with Group Replication clusters):$ mysql -h cluster1-haproxy -uroot -p<root password>
$ mysql -h cluster1-router -uroot -p<root password>
Expected output
mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4065 Server version: 8.0.29-21 Percona Server (GPL), Release 21, Revision c59f87d2854 Copyright (c) 2009-2022 Percona LLC and/or its affiliates Copyright (c) 2000, 2022, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
The following example uses the MySQL prompt to check the
max_connections
variable:mysql> SHOW VARIABLES LIKE "max_connections";
Expected output
+-----------------+-------+ | Variable_name | Value | +-----------------+-------+ | max_connections | 158 | +-----------------+-------+ 1 row in set (0.02 sec) mysql>
-
You can also check wether you can connect to MySQL from the outside with the help of the
kubectl port-forward
command as follows:$ kubectl port-forward svc/cluster1-mysql-primary 3306:3306 & $ mysql -h 127.0.0.1 -P 3306 -uroot -p<root password>