This guide provides a quick-start guide for users of the Oracle MySQL Operator.
- Kubernetes
- The mysql-operator repo checked out locally
First create the namespace that the operator will reside in. By default this is mysql-operator:
kubectl create ns mysql-operator
The MySQL Operator is installed into your cluster with a Helm chart
Install the helm tool locally by following these instructions
If you have not already installed tiller to your cluster set it up with:
helm initVerify helm is installed :
helm version
Client: &version.Version{SemVer:"v2.5.0", GitCommit:"012cb0ac1a1b2f888144ef5a67b8dab6c2d45be6", GitTreeState:"clean"}
Server: &version.Version{SemVer:"v2.5.0", GitCommit:"012cb0ac1a1b2f888144ef5a67b8dab6c2d45be6", GitTreeState:"clean"}The helm chart for the operator is included in this git repo, run the following in the root of the checked out mysql-operator repo.
To install the chart in a cluster without RBAC with the release name my-release:
$ helm install --name my-release mysql-operatorIf your cluster has RBAC enabled then you will need to run:
$ helm install --name my-release mysql-operator --set rbac.enabled=trueThe above command deploys the MySQL Operator on the Kubernetes cluster in the default configuration. The configuration section lists the parameters that can be configured during installation.
Tip: List all releases using
helm list
To uninstall/delete the my-release deployment:
$ helm delete my-releaseThe command removes all the Kubernetes components associated with the chart and deletes the release.
The following tables lists the configurable parameters of the MySQL-operator chart and their default values.
| Parameter | Description | Default |
|---|---|---|
rbac.enabled |
If true, enables RBAC | false |
operator.namespace |
Controls the namespace in which the operator is deployed | mysql-operator |
Now let's create a new MySQL cluster. Create a cluster.yaml file with the following contents
apiVersion: mysql.oracle.com/v1
kind: MySQLCluster
metadata:
name: myappdbAnd create it with kubectl
$ kubectl apply -f cluster.yaml
mysqlcluster "myappdb" created
You should now have a cluster in the default namespace
$ kubectl get mysqlclusters
NAME KIND
myappdb MySQLCluster.v1.mysql.oracle.com
To find out how to create larger clusters, and configure storage see Clusters.
The first thing you need to do is fetch the MySQL root password which is auto-generated for us by default and stored ia secret named <dbname>-root-password
$ kubectl get secret myappdb-root-password -o jsonpath="{.data.password}" | base64 -D
ETdmMKh2UuDq9m7y
You can use a MySQL client container to verify that you can connect to MySQL inside the Kubernetes cluster.
$ kubectl run mysql-client --image=mysql:5.7 -i -t --rm --restart=Never \
-- mysql -h myappdb -uroot -pETdmMKh2UuDq9m7y -e 'SELECT 1'
Waiting for pod default/mysql-client to be running, status is Pending, pod ready: false
mysql: [Warning] Using a password on the command line interface can be insecure.
+---+
| 1 |
+---+
| 1 |
+---+
Note: If helm list gives the following error
Error: User "system:serviceaccount:kube-system:default" cannot list configmaps in the namespace "kube-system". (get configmaps)then it could be because the cluster you are targeting has role-based-authentication (RBAC) enabled. To fix this, issue the following commands:
kubectl create serviceaccount --namespace kube-system tiller
kubectl create clusterrolebinding \
tiller-cluster-rule \
--clusterrole=cluster-admin \
--serviceaccount=kube-system:tiller
kubectl patch deploy --namespace kube-system \
tiller-deploy \
-p '{"spec":{"template":{"spec":{"serviceAccount":"tiller"}}}}'