SlideShare a Scribd company logo
Fault Tolerance
Exploration of MySQL Operator
for Kubernetes in Python
October 29, 2022
Ivan Ma
MySQL Master principal Solution Engineer
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
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/
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/
CRD - example
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: demowebs.mygroup.info
spec:
scope: Namespaced
group: mygroup.info
versions:
- name: v1
served: true
storage: true
schema:
openAPIV3Schema:
type: object
properties:
spec:
type: object
properties:
gitRepo:
type: string
replicas:
type: integer
names:
kind: DemoWeb
plural: demowebs
singular: demoweb
shortNames:
- dweb
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
Creating the Resource Object
kubectl create ns mydemo
cat << EOF |kubectl apply -n mydemo -f -
apiVersion: mygroup.info/v1
kind: DemoWeb
metadata:
name: mydemoweb
spec:
replicas: 2
gitRepo: "https://github.com/ivanxma/staticweb.git"
EOF
Creation of the myoperator.py
The operator to be executed by “kopf”
import kopf
import kubernetes.client
from kubernetes.client.rest import ApiException
import yaml
@kopf.on.create('mygroup.info', 'v1', 'demowebs')
def create_fn(spec, **kwargs):
name = kwargs["body"]["metadata"]["name"]
print("Name is %sn" % name)
# Create the deployment spec
doc = yaml.safe_load(f"""
apiVersion: apps/v1
kind: Deployment
metadata:
name: {name}-deployment
labels:
app: {name}
spec:
replicas: {spec.get('replicas', 1)}
selector:
matchLabels:
app: {name}
template:
metadata:
labels:
app: {name}
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
volumeMounts:
- name: workdir
mountPath: /usr/share/nginx/html
initContainers:
- name: install
image: alpine/git
command:
- git
- clone
- {spec.get('gitrepo', 'https://github.com/ivanxma/staticweb.git')}
- /work-dir
volumeMounts:
- name: workdir
mountPath: /work-dir
dnsPolicy: Default
volumes:
- name: workdir
emptyDir: {{}}
""")
# Adopt the Yaml and Apply
kopf.adopt(doc)
api = kubernetes.client.AppsV1Api()
try:
depl =
api.create_namespaced_deployment(namespace=doc['metadata']['nam
espace'], body=doc)
except ApiException as e:
print("Exception when calling AppsV1Api-
>create_namespaced_deployment: %sn" % e)
CRD : kind : DemoWeb
spec properties : replicas, gitRepos
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
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"})
MySQL Operator
Creation of Innodb Cluster in K8s
11
mysql-2
mysql-1
mysql-0
Kubernetes Environment
MySQL InnoDB Cluster
application-0
apps-0
app-0 app-1
LB
Container
Bins  Libs
App
Container
Bins  Libs
App
mysql-mon-0
mem-0
Container
Bins  Libs
MySQL
Monitor
mysql-innodb-cluster-0
mysql-routers [Replicaset]
router-x
Container
Bins  Libs
MySQL
Router
router-y
Container
Bins  Libs
MySQL
Router
K8s
Service
mysql-servers [Statefulset]
mysql-0
Container
Bins  Libs
MySQL
mysql-1
Container
Bins  Libs
MySQL
mysql-2
Container
Bins  Libs
MySQL
GR GR
prim
ary
router-z
Container
Bins  Libs
MySQL
Router
Deployment
pod
Kopf framework
mysql-operator
Manifest Installation
MySQL Operator for Kubernetes
• https://github.com/mysql/mysql-operator
• https://dev.mysql.com/doc/mysql-operator/en/mysql-operator-installation-kubectl.html
• 1- Apply Custom Resource Definition:
• $> kubectl apply -f https://raw.githubusercontent.com/mysql/mysql-operator/trunk/deploy/deploy-
crds.yaml
• 2- Deploy operator
• $> kubectl apply -f https://raw.githubusercontent.com/mysql/mysql-operator/trunk/deploy/deploy-
operator.yaml
• 3- Describe operator
• $> kubectl get deployment mysql-operator --namespace mysql-operator
Helm installation
MySQL Operator for Kubernetes
• https://dev.mysql.com/doc/mysql-operator/en/mysql-operator-installation-helm.html
• $> helm repo add mysql-operator https://mysql.github.io/mysql-operator/
• $> helm repo update
• $> helm install my-mysql-operator mysql-operator/mysql-operator --namespace mysql-operator --create-
namespace
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 >
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>
Thank you

More Related Content

Similar to Exploring MySQL Operator for Kubernetes in Python (20)

PDF
Cloud-native applications with Java and Kubernetes - Yehor Volkov
Kuberton
 
PDF
Build containerized application using Docker and Azure.pdf
Hamida Rebai Trabelsi
 
PDF
Cloud-native .NET-Microservices mit Kubernetes @BASTAcon
Mario-Leander Reimer
 
PPTX
Kubernetes @ meetic
Sébastien Le Gall
 
PDF
Docker kubernetes fundamental(pod_service)_190307
Inhye Park
 
PDF
DevOps Workflow: A Tutorial on Linux Containers
inside-BigData.com
 
PDF
Microservices in Java
Anatole Tresch
 
PDF
Continuous Deployment with Kubernetes, Docker and GitLab CI
alexanderkiel
 
PDF
Mihai Criveti - PyCon Ireland - Automate Everything
Mihai Criveti
 
PDF
Pro2516 10 things about oracle and k8s.pptx-final
Michel Schildmeijer
 
PDF
Revolutionizing WSO2 PaaS with Kubernetes & App Factory
Imesh Gunaratne
 
PDF
GitOps & the deployment branching models - DevOps D-day Marseille 2021
SoKube
 
PDF
Priming Your Teams For Microservice Deployment to the Cloud
Matt Callanan
 
PPTX
Kubernetes workshop -_the_basics
Sjuul Janssen
 
PPTX
使用 Prometheus 監控 Kubernetes Cluster
inwin stack
 
PPTX
WSO2Con USA 2015: Revolutionizing WSO2 PaaS with Kubernetes & App Factory
WSO2
 
PDF
Build Your Own CaaS (Container as a Service)
HungWei Chiu
 
PDF
04_Azure Kubernetes Service: Basic Practices for Developers_GAB2019
Kumton Suttiraksiri
 
PDF
Getting Started with MariaDB with Docker
MariaDB plc
 
PPTX
Amazon Web Services and Docker: from developing to production
Paolo latella
 
Cloud-native applications with Java and Kubernetes - Yehor Volkov
Kuberton
 
Build containerized application using Docker and Azure.pdf
Hamida Rebai Trabelsi
 
Cloud-native .NET-Microservices mit Kubernetes @BASTAcon
Mario-Leander Reimer
 
Kubernetes @ meetic
Sébastien Le Gall
 
Docker kubernetes fundamental(pod_service)_190307
Inhye Park
 
DevOps Workflow: A Tutorial on Linux Containers
inside-BigData.com
 
Microservices in Java
Anatole Tresch
 
Continuous Deployment with Kubernetes, Docker and GitLab CI
alexanderkiel
 
Mihai Criveti - PyCon Ireland - Automate Everything
Mihai Criveti
 
Pro2516 10 things about oracle and k8s.pptx-final
Michel Schildmeijer
 
Revolutionizing WSO2 PaaS with Kubernetes & App Factory
Imesh Gunaratne
 
GitOps & the deployment branching models - DevOps D-day Marseille 2021
SoKube
 
Priming Your Teams For Microservice Deployment to the Cloud
Matt Callanan
 
Kubernetes workshop -_the_basics
Sjuul Janssen
 
使用 Prometheus 監控 Kubernetes Cluster
inwin stack
 
WSO2Con USA 2015: Revolutionizing WSO2 PaaS with Kubernetes & App Factory
WSO2
 
Build Your Own CaaS (Container as a Service)
HungWei Chiu
 
04_Azure Kubernetes Service: Basic Practices for Developers_GAB2019
Kumton Suttiraksiri
 
Getting Started with MariaDB with Docker
MariaDB plc
 
Amazon Web Services and Docker: from developing to production
Paolo latella
 

More from Ivan Ma (17)

PDF
20201106 hk-py con-mysql-shell
Ivan Ma
 
PDF
20200613 my sql-ha-deployment
Ivan Ma
 
PDF
20191001 bkk-secret-of inno-db_clusterv1
Ivan Ma
 
PDF
20190817 coscup-oracle my sql innodb cluster sharing
Ivan Ma
 
PDF
20190615 hkos-mysql-troubleshootingandperformancev2
Ivan Ma
 
PDF
20180420 hk-the powerofmysql8
Ivan Ma
 
PDF
20171104 hk-py con-mysql-documentstore_v1
Ivan Ma
 
PDF
MySQL InnoDB Cluster and MySQL Group Replication @HKOSC 2017
Ivan Ma
 
PDF
What's New in MySQL 8.0 @ HKOSC 2017
Ivan Ma
 
PDF
20161029 py con-mysq-lv3
Ivan Ma
 
PDF
20160821 coscup-my sql57docstorelab01
Ivan Ma
 
PDF
Hkosc group replication-lecture_lab07
Ivan Ma
 
PDF
20151010 my sq-landjavav2a
Ivan Ma
 
PDF
01 demystifying mysq-lfororacledbaanddeveloperv1
Ivan Ma
 
PDF
Exploring mysql cluster 7.4
Ivan Ma
 
PDF
20150110 my sql-performanceschema
Ivan Ma
 
PDF
20141011 my sql clusterv01pptx
Ivan Ma
 
20201106 hk-py con-mysql-shell
Ivan Ma
 
20200613 my sql-ha-deployment
Ivan Ma
 
20191001 bkk-secret-of inno-db_clusterv1
Ivan Ma
 
20190817 coscup-oracle my sql innodb cluster sharing
Ivan Ma
 
20190615 hkos-mysql-troubleshootingandperformancev2
Ivan Ma
 
20180420 hk-the powerofmysql8
Ivan Ma
 
20171104 hk-py con-mysql-documentstore_v1
Ivan Ma
 
MySQL InnoDB Cluster and MySQL Group Replication @HKOSC 2017
Ivan Ma
 
What's New in MySQL 8.0 @ HKOSC 2017
Ivan Ma
 
20161029 py con-mysq-lv3
Ivan Ma
 
20160821 coscup-my sql57docstorelab01
Ivan Ma
 
Hkosc group replication-lecture_lab07
Ivan Ma
 
20151010 my sq-landjavav2a
Ivan Ma
 
01 demystifying mysq-lfororacledbaanddeveloperv1
Ivan Ma
 
Exploring mysql cluster 7.4
Ivan Ma
 
20150110 my sql-performanceschema
Ivan Ma
 
20141011 my sql clusterv01pptx
Ivan Ma
 
Ad

Recently uploaded (20)

PDF
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PPTX
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
DOCX
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
PPTX
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PDF
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
Ad

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/
  • 5. CRD - example apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: name: demowebs.mygroup.info spec: scope: Namespaced group: mygroup.info versions: - name: v1 served: true storage: true schema: openAPIV3Schema: type: object properties: spec: type: object properties: gitRepo: type: string replicas: type: integer names: kind: DemoWeb plural: demowebs singular: demoweb shortNames: - dweb
  • 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
  • 7. Creating the Resource Object kubectl create ns mydemo cat << EOF |kubectl apply -n mydemo -f - apiVersion: mygroup.info/v1 kind: DemoWeb metadata: name: mydemoweb spec: replicas: 2 gitRepo: "https://github.com/ivanxma/staticweb.git" EOF
  • 8. Creation of the myoperator.py The operator to be executed by “kopf” import kopf import kubernetes.client from kubernetes.client.rest import ApiException import yaml @kopf.on.create('mygroup.info', 'v1', 'demowebs') def create_fn(spec, **kwargs): name = kwargs["body"]["metadata"]["name"] print("Name is %sn" % name) # Create the deployment spec doc = yaml.safe_load(f""" apiVersion: apps/v1 kind: Deployment metadata: name: {name}-deployment labels: app: {name} spec: replicas: {spec.get('replicas', 1)} selector: matchLabels: app: {name} template: metadata: labels: app: {name} spec: containers: - name: nginx image: nginx ports: - containerPort: 80 volumeMounts: - name: workdir mountPath: /usr/share/nginx/html initContainers: - name: install image: alpine/git command: - git - clone - {spec.get('gitrepo', 'https://github.com/ivanxma/staticweb.git')} - /work-dir volumeMounts: - name: workdir mountPath: /work-dir dnsPolicy: Default volumes: - name: workdir emptyDir: {{}} """) # Adopt the Yaml and Apply kopf.adopt(doc) api = kubernetes.client.AppsV1Api() try: depl = api.create_namespaced_deployment(namespace=doc['metadata']['nam espace'], body=doc) except ApiException as e: print("Exception when calling AppsV1Api- >create_namespaced_deployment: %sn" % e) CRD : kind : DemoWeb spec properties : replicas, gitRepos
  • 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"})
  • 11. MySQL Operator Creation of Innodb Cluster in K8s 11
  • 12. mysql-2 mysql-1 mysql-0 Kubernetes Environment MySQL InnoDB Cluster application-0 apps-0 app-0 app-1 LB Container Bins Libs App Container Bins Libs App mysql-mon-0 mem-0 Container Bins Libs MySQL Monitor mysql-innodb-cluster-0 mysql-routers [Replicaset] router-x Container Bins Libs MySQL Router router-y Container Bins Libs MySQL Router K8s Service mysql-servers [Statefulset] mysql-0 Container Bins Libs MySQL mysql-1 Container Bins Libs MySQL mysql-2 Container Bins Libs MySQL GR GR prim ary router-z Container Bins Libs MySQL Router Deployment pod Kopf framework mysql-operator
  • 13. Manifest Installation MySQL Operator for Kubernetes • https://github.com/mysql/mysql-operator • https://dev.mysql.com/doc/mysql-operator/en/mysql-operator-installation-kubectl.html • 1- Apply Custom Resource Definition: • $> kubectl apply -f https://raw.githubusercontent.com/mysql/mysql-operator/trunk/deploy/deploy- crds.yaml • 2- Deploy operator • $> kubectl apply -f https://raw.githubusercontent.com/mysql/mysql-operator/trunk/deploy/deploy- operator.yaml • 3- Describe operator • $> kubectl get deployment mysql-operator --namespace mysql-operator
  • 14. Helm installation MySQL Operator for Kubernetes • https://dev.mysql.com/doc/mysql-operator/en/mysql-operator-installation-helm.html • $> helm repo add mysql-operator https://mysql.github.io/mysql-operator/ • $> helm repo update • $> helm install my-mysql-operator mysql-operator/mysql-operator --namespace mysql-operator --create- namespace
  • 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>