Recently, Kubernetes and containerized applications have been increasingly popular for their efficiency, scalability, and ease of deployment. Azure provides a fully managed Kubernetes service (Azure Kubernetes Service, or AKS) that helps you quickly and easily define, deploy, debug, and upgrade even the most complex containerized applications.
If you want to use a MySQL database in your Azure Kubernetes application, there are three options:
In this blog post, we’ll look more closely at the first option, discussing how you can deploy simple applications on AKS that integrate Azure Database for MySQL - Flexible Server on the backend in five simple and easy-to-follow steps!
Note: This blog post provides a brief summary of the process. For detailed tutorials with sample applications and commands, see the following articles:
First, create a MySQL flexible server with the desired configuration by using the Azure Portal, the Azure CLI, an ARM template, or other Azure tools.
Along with choosing the right Compute, storage, backup, and high availability options, it’s important to decide the suitable networking option while creating the MySQL flexible server. Based on how you’d like AKS to reach the MySQL flexible server, you can choose either of the following options:
Unless your scenario involves only small projects or demos, it’s highly recommended to create your server with private access, which will help secure access to your server via VNet Integration.
You can quickly create a flexible server in a VNet using the Azure CLI by running the following command:
az mysql flexible-server create \
--name <server-name> \
--resource-group <resource-group-name> \
--location <azure-region> \
--admin-user <your-admin-username> \
--admin-password <your-admin-password> \
--vnet <vnet-name> \
--subnet <mysql-subnet-name>
The subnet specified will be delegated for use only with your MySQL flexible server. Be sure that the subnet doesn’t include any other resources.
Note: If you prefer to use public access networking instead, be sure that you’ve created firewall rules to allow either all Azure services or specific services, such as the AKS cluster.
You can also create databases for your application by using the CLI command: az mysql flexible-server db create
Update your application code with the following changes:
For reference on how to prepare your application code for AKS and MySQL Flexible Server, see “Code the application” sections in these tutorials: Java SpringBoot | WordPress .
You can either build and deploy the docker image to Docker hub or use Azure Container Registry, a private container registry that allows you to securely build and deploy your applications and custom code.
To quickly create an Azure container registry, use the az acr create command, as shown below:
az acr create --resource-group <resource-group-name> \
--location <azure-region> \
--name <registryname> \
--sku <Basic/Classic/Premium/Standard>
Now, build the application image and push it to this registry using Docker CLI (docker build, docker tag, and docker push), ACR tasks, or developer tools such as the Maven Jib plugin for containerized Java applications.
Next, create an AKS cluster in the VNet and attach the Azure container registry account to the cluster.
Before you create an AKS cluster, you first need to create a subnet for the cluster within the same VNet as the MySQL flexible server. The next thing to consider is whether to use kubenet networking or Azure CNI networking for the cluster. Based on your application and infrastructure requirements, this comparison chart can help you decide.
If you’re using Azure CNI, create the AKS cluster using the az aks create command, as shown below:
az aks create \
--resource-group <resource-group-name> \
--name <AKS-cluster-name> \
--network-plugin azure \
--service-cidr 10.0.0.0/16 \
--dns-service-ip 10.0.0.10 \
--docker-bridge-address 172.17.0.1/16 \
--vnet-subnet-id <AKS-subnet-ID> \
--attach-acr <registryname> \
--dns-name-prefix <AKS-DNS-prefix> \
--generate-ssh-keys
To deploy the application to the AKS cluster, you first need to create a Kubernetes manifest file that defines a desired state for the cluster, such as what container images to run.
Key things to define in the Kubernetes manifest YAML file include:
After the YAML file is ready, deploy it with kubectl apply or with the Kubernetes resource view via the Azure portal.
You should now be able to launch the application by opening a web browser and navigating to the Kubernetes service’s external IP.
We hope this five-step guide simplifies the deployment process and helps you quickly get started with building your applications on AKS and Azure Database for MySQL – Flexible Server.
If you’re a new developer or Azure user seeking a quick, affordable way to develop/deploy apps on Azure, create an Azure free account today. With an Azure free account, you can now try Azure Database for MySQL - Flexible Server for free for 12 months!
If you have any questions, feedback, or suggestions on what else you’d like us to write about, please leave a comment below or email us at AskAzureDBforMySQL@service.microsoft.com. Thank you!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.