Home
%3CLINGO-SUB%20id%3D%22lingo-sub-1105847%22%20slang%3D%22en-US%22%3EScaling%20an%20Azure%20Database%20for%20MySQL%20workload%20running%20on%20Kubernetes%20with%20read%20replicas%20and%20ProxySQL%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1105847%22%20slang%3D%22en-US%22%3E%3CH2%20id%3D%22toc-hId--1416309462%22%20id%3D%22toc-hId--1416309462%22%20id%3D%22toc-hId--1416309462%22%3E%3CSPAN%3EIntroduction%3C%2FSPAN%3E%3C%2FH2%3E%0A%3CP%3EImagine%20that%20you%20are%20designing%20and%20developing%20a%20cloud-native%20application%20on%20Kubernetes%20to%20allow%20your%20application%20to%20scale%20seamlessly%20as%20and%20when%20needed.%20You%20decide%20to%20host%20your%20MySQL%20database%20for%20the%20application%20on%20Azure%20Database%20for%20MySQL%2C%20which%20is%20a%20fully%20managed%20service%20that%20ensures%20your%20backups%20and%20addresses%20availability%20and%20security.With%20Kubernetes%2C%20you%20can%20easily%20scale%20out%20the%20application%20layer%20by%20simply%20adding%20nodes%20to%20the%20Kubernetes%20Cluster%20or%20by%20scaling%20individual%20application%20pods%2C%20which%20are%20stateless%20in%20nature.%20However%2C%20when%20scaling%20up%20a%20MySQL%20database%2C%20you%20may%20be%20constrained%20by%20the%20maximum%20limits%20supported%20by%20a%20single%20node%20of%20Azure%20Database%20for%20MySQL.%20In%20this%20scenario%2C%20MySQL%20replication%20with%20ProxySQL%20load%20balancer%20proxy%20can%20provide%20a%20more%20scalable%20design%20from%20database%20perspective.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%20can%20easily%20scale%20out%20Azure%20Database%20for%20MySQL%20using%20%3CA%20href%3D%22https%3A%2F%2Fnam06.safelinks.protection.outlook.com%2F%3Furl%3Dhttps%253A%252F%252Fdocs.microsoft.com%252Fen-us%252Fazure%252Fmysql%252Fconcepts-read-replicas%26amp%3Bdata%3D02%257C01%257CAmol.Bhatnagar%2540microsoft.com%257Ce934e0a67a934055ddac08d79595aa09%257C72f988bf86f141af91ab2d7cd011db47%257C1%257C0%257C637142342343146764%26amp%3Bsdata%3DKwbOd%252F0NUbheXg25XwRhD6oweGdIMXBUXq3K4EiCX9c%253D%26amp%3Breserved%3D0%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Eread%20replicas%3C%2FA%3E%2C%20and%20even%20further%20using%20a%20load%20balancer%20proxy%20to%20decouple%20and%20abstract%20your%20application%20from%20the%20complexity%20of%20database%20replication.%20In%20the%20distributed%20application%2C%20it%E2%80%99s%20quite%20common%20to%20use%20load%20balancers%20so%20that%20your%20application%20is%20not%20dependent%20on%20database%20topologies%2C%20to%20easily%20load%20balance%20the%20workload%2C%20and%20to%20do%20connection%20failover.%20%3CA%20href%3D%22https%3A%2F%2Fnam06.safelinks.protection.outlook.com%2F%3Furl%3Dhttps%253A%252F%252Fwww.proxysql.com%252F%26amp%3Bdata%3D02%257C01%257CAmol.Bhatnagar%2540microsoft.com%257Ce934e0a67a934055ddac08d79595aa09%257C72f988bf86f141af91ab2d7cd011db47%257C1%257C0%257C637142342343146764%26amp%3Bsdata%3D9tfKrRpyP3cWV8fuVlGKkMkVe5O5LRCAuCz34gQ6TqI%253D%26amp%3Breserved%3D0%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3EProxySQL%3C%2FA%3E%2C%20a%20high-performance%20MySQL%20proxy%2C%20enables%20users%20to%20send%20different%20queries%20to%20multiple%20servers%20to%20distribute%20the%20load%20more%20efficiently.%20ProxySQL%20has%20several%20benefits%2C%20including%20intelligent%20load%20balancing%20across%20different%20databases%20and%20the%20ability%20to%20determine%20if%20a%20database%20instance%20is%20running%20so%20that%20read%20traffic%20can%20be%20redirected%20accordingly.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20this%20blog%20post%2C%20we%20use%20WordPress%20as%20one%20of%20the%20canonical%20sample%20applications%20for%20MySQL.%20This%20application%20needs%20to%20be%20modernized%20to%20a%20scalable%20cloud%20native%20design%20architecture%20to%20cater%20to%20millions%20of%20mobile%20and%20internet%20device%20users.%20The%20following%20section%20describes%20how%20to%20scale%20your%20WordPress%20application%20using%20ProxySQL%20deployed%20as%20service%20in%20Azure%20Kubernetes%20Service%20(AKS)%20to%20perform%20transparent%20read%2Fwrite%20split%20across%20Azure%20Database%20for%20MySQL%20replicas.%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EImportant%3C%2FSTRONG%3E%3A%20Azure%20Database%20for%20MySQL%20supports%20ProxySQL%20version%202.0.6%20and%20later.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-1071203371%22%20id%3D%22toc-hId-1071203371%22%20id%3D%22toc-hId-1071203371%22%3E%3CSPAN%3EProxySQL%20as%20a%20service%20in%20AKS%20using%20Azure%20Database%20for%20MySQL%20setup%3C%2FSPAN%3E%3C%2FH2%3E%0A%3CP%3EThe%20basic%20set%20up%20for%20running%20ProxySQL%20as%20a%20service%20in%20AKS%20using%20Azure%20Database%20for%20MySQL%20is%20shown%20in%20Figure%201.%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--736251092%22%20id%3D%22toc-hId--736251092%22%20id%3D%22toc-hId--736251092%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F165078i4EF7D12D05832CC8%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22Capture3.PNG%22%20title%3D%22Capture3.PNG%22%20%2F%3E%3C%2FSPAN%3E%3CSPAN%20style%3D%22color%3A%20inherit%3B%20font-size%3A%2030px%3B%22%3EProcedure%3C%2FSPAN%3E%3C%2FH2%3E%0A%3CP%3ESetting%20up%20ProxySQL%20as%20a%20service%20in%20AKS%20using%20Azure%20Database%20for%20MySQL%20involves%20the%20following%20tasks%3A%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3EDeploy%20ProxySQL%20as%20a%20service.%3C%2FLI%3E%0A%3CLI%3EPrepare%20the%20WordPress%20deployment.%3C%2FLI%3E%0A%3CLI%3EDeploy%20WordPress.%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CH2%20id%3D%22toc-hId-1751261741%22%20id%3D%22toc-hId-1751261741%22%20id%3D%22toc-hId-1751261741%22%3E%3CSPAN%3EDeploy%20ProxySQL%20as%20a%20service%3C%2FSPAN%3E%3C%2FH2%3E%0A%3CP%3ETo%20deploy%20ProxySQL%20as%20a%20service%2C%20refer%20to%26nbsp%3B%3CA%20title%3D%22deploy%20ProxySQL%20as%20a%20service%20on%20Kubernetes%20using%20Azure%20Database%20for%20MySQL.%22%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fazure-database-for-mysql%2Fdeploy-proxysql-as-a-service-on-kubernetes-using-azure-database%2Fba-p%2F1105959%22%20target%3D%22_self%22%3Edeploy%20ProxySQL%20as%20a%20service%20on%20Kubernetes%20using%20Azure%20Database%20for%20MySQL.%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--56192722%22%20id%3D%22toc-hId--56192722%22%20id%3D%22toc-hId--56192722%22%3E%3CSPAN%3EPrepare%20the%20WordPress%20deployment%3C%2FSPAN%3E%3C%2FH2%3E%0A%3CP%3EYou%20can%20use%20the%20sample%20WordPress%20deployment%20file%20below.%20Update%20the%20WordPress%20config%20details%20in%20the%20WordPress%20environment%20variables%20and%20the%20ProxySQL%20service%20details%20from%20the%20ProxySQL%20deployment%20you%20just%20performed.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3EapiVersion%3A%20apps%2Fv1%0Akind%3A%20Deployment%0Ametadata%3A%0A%20%20name%3A%20wordpress%0A%20%20labels%3A%0A%20%20%20%20app%3A%20wordpress%0Aspec%3A%0A%20%20replicas%3A%201%0A%20%20selector%3A%0A%20%20%20%20matchLabels%3A%0A%20%20%20%20%20%20app%3A%20wordpress%0A%20%20%20%20%20%20tier%3A%20frontend%0A%20%20strategy%3A%0A%20%20%20%20type%3A%20RollingUpdate%0A%20%20template%3A%0A%20%20%20%20metadata%3A%0A%20%20%20%20%20%20labels%3A%0A%20%20%20%20%20%20%20%20app%3A%20wordpress%0A%20%20%20%20%20%20%20%20tier%3A%20frontend%0A%20%20%20%20spec%3A%0A%20%20%20%20%20%20restartPolicy%3A%20Always%0A%20%20%20%20%20%20containers%3A%0A%20%20%20%20%20%20-%20image%3A%20wordpress%3Alatest%0A%20%20%20%20%20%20%20%20name%3A%20wordpress%0A%20%20%20%20%20%20%20%20env%3A%0A%20%20%20%20%20%20%20%20-%20name%3A%20WORDPRESS_DB_HOST%0A%20%20%20%20%20%20%20%20%20%20value%3A%20proxysql%0A%20%20%20%20%20%20%20%20-%20name%3A%20WORDPRESS_DB_USER%0A%20%20%20%20%20%20%20%20%20%20value%3A%20mydemouser%0A%20%20%20%20%20%20%20%20-%20name%3A%20WORDPRESS_DB_DATABASE%0A%20%20%20%20%20%20%20%20%20%20value%3A%20wordpress%0A%20%20%20%20%20%20%20%20-%20name%3A%20WORDPRESS_DB_PASSWORD%0A%20%20%20%20%20%20%20%20%20%20value%3A%20%22secretpassword%22%0A%20%20%20%20%20%20%20%20ports%3A%0A%20%20%20%20%20%20%20%20-%20containerPort%3A%2080%0A%20%20%20%20%20%20%20%20%20%20name%3A%20wordpress%0A---%0AapiVersion%3A%20v1%0Akind%3A%20Service%0Ametadata%3A%0A%20%20name%3A%20wordpress%0A%20%20labels%3A%0A%20%20%20%20app%3A%20wordpress%0A%20%20%20%20tier%3A%20frontend%0Aspec%3A%0A%20%20type%3A%20LoadBalancer%0A%20%20ports%3A%0A%20%20-%20name%3A%20wordpress%0A%20%20%20%20nodePort%3A%2030088%0A%20%20%20%20port%3A%2080%0A%20%20selector%3A%0A%20%20%20%20app%3A%20wordpress%0A%20%20%20%20tier%3A%20frontend%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--1863647185%22%20id%3D%22toc-hId--1863647185%22%20id%3D%22toc-hId--1863647185%22%3E%3CSPAN%3EDeploy%20the%20resources%3C%2FSPAN%3E%3C%2FH2%3E%0A%3CP%3ENext%2C%20deploy%20WordPress%20on%20AKS.%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3EConfigure%20kubectl%20to%20use%20the%20credential%20for%20the%20AKS%20cluster%20created%20as%20part%20of%20deploying%20ProxySQL%20as%20a%20service.%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3Eaz%20aks%20get-credentials%20--name%20aks-cluster-name%20--resource-group%20%22mydemo%22%E2%80%8B%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLI%3E%0A%3CLI%3EDeploy%20WordPress%20using%20the%20wordpress%20deployment%20file.%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3Ekubectl%20create%20-f%20.%5Cwordpress.yml%E2%80%8B%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLI%3E%0A%3CLI%3EAfter%20the%20deployment%20finishes%2C%20can%20go%20to%20WordPress%20site%20by%20visiting%20the%20external%20IP.%20To%20get%20the%20external%20IPs%2C%20run%20the%20following%20command%3A%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3Ekubectl%20getpods%2Cservices%20-o%20wide%20%20%20%E2%80%8B%3C%2FCODE%3E%3C%2FPRE%3E%26nbsp%3B%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%3CSPAN%3ETo%20learn%20about%20how%20to%20load%20balance%20read%20replicas%20using%20ProxySQL%20in%20Azure%20Database%20for%20MySQL%2C%20see%20the%20below%20post%20%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fazure-database-for-mysql%2Fload-balance-read-replicas-using-proxysql-in-azure-database-for%2Fba-p%2F880042%22%20target%3D%22_blank%22%20rel%3D%22noopener%22%3Ehere%3C%2FA%3E%3CSPAN%3E.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EIf%20you%20have%20trouble%20setting%20up%20ProxySQL%20as%20a%20service%20in%20AKS%20using%20Azure%20Database%20for%20MySQL%2C%20please%20contact%20the%20Azure%20Database%20for%20MySQL%20team%20at%20%3C%2FSPAN%3E%3CA%20href%3D%22mailto%3AAskAzureDBforMySQL%40service.microsoft.com%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3EAskAzureDBforMySQL%40service.microsoft.com%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EThank%20you!%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EAmol%20Bhatnagar%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EProgram%20Manager%20-%20Microsoft%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-1105847%22%20slang%3D%22en-US%22%3E%3CP%3EThis%20blog%20post%20shows%26nbsp%3Bhow%20to%20scale%20your%20WordPress%20application%20using%20ProxySQL%20deployed%20as%20service%20in%20Azure%20Kubernetes%20Service%20(AKS)%20to%20perform%20transparent%20read%2Fwrite%20split%20across%20Azure%20Database%20for%20MySQL%20replicas%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1105847%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EScaling%20an%20Azure%20Database%20for%20MySQL%20workload%20running%20on%20Kubernetes%20with%20read%20replicas%20and%20ProxySQL%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1110797%22%20slang%3D%22en-US%22%3ERe%3A%20Scaling%20an%20Azure%20Database%20for%20MySQL%20workload%20running%20on%20Kubernetes%20with%20read%20replicas%20and%20ProxyS%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1110797%22%20slang%3D%22en-US%22%3E%3CP%3EProxySQL%20is%20great%20for%20MySQL.%20Another%20vendor-neutral%20proxy%20on%20Azure%20is%20Heimdall%20Data.%20It%20supports%20query%20caching%20and%20read%2Fwrite%20split%20with%20replication%20lag%20detection%3A%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fazure-database-for-postgresql%2Fusing-the-heimdall-proxy-to-split-reads-and-writes-for-azure%2Fba-p%2F1058854%22%20target%3D%22_blank%22%3Ehttps%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fazure-database-for-postgresql%2Fusing-the-heimdall-proxy-to-split-reads-and-writes-for-azure%2Fba-p%2F1058854%3C%2FA%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
Microsoft

