The document discusses the MySQL Operator for Kubernetes, which allows users to run MySQL clusters on Kubernetes. It provides an overview of how the operator works using the Kopf framework to create Kubernetes custom resources and controllers. It describes how the operator creates deployments, services, and other resources to set up MySQL servers in a stateful set, a replica set for routers, and monitoring. The document also provides instructions for installing the MySQL Operator using Kubernetes manifests or Helm.
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Exploring MySQL Operator for Kubernetes in Python
1. Fault Tolerance
Exploration of MySQL Operator
for Kubernetes in Python
October 29, 2022
Ivan Ma
MySQL Master principal Solution Engineer
2. The following is intended to outline our general product direction.
It is intended for information purposes only, and may not be
incorporated into any contract. It is not a commitment to deliver
any material, code, or functionality, and should not be relied upon
in making purchasing decisions. The development, release,
timing, and pricing of any features or functionality described for
Oracle’s products may change and remains at the sole discretion
of Oracle Corporation.
Safe harbor statement
2
3. MySQL Operator for Kubernetes
• Pod [ mysqloperator ]
• Dockerfile [ building the image ]
• https://github.com/mysql/mysql-operator/blob/trunk/docker-build/Dockerfile
• Installed with MySQL Shell
• mysqloperator package for Python
• COPY mysqloperator/ /usr/lib/mysqlsh/python-packages/mysqloperator
• Kopf
• Framework to build Kubernetes operators in Python
• https://kopf.readthedocs.io/en/stable/architecture/
4. kopf operator creation
• Manual Execution
• pip3 install kopf
• Create CRD
• Create the myoperator.py
• “Manually”
• kopf run myoprator.py
• Creating the resource object
External Reference Only : https://blog.baeke.info/2020/01/26/writing-a-kubernetes-
operator-with-kopf/
6. Creation of crd
# kubectl apply –f demowebs-crd.yaml
# kubectl get crd demowebs.mygroup.info
NAME CREATED AT
demowebs.mygroup.info 2022-10-21T04:05:00Z
9. The resource object
• The resource object DemoWeb [kind] is created - A definition ONLY
• What next : to execute the operator
• # kopf run --namespace=”<namespaces>” myoperator.py
10. How the MySQL Operator works
https://github.com/mysql/mysql-operator/blob/trunk/mysqloperator/controller/innodbcluster/operator_cluster.py
• @kopf.on.create(consts.GROUP, consts.VERSION, consts.INNODBCLUSTER_PLURAL)
• 1. prepare_initconf è2. prepare_secrets
• 3. prepare_router_secrets è 4. prepare_cluster_service
• 5. prepare-service_account è 6. prepare_role_binding
• 7. prepare_cluster_stateful_set è 8. prepare_cluster_pod_disruption_budget
• 9. prepare_router_service è 10 prepare_router_deployment
• 11 prepare_backup_secrets è
• Finally : set cluster status è online instance = 0, status as PENDING
• @kopf.on.delete(consts.GROUP, consts.VERSION,consts.INNODBCLUSTER_PLURAL)
• @kopf.on.filed(consts.GROUP, const.VERSION, consts.INNODBCLUSTER_PLURAL, filed=“….”)
• @kopf.on.field(consts.GROUP, consts.VERSION, consts.INNODBCLUSTER_PLURAL,field="spec.version") (spec.router.version)
• cluster_ctl.on_server_version_change(new)
• @kopf.on.create("", "v1", "pods",labels={"component": "mysqld"})
• @kopf.on.event ("", "v1", "pods",labels={"component": "mysqld"})
• @kopf.on.delete("", "v1", "pods", labels={"component": "mysqld"})
15. Connecting to InnoDB Cluster with MySQL Operator Image
$> kubectl run --rm -it myshell -n <the ns> --image=mysql/mysql-operator – mysqlsh
If you don't see a command prompt, try pressing enter. MySQL JS >
16. More on Operations
MySQL Operator for Kubernetes
• Checking Innodb cluster status:
• kubectl get innodbcluster --watch –n <namespace>
• Retrieve IP address of cluster:
• kubectl get service mycluster –n <namespace>
• Describe the storage (PVC) for a MySQL server:
• kubectl describe pvc datadir-mycluster-[0|1|2|…] –n <namespace>
• Exposing ports (applications outside of Kubernetes):
• kubectl port-forward service/mycluster mysql –n <namespace>
• kubectl expose rs mycluster-router --port=6446 --target-port=6446 --type=LoadBalancer -
-name mycluster-lb –n <namespace>