SlideShare a Scribd company logo
1 of 17
Download to read offline
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

Cloud-native applications with Java and Kubernetes - Yehor Volkov
 Cloud-native applications with Java and Kubernetes - Yehor Volkov Cloud-native applications with Java and Kubernetes - Yehor Volkov
Cloud-native applications with Java and Kubernetes - Yehor VolkovKuberton
 
Build containerized application using Docker and Azure.pdf
Build containerized application using Docker and Azure.pdfBuild containerized application using Docker and Azure.pdf
Build containerized application using Docker and Azure.pdfHamida Rebai Trabelsi
 
Cloud-native .NET-Microservices mit Kubernetes @BASTAcon
Cloud-native .NET-Microservices mit Kubernetes @BASTAconCloud-native .NET-Microservices mit Kubernetes @BASTAcon
Cloud-native .NET-Microservices mit Kubernetes @BASTAconMario-Leander Reimer
 
Docker kubernetes fundamental(pod_service)_190307
Docker kubernetes fundamental(pod_service)_190307Docker kubernetes fundamental(pod_service)_190307
Docker kubernetes fundamental(pod_service)_190307Inhye Park
 
DevOps Workflow: A Tutorial on Linux Containers
DevOps Workflow: A Tutorial on Linux ContainersDevOps Workflow: A Tutorial on Linux Containers
DevOps Workflow: A Tutorial on Linux Containersinside-BigData.com
 
Continuous Deployment with Kubernetes, Docker and GitLab CI
Continuous Deployment with Kubernetes, Docker and GitLab CIContinuous Deployment with Kubernetes, Docker and GitLab CI
Continuous Deployment with Kubernetes, Docker and GitLab CIalexanderkiel
 
Mihai Criveti - PyCon Ireland - Automate Everything
Mihai Criveti - PyCon Ireland - Automate EverythingMihai Criveti - PyCon Ireland - Automate Everything
Mihai Criveti - PyCon Ireland - Automate EverythingMihai Criveti
 
Pro2516 10 things about oracle and k8s.pptx-final
Pro2516   10 things about oracle and k8s.pptx-finalPro2516   10 things about oracle and k8s.pptx-final
Pro2516 10 things about oracle and k8s.pptx-finalMichel Schildmeijer
 
Revolutionizing WSO2 PaaS with Kubernetes & App Factory
Revolutionizing WSO2 PaaS with Kubernetes & App FactoryRevolutionizing WSO2 PaaS with Kubernetes & App Factory
Revolutionizing WSO2 PaaS with Kubernetes & App FactoryImesh Gunaratne
 
GitOps & the deployment branching models - DevOps D-day Marseille 2021
GitOps & the deployment branching models - DevOps D-day Marseille 2021GitOps & the deployment branching models - DevOps D-day Marseille 2021
GitOps & the deployment branching models - DevOps D-day Marseille 2021SoKube
 
Priming Your Teams For Microservice Deployment to the Cloud
Priming Your Teams For Microservice Deployment to the CloudPriming Your Teams For Microservice Deployment to the Cloud
Priming Your Teams For Microservice Deployment to the CloudMatt Callanan
 
Kubernetes workshop -_the_basics
Kubernetes workshop -_the_basicsKubernetes workshop -_the_basics
Kubernetes workshop -_the_basicsSjuul Janssen
 
使用 Prometheus 監控 Kubernetes Cluster
使用 Prometheus 監控 Kubernetes Cluster 使用 Prometheus 監控 Kubernetes Cluster
使用 Prometheus 監控 Kubernetes Cluster inwin stack
 
WSO2Con USA 2015: Revolutionizing WSO2 PaaS with Kubernetes & App Factory
WSO2Con USA 2015: Revolutionizing WSO2 PaaS with Kubernetes & App FactoryWSO2Con USA 2015: Revolutionizing WSO2 PaaS with Kubernetes & App Factory
WSO2Con USA 2015: Revolutionizing WSO2 PaaS with Kubernetes & App FactoryWSO2
 
Build Your Own CaaS (Container as a Service)
Build Your Own CaaS (Container as a Service)Build Your Own CaaS (Container as a Service)
Build Your Own CaaS (Container as a Service)HungWei Chiu
 
