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.
The basic set up for running ProxySQL as a service in AKS using Azure Database for MySQL is shown in Figure 1.
Setting up ProxySQL as a service in AKS using Azure Database for MySQL involves the following tasks:
To deploy ProxySQL as a service, refer to deploy ProxySQL as a service on Kubernetes using Azure Database for MySQL.
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
Next, deploy WordPress on AKS.
az aks get-credentials --name aks-cluster-name --resource-group "mydemo"
kubectl create -f .\wordpress.yml
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
Program Manager - Microsoft
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.