Introduction

Imagine that you are designing and developing a cloud-native application on Kubernetes to allow your application to scale seamlessly as and when needed. You decide to host your MySQL database for the application on Azure Database for MySQL, which is a fully managed service that ensures your backups and addresses availability and security.With Kubernetes, you can easily scale out the application layer by simply adding nodes to the Kubernetes Cluster or by scaling individual application pods, which are stateless in nature. However, when scaling up a MySQL database, you may be constrained by the maximum limits supported by a single node of Azure Database for MySQL. In this scenario, MySQL replication with ProxySQL load balancer proxy can provide a more scalable design from database perspective.

 

You can easily scale out Azure Database for MySQL using read replicas, and even further using a load balancer proxy to decouple and abstract your application from the complexity of database replication. In the distributed application, it’s quite common to use load balancers so that your application is not dependent on database topologies, to easily load balance the workload, and to do connection failover. ProxySQL, a high-performance MySQL proxy, enables users to send different queries to multiple servers to distribute the load more efficiently. ProxySQL has several benefits, including intelligent load balancing across different databases and the ability to determine if a database instance is running so that read traffic can be redirected accordingly.

 

In this blog post, we use WordPress as one of the canonical sample applications for MySQL. This application needs to be modernized to a scalable cloud native design architecture to cater to millions of mobile and internet device users. The following section describes how to scale your WordPress application using ProxySQL deployed as service in Azure Kubernetes Service (AKS) to perform transparent read/write split across Azure Database for MySQL replicas.