04_Azure Kubernetes Service: Basic Practices for Developers_GAB2019
04_Azure Kubernetes Service: Basic Practices for Developers_GAB201904_Azure Kubernetes Service: Basic Practices for Developers_GAB2019
04_Azure Kubernetes Service: Basic Practices for Developers_GAB2019Kumton Suttiraksiri
 
Getting Started with MariaDB with Docker
Getting Started with MariaDB with DockerGetting Started with MariaDB with Docker
Getting Started with MariaDB with DockerMariaDB plc
 
Amazon Web Services and Docker: from developing to production
Amazon Web Services and Docker: from developing to productionAmazon Web Services and Docker: from developing to production
Amazon Web Services and Docker: from developing to productionPaolo latella
 

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

Cloud-native applications with Java and Kubernetes - Yehor Volkov
 Cloud-native applications with Java and Kubernetes - Yehor Volkov Cloud-native applications with Java and Kubernetes - Yehor Volkov
Cloud-native applications with Java and Kubernetes - Yehor Volkov
 
Build containerized application using Docker and Azure.pdf
Build containerized application using Docker and Azure.pdfBuild containerized application using Docker and Azure.pdf
Build containerized application using Docker and Azure.pdf
 
Cloud-native .NET-Microservices mit Kubernetes @BASTAcon
Cloud-native .NET-Microservices mit Kubernetes @BASTAconCloud-native .NET-Microservices mit Kubernetes @BASTAcon
Cloud-native .NET-Microservices mit Kubernetes @BASTAcon
 
Kubernetes @ meetic
Kubernetes @ meeticKubernetes @ meetic
Kubernetes @ meetic
 
Docker kubernetes fundamental(pod_service)_190307
Docker kubernetes fundamental(pod_service)_190307Docker kubernetes fundamental(pod_service)_190307
Docker kubernetes fundamental(pod_service)_190307
 
DevOps Workflow: A Tutorial on Linux Containers
DevOps Workflow: A Tutorial on Linux ContainersDevOps Workflow: A Tutorial on Linux Containers
DevOps Workflow: A Tutorial on Linux Containers
 
Microservices in Java
Microservices in JavaMicroservices in Java
Microservices in Java
 
Continuous Deployment with Kubernetes, Docker and GitLab CI
Continuous Deployment with Kubernetes, Docker and GitLab CIContinuous Deployment with Kubernetes, Docker and GitLab CI
Continuous Deployment with Kubernetes, Docker and GitLab CI
 
Mihai Criveti - PyCon Ireland - Automate Everything
Mihai Criveti - PyCon Ireland - Automate EverythingMihai Criveti - PyCon Ireland - Automate Everything
Mihai Criveti - PyCon Ireland - Automate Everything
 
Pro2516 10 things about oracle and k8s.pptx-final
Pro2516   10 things about oracle and k8s.pptx-finalPro2516   10 things about oracle and k8s.pptx-final
Pro2516 10 things about oracle and k8s.pptx-final
 
Revolutionizing WSO2 PaaS with Kubernetes & App Factory
Revolutionizing WSO2 PaaS with Kubernetes & App FactoryRevolutionizing WSO2 PaaS with Kubernetes & App Factory
Revolutionizing WSO2 PaaS with Kubernetes & App Factory
 
GitOps & the deployment branching models - DevOps D-day Marseille 2021
GitOps & the deployment branching models - DevOps D-day Marseille 2021GitOps & the deployment branching models - DevOps D-day Marseille 2021
GitOps & the deployment branching models - DevOps D-day Marseille 2021
 
Priming Your Teams For Microservice Deployment to the Cloud
Priming Your Teams For Microservice Deployment to the CloudPriming Your Teams For Microservice Deployment to the Cloud
Priming Your Teams For Microservice Deployment to the Cloud
 
Kubernetes workshop -_the_basics
Kubernetes workshop -_the_basicsKubernetes workshop -_the_basics
Kubernetes workshop -_the_basics
 
使用 Prometheus 監控 Kubernetes Cluster
使用 Prometheus 監控 Kubernetes Cluster 使用 Prometheus 監控 Kubernetes Cluster
使用 Prometheus 監控 Kubernetes Cluster
 
