If you have an existing Kubernetes cluster with multiple nodes, each having a unique namespace and running a MySQL database server, you can install and verify the MySQL Operator on this cluster. The MySQL Operator is an operator for managing MySQL InnoDB Cluster setups inside a Kubernetes Cluster. It automates the setup and maintenance of MySQL InnoDB Cluster setups, including upgrades and backups [Source 0].
To install and verify the MySQL Operator, follow these steps:
-
Install the MySQL Operator
Use
kubectl
to install the MySQL Operator by applying the manifest files. The manifest files contain the required Custom Resource Definitions (CRDs) and the operator deployment configuration.Apply the CRDs:
kubectl apply -f https://raw.githubusercontent.com/mysql/mysql-operator/trunk/deploy/deploy-crds.yaml
Then apply the operator:
kubectl apply -f https://raw.githubusercontent.com/mysql/mysql-operator/trunk/deploy/deploy-operator.yaml
-
Verify the Operator Deployment
After applying the operator, you can verify its deployment by checking the status of the deployed resources. Run the following command to check the status of the operator:
kubectl get deployment -n mysql-operator mysql-operator
This command should show you the MySQL operator deployment status. If the operator is running correctly, it should display
1/1
under theREADY
column [Source 0]. -
Create a MySQL InnoDB Cluster
Once the MySQL Operator is running, you can create a MySQL InnoDB Cluster. First, create a secret with the credentials for a MySQL root user:
kubectl create secret generic mypwds \ --from-literal=rootUser=root \ --from-literal=rootHost=% \ --from-literal=rootPassword="sakila"
Then, define your MySQL InnoDB Cluster in a YAML file, for example,
mycluster.yaml
:apiVersion: mysql.oracle.com/v2 kind: InnoDBCluster metadata: name: mycluster spec: secretName: mypwds tlsUseSelfSigned: true instances: 3 router: instances: 1
Apply the cluster configuration:
kubectl apply -f mycluster.yaml
-
Monitor the Cluster Creation
After applying the cluster configuration, you can monitor the cluster creation process using the following command:
kubectl get innodbcluster --watch
Once the cluster is successfully created, the
STATUS
should change toONLINE
[Source 0]. -
Connect to the MySQL InnoDB Cluster
You can connect to the MySQL InnoDB Cluster using the MySQL Shell. The following command creates a new container named
myshell
using thecontainer-registry.oracle.com/mysql/community-operator
image and immediately executes MySQL Shell:kubectl run --rm -it myshell --image=container-registry.oracle.com/mysql/community-operator -- mysqlsh
Then, you can connect to the cluster using the MySQL Shell with the command
\connect root@mycluster
. This assumes that the default namespace is used. The long form is{innodbclustername}.{namespace}.svc.cluster.local
[Source 0].
Remember to install the MySQL Operator in the same namespace where the MySQL databases are running. If each node in your cluster has its own namespace and MySQL database, you might need to install the Operator in each namespace separately.