Important: Azure Database for MySQL supports ProxySQL version 2.0.6 and later.

 

ProxySQL as a service in AKS using Azure Database for MySQL setup

The basic set up for running ProxySQL as a service in AKS using Azure Database for MySQL is shown in Figure 1.

Capture3.PNGProcedure

Setting up ProxySQL as a service in AKS using Azure Database for MySQL involves the following tasks:

  1. Deploy ProxySQL as a service.
  2. Prepare the WordPress deployment.
  3. Deploy WordPress.

Deploy ProxySQL as a service

To deploy ProxySQL as a service, refer to deploy ProxySQL as a service on Kubernetes using Azure Database for MySQL.

 

Prepare the WordPress deployment

You can use the sample WordPress deployment file below. Update the WordPress config details in the WordPress environment variables and the ProxySQL service details from the ProxySQL deployment you just performed.

 

 

 

apiVersion: apps/v1
kind: Deployment
metadata:
  name: wordpress
  labels:
    app: wordpress
spec:
  replicas: 1
  selector:
    matchLabels:
      app: wordpress
      tier: frontend
  strategy:
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: wordpress
        tier: frontend
    spec:
      restartPolicy: Always
      containers:
      - image: wordpress:latest
        name: wordpress
        env:
        - name: WORDPRESS_DB_HOST
          value: proxysql
        - name: WORDPRESS_DB_USER
          value: mydemouser
        - name: WORDPRESS_DB_DATABASE
          value: wordpress
        - name: WORDPRESS_DB_PASSWORD
          value: "secretpassword"
        ports:
        - containerPort: 80
          name: wordpress