WSO2Con USA 2015: Revolutionizing WSO2 PaaS with Kubernetes & App Factory
WSO2Con USA 2015: Revolutionizing WSO2 PaaS with Kubernetes & App FactoryWSO2Con USA 2015: Revolutionizing WSO2 PaaS with Kubernetes & App Factory
WSO2Con USA 2015: Revolutionizing WSO2 PaaS with Kubernetes & App Factory
 
Build Your Own CaaS (Container as a Service)
Build Your Own CaaS (Container as a Service)Build Your Own CaaS (Container as a Service)
Build Your Own CaaS (Container as a Service)
 
04_Azure Kubernetes Service: Basic Practices for Developers_GAB2019
04_Azure Kubernetes Service: Basic Practices for Developers_GAB201904_Azure Kubernetes Service: Basic Practices for Developers_GAB2019
04_Azure Kubernetes Service: Basic Practices for Developers_GAB2019
 
Getting Started with MariaDB with Docker
Getting Started with MariaDB with DockerGetting Started with MariaDB with Docker
Getting Started with MariaDB with Docker
 
Amazon Web Services and Docker: from developing to production
Amazon Web Services and Docker: from developing to productionAmazon Web Services and Docker: from developing to production
Amazon Web Services and Docker: from developing to production
 

More from Ivan Ma

20201106 hk-py con-mysql-shell
20201106 hk-py con-mysql-shell20201106 hk-py con-mysql-shell
20201106 hk-py con-mysql-shellIvan Ma
 
20200613 my sql-ha-deployment
20200613 my sql-ha-deployment20200613 my sql-ha-deployment
20200613 my sql-ha-deploymentIvan Ma
 
20191001 bkk-secret-of inno-db_clusterv1
20191001 bkk-secret-of inno-db_clusterv120191001 bkk-secret-of inno-db_clusterv1
20191001 bkk-secret-of inno-db_clusterv1Ivan Ma
 
20190817 coscup-oracle my sql innodb cluster sharing
20190817 coscup-oracle my sql innodb cluster sharing20190817 coscup-oracle my sql innodb cluster sharing
20190817 coscup-oracle my sql innodb cluster sharingIvan Ma
 
20190615 hkos-mysql-troubleshootingandperformancev2
20190615 hkos-mysql-troubleshootingandperformancev220190615 hkos-mysql-troubleshootingandperformancev2
20190615 hkos-mysql-troubleshootingandperformancev2Ivan Ma
 
20180420 hk-the powerofmysql8
20180420 hk-the powerofmysql820180420 hk-the powerofmysql8
20180420 hk-the powerofmysql8Ivan Ma
 
20171104 hk-py con-mysql-documentstore_v1
20171104 hk-py con-mysql-documentstore_v120171104 hk-py con-mysql-documentstore_v1
20171104 hk-py con-mysql-documentstore_v1Ivan Ma
 
MySQL InnoDB Cluster and MySQL Group Replication @HKOSC 2017
MySQL InnoDB Cluster and MySQL Group Replication @HKOSC 2017MySQL InnoDB Cluster and MySQL Group Replication @HKOSC 2017
MySQL InnoDB Cluster and MySQL Group Replication @HKOSC 2017Ivan Ma
 
What's New in MySQL 8.0 @ HKOSC 2017
What's New in MySQL 8.0 @ HKOSC 2017What's New in MySQL 8.0 @ HKOSC 2017
What's New in MySQL 8.0 @ HKOSC 2017Ivan Ma
 
20161029 py con-mysq-lv3
20161029 py con-mysq-lv320161029 py con-mysq-lv3
20161029 py con-mysq-lv3Ivan Ma
 
20160821 coscup-my sql57docstorelab01
20160821 coscup-my sql57docstorelab0120160821 coscup-my sql57docstorelab01
20160821 coscup-my sql57docstorelab01Ivan Ma
 
Hkosc group replication-lecture_lab07
Hkosc group replication-lecture_lab07Hkosc group replication-lecture_lab07
Hkosc group replication-lecture_lab07Ivan Ma
 
20151010 my sq-landjavav2a
20151010 my sq-landjavav2a20151010 my sq-landjavav2a
20151010 my sq-landjavav2aIvan Ma
 
