Install Percona XtraDB Cluster using kubectl¶
The kubectl command line utility is a tool used before anything else to interact with Kubernetes and containerized applications running on it. Users can run kubectl to deploy applications, manage cluster resources, check logs, etc.
Pre-requisites¶
The following tools are used in this guide and therefore should be preinstalled:
-
The Git distributed version control system. You can install it following the official installation instructions.
-
The kubectl tool to manage and deploy applications on Kubernetes, included in most Kubernetes distributions. Install it, if not present, following the official installation instructions.
Install the Operator and Percona XtraDB Cluster¶
The following steps are needed to deploy the Operator and Percona XtraDB Cluster in your Kubernetes environment:
-
Deploy the Operator with the following command:
$ kubectl apply -f https://raw.githubusercontent.com/percona/percona-xtradb-cluster-operator/v1.12.0/deploy/bundle.yaml
Expected output
customresourcedefinition.apiextensions.k8s.io/perconaxtradbclusters.pxc.percona.com created customresourcedefinition.apiextensions.k8s.io/perconaxtradbclusterbackups.pxc.percona.com created customresourcedefinition.apiextensions.k8s.io/perconaxtradbclusterrestores.pxc.percona.com created customresourcedefinition.apiextensions.k8s.io/perconaxtradbbackups.pxc.percona.com created role.rbac.authorization.k8s.io/percona-xtradb-cluster-operator created serviceaccount/percona-xtradb-cluster-operator created rolebinding.rbac.authorization.k8s.io/service-account-percona-xtradb-cluster-operator created deployment.apps/percona-xtradb-cluster-operator created
As the result you will have the Operator Pod up and running.
-
Deploy Percona XtraDB Cluster:
$ kubectl apply -f https://raw.githubusercontent.com/percona/percona-xtradb-cluster-operator/v1.12.0/deploy/cr.yaml
Expected output
perconaxtradbcluster.pxc.percona.com/ cluster1 created
Note
This deploys default Percona XtraDB Cluster configuration with three HAProxy and three XtraDB Cluster instances. Please see deploy/cr.yaml and Custom Resource Options for the configuration options. You can clone the repository with all manifests and source code by executing the following command:
$ git clone -b v1.12.0 https://github.com/percona/percona-xtradb-cluster-operator
After editing the needed options, apply your modified
deploy/cr.yaml
file as follows:$ kubectl apply -f deploy/cr.yaml
The creation process may take some time. When the process is over your cluster will obtain the
ready
status. You can check it with the following command:$ kubectl get pxc
Expected output
NAME ENDPOINT STATUS PXC PROXYSQL HAPROXY AGE cluster1 cluster1-haproxy.default ready 3 3 5m51s
Verifying the cluster operation¶
It may take ten minutes to get the cluster started. When kubectl get pxc
command finally shows you the cluster status as ready
, you can try to connect
to the cluster.
-
You will need the login and password for the admin user to access the cluster. Use
kubectl get secrets
command to see the list of Secrets objects (by default the Secrets object you are interested in hascluster1-secrets
name). You can use the following command to get the password of theroot
user:$ kubectl get secrets cluster1-secrets -o yaml -o jsonpath='{.data.root}' | base64 --decode | tr '\n' ' ' && echo " "
-
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
Executing it may require some time to deploy the correspondent Pod.
-
Now run
mysql
tool in the percona-client command shell using the password obtained from the secret. The command will look different depending on whether your cluster provides load balancing with HAProxy (the default choice) or ProxySQL:$ mysql -h cluster1-haproxy -uroot -proot_password
$ mysql -h cluster1-proxysql -uroot -proot_password