---
apiVersion: v1
kind: Service
metadata:
  name: wordpress
  labels:
    app: wordpress
    tier: frontend
spec:
  type: LoadBalancer
  ports:
  - name: wordpress
    nodePort: 30088
    port: 80
  selector:
    app: wordpress
    tier: frontend

 

 

 

Deploy the resources

Next, deploy WordPress on AKS.

  1. Configure kubectl to use the credential for the AKS cluster created as part of deploying ProxySQL as a service.
    az aks get-credentials --name aks-cluster-name --resource-group "mydemo"​
  2. Deploy WordPress using the wordpress deployment file.
    kubectl create -f .\wordpress.yml​
  3. After the deployment finishes, can go to WordPress site by visiting the external IP. To get the external IPs, run the following command:
    kubectl getpods,services -o wide   ​
     

To learn about how to load balance read replicas using ProxySQL in Azure Database for MySQL, see the post here.

If you have trouble setting up ProxySQL as a service in AKS using Azure Database for MySQL, please contact the Azure Database for MySQL team at AskAzureDBforMySQL@service.microsoft.com

Thank you!

Amol Bhatnagar

Program Manager - Microsoft

1 Comment
Senior Member

ProxySQL is great for MySQL. Another vendor-neutral proxy on Azure is Heimdall Data. It supports query caching and read/write split with replication lag detection: https://techcommunity.microsoft.com/t5/azure-database-for-postgresql/using-the-heimdall-proxy-to-spl...