01 demystifying mysq-lfororacledbaanddeveloperv1
01 demystifying mysq-lfororacledbaanddeveloperv101 demystifying mysq-lfororacledbaanddeveloperv1
01 demystifying mysq-lfororacledbaanddeveloperv1Ivan Ma
 
Exploring mysql cluster 7.4
Exploring mysql cluster 7.4Exploring mysql cluster 7.4
Exploring mysql cluster 7.4Ivan Ma
 
20150110 my sql-performanceschema
20150110 my sql-performanceschema20150110 my sql-performanceschema
20150110 my sql-performanceschemaIvan Ma
 
20141011 my sql clusterv01pptx
20141011 my sql clusterv01pptx20141011 my sql clusterv01pptx
20141011 my sql clusterv01pptxIvan Ma
 

More from Ivan Ma (17)

20201106 hk-py con-mysql-shell
20201106 hk-py con-mysql-shell20201106 hk-py con-mysql-shell
20201106 hk-py con-mysql-shell
 
20200613 my sql-ha-deployment
20200613 my sql-ha-deployment20200613 my sql-ha-deployment
20200613 my sql-ha-deployment
 
20191001 bkk-secret-of inno-db_clusterv1
20191001 bkk-secret-of inno-db_clusterv120191001 bkk-secret-of inno-db_clusterv1
20191001 bkk-secret-of inno-db_clusterv1
 
20190817 coscup-oracle my sql innodb cluster sharing
20190817 coscup-oracle my sql innodb cluster sharing20190817 coscup-oracle my sql innodb cluster sharing
20190817 coscup-oracle my sql innodb cluster sharing
 
20190615 hkos-mysql-troubleshootingandperformancev2
20190615 hkos-mysql-troubleshootingandperformancev220190615 hkos-mysql-troubleshootingandperformancev2
20190615 hkos-mysql-troubleshootingandperformancev2
 
20180420 hk-the powerofmysql8
20180420 hk-the powerofmysql820180420 hk-the powerofmysql8
20180420 hk-the powerofmysql8
 
20171104 hk-py con-mysql-documentstore_v1
20171104 hk-py con-mysql-documentstore_v120171104 hk-py con-mysql-documentstore_v1
20171104 hk-py con-mysql-documentstore_v1
 
MySQL InnoDB Cluster and MySQL Group Replication @HKOSC 2017
MySQL InnoDB Cluster and MySQL Group Replication @HKOSC 2017MySQL InnoDB Cluster and MySQL Group Replication @HKOSC 2017
MySQL InnoDB Cluster and MySQL Group Replication @HKOSC 2017
 
What's New in MySQL 8.0 @ HKOSC 2017
What's New in MySQL 8.0 @ HKOSC 2017What's New in MySQL 8.0 @ HKOSC 2017
What's New in MySQL 8.0 @ HKOSC 2017
 
20161029 py con-mysq-lv3
20161029 py con-mysq-lv320161029 py con-mysq-lv3
20161029 py con-mysq-lv3
 
20160821 coscup-my sql57docstorelab01
20160821 coscup-my sql57docstorelab0120160821 coscup-my sql57docstorelab01
20160821 coscup-my sql57docstorelab01
 
Hkosc group replication-lecture_lab07
Hkosc group replication-lecture_lab07Hkosc group replication-lecture_lab07
Hkosc group replication-lecture_lab07
 
20151010 my sq-landjavav2a
20151010 my sq-landjavav2a20151010 my sq-landjavav2a
20151010 my sq-landjavav2a
 
01 demystifying mysq-lfororacledbaanddeveloperv1
01 demystifying mysq-lfororacledbaanddeveloperv101 demystifying mysq-lfororacledbaanddeveloperv1
01 demystifying mysq-lfororacledbaanddeveloperv1
 
Exploring mysql cluster 7.4
Exploring mysql cluster 7.4Exploring mysql cluster 7.4
Exploring mysql cluster 7.4
 
20150110 my sql-performanceschema
20150110 my sql-performanceschema20150110 my sql-performanceschema
20150110 my sql-performanceschema
 
20141011 my sql clusterv01pptx
20141011 my sql clusterv01pptx20141011 my sql clusterv01pptx
20141011 my sql clusterv01pptx
 

Recently uploaded

Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 

Recently uploaded (20)

Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
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/
  • 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>