Select Page

Azure MySQL as a Service – What is it

Every time we wanted to deploy an application to Azure that needed to connect to a MySQL Database we had a small problem. The problem was that we either had to use a third party MySQL provider like ClearDB and pay extra fees for the service or option two, create and maintain our MySQL instance in a virtual machine. The problem with ClearDB was that performance was horrible even, prices were high, and the service was not neatly integrated into Azure. The problem with a Virtual Machine was that we had to install, configure, secure and maintain a MySQL instance. One instance of MySQL is almost OK to support, but if you need High-Availability with data replication and all the she-bang, then we would be dealing with a disaster waiting to happen. For example, configuring SQL Always-On is in some way simple to do because the mechanisms are already integrated into the product, but you don’t have that with MySQL Community Edition or MariaDB Community Edition. I tried once to configure HA on a MariaDB instance, and oh boy, there were some many problems I couldn’t wrap my head around.

Last year Microsoft announced the public preview of the MySQL and Postgre database as a service offering in Azure which provided us mainly with a SQL Database like experience. Well, recently Microsoft announced that the services as mentioned earlier are now Generally Available, so I took the time to write my experience with them from a management and performance standpoint.

What is Azure Database for MySQL?

The Azure Database for MySQL is a database offering based on MySQL Community Edition with built-in high availability, scalable, secure and point in time backups. From a management standpoint, we’re relieved of patching, security, HA, backup and so on; That duty is offloaded to Azure at no cost to you as a user. The best benefit that you get with the service is that you can dynamically scale it on demand.
Comparable to the Azure SQL Database offering, we have multiple tiers of performance with different price points depending on our needs. At this point we have the following tiers available:

Basic
This one should be only used in dev/test scenarios. This type of tier will not offer you predictable performance nor a high number of MySQL Connections
The number of Max Connections is 50 per core, and this tier will only allow you to have a maximum 2vcores and it runs on Standard storage (HDD)

General Purpose
This is the tier that should be used for production applications. The tier offers scalable and predictable I/Os. If we want to compare this to the Azure SQL Database offering, we can compare it to the Standard tier.
The number of Max Connections is dependant on the vCore count:
2 vCores – 300 Connections
4 vCores – 625 Connections
8 vCores – 1250 Connections
16 vCores – 2500 Connections
32 vCores – 5000 Connections

Memory Optimized
This is the highest tier available at the moment and the most expensive. This tier is great for high concurrency and fast transaction processing. As this tier is not cheap to start with, I suggest first testing if your application uses the added benefits of the tier.

The number of Max Connections is dependant on the vCore count:
2 vCores – 300 Connections
4 vCores – 625 Connections
8 vCores – 1250 Connections
16 vCores – 2500 Connections
32 vCores – 5000 Connections

*The Max Connection numbers presented above can change at any point so consult the Azure documentation before you size a database for an application

If your application is very chatty with the database server and you’re using too many connections you will receive the following error:
ERROR 1040 (08004): Too many connections

This is a standard MySQL error. If you’re hitting that wall, then your options are to either scale up the Database or modify your application so that it doesn’t initiate that many TCP connections.

Another limitation that you will hit if you’re porting a legacy application to this service is that the engine doesn’t support MyISAM databases. If you’re using MyISAM, then you will have to convert it to InnoDB. The reason as to why MyISAM is not supported in this scenarios is because it’s not scalable and cannot work in distributed environments.

Converting the database can be simple, or it can be hard. The simple way is just to run “ALTER TABLE table_name ENGINE=InnoDB;” but you don’t get that many free lunches in life.
So Microsoft is announcing that it will add to it’s DMA (Database Migration Assistant) the possibility of migrating your on-premises / IaaS MySQL/Postgre instances to Azure Database for MySQL.

As the “server admin,” you do not have any super admin or DBA role privileges which means that modifying specific settings is not permitted. This is intended so that you don’t cause any issues with the database server and cause a service disruption by mistake. You have the possibility of importing databases using mysqlimport and mysqldump on the database server.

What we should know before using the service

As any PaaS offering, we have to understand that we are provisioning a database server and deploying databases in a shared environment. So depending on the plan we will be using, we will be affected in some way by the other databases that will be sitting on the same servers as we are. With that in mind, we have to know the limits of each tier that’s available to us and test the application while applying load.

If you’re getting the “Too many connections” error, then you might have to scale-up the database or re-write some code. Another factor that will affect the performance of our application is that the database server is not in the same virtual network or on the same VM as the application, so you have to take into account the network latency factor. The latency will not be huge, but if your application is expecting super fast responses because it found the database in memory, then you will have a significant issue.

Another factor that will cause problems to your application is transient errors. These types of errors occur naturally in a cloud environment because the cloud provider is dealing with millions of servers and failure is something pretty frequent. So these transient failures usually occur when your database was moved to another server, and the load balancer that’s handling your requests didn’t switch, and you will get a timeout. That timeout is very short, but if your application doesn’t have a retry mechanism like a circuit breaker, then you will get an exception.

How do I start?

Creating an Azure Database for MySQL is pretty simple. You can do it from the Portal or from the CLI.

From the portal you will have to go to Create a resource -> Type in “Azure MySQL” -> Select Azure Database for MySQL -> press create.

After you press create, you will be presented with a new blade asking you to fill out some parameters. After you fill out all the parameters shown in the screenshot below, you can select the pricing and performance tier.

From the CLI, you have to run the following commands:

After you press create, you wait a few minutes for the server to be provisioned and after that, you ready to connect to it. What you need to know is that the firewall and SSL settings are enforced by default so you will have to add your IP to the whitelist so you can connect to it with MySQL Workbench, allow Azure services if you need an VM or App Service to connect to it and when you’re connecting your application, you will have to change the connection string to use encrypted connections otherwise you have to disable SSL.

You can dynamically scale the CPU / Storage based on your needs but you cannot change the pricing / performance tier after the server has been provisioned. Storage can only be increased and not lowered and you cannot change to LRS from GRS or vice versa for the Backup Redundancy Option.

Hope this was useful. Have a good one!

Integrating Azure Container Instances in AKS

In a previous blog post, I talked about how excellent the managed Kubernetes service is in Azure and in another blog post I spoke about Azure Container Instances. In this blog post, we will be combining them so that we get the best of both worlds.

We know that we can use ACI for some simple scenarios like task automation, CI/CD agents like VSTS agents (Windows or Linux), simple web servers and so on but it’s another thing that we need to manage. Even though that ACI has almost no strings attached, e.g. no VM management, custom resource sizing and fast startup, we still may want to control them from a single pane of glass.

ACI doesn’t provide you with auto-scaling, rolling upgrades, load balancing and affinity/anti-affinity, that’s the work of a container orchestrator. So if we want the best of both worlds, we need an ACI connector.

The ACI Connector is a virtual kubelet that get’s installed on your AKS cluster, and from there you can deploy containers just by merely referencing the node.

If you’re interested in the project, you can take a look here.

To install the ACI Connector, we need to cover some prerequisites.
The first thing that we need to do is to do is to create a service principal for the ACI connector. You can follow this document here on how to do it.

When you’ve created the SPN, grant it contributor rights on your AKS Resource Group and then continue with the setup.

I won’t be covering the Windows Subsystem for Linux or any other bash system as those have different prerequisites. What I will cover in this blog post is how to get started using the Azure Cloud Shell.

So pop open an Azure Cloud Shell and (assuming you already have an AKS cluster) get the credentials.

After that, you will need to install helm and upgrade tiller. For that, you will run the following.

The reason that you need to initialize helm and upgrade tiller is not very clear to me but I believe that helm and tiller should be installed and upgraded to the latest version every time.

Once those are installed, you’re ready to install the ACI connector as a virtual kubelet. Azure CLI installs the connector using a helm chart. Type in the command below using the SPN you created.

As you can see the in command from above, I typed both for the –os-type. ACI supports Windows and Linux containers so there’s no reason not to get both 🙂

After the install, you can query the Kubernetes cluster for the ACI Connector.

Now that the kubelet is installed, all you need to do is just to run kubectl -f create YAML file, and you’re done 🙂

If you want to target the ACI Connector with the YAML file, you need to reference a nodeName of virtual-kubelet-ACICONNECTORNAME-linux or windows.

You run that example from above and the AKS cluster will provision an ACI for you.

What you should know

The ACI connector allows the Kubernetes cluster to connect to Azure and provision Container Instances for you. That doesn’t mean that it will provision the containers in the same VNET as the K8 is so you can do some burst processing or those types of workloads. This is let’s say an alpha concept which is being built upon and new ways of using it are being presented every day. I have been asked by people, what’s the purpose of this thing because I cannot connect to it, but the fact is that you cannot expect that much from a preview product. I have given suggestions on how to improve it, and I suggest you should too.

Well that’s it for today. As always have a good one!

Azure Site Recovery – Protecting your Azure IaaS workloads

Having a disaster recovery plan is not something new. The thing that we need to be aware of is that outages and security breaches are becoming more and more common and they will not go away ever. The cloud brought the possibility of moving part of our datacenter workloads there and leverage the high availability of their solutions. By leveraging cloud solutions doesn’t exempt us from having DR plans and solutions in place for our business-critical application. Remember the Amazon S3 outage ? That caused a lot of problems for a lot of companies, and they were down until Amazon solved the problem.

The Amazon problem is just one issue with a bucket of the other problems. There we had a human error that caused the outage, but we have natural disasters like hurricanes that take out datacenter without any mercy. We have Harvey, Irma and Maria that hit the US pretty severely so even if cloud providers are pretty resilient to these types of natural disasters, we still have to protect our business-critical applications.

Traditional backup solutions run on servers, those servers require storage and depending on backup times and data retention the costs can go up tenfold. This is the main thing that happens on-premises. In the cloud, you would have the same type of solution, but this time you’re not buying physical servers instead you’re renting compute cycles from a provider. You still have to deal maintaining the system so that it works when such a problem happens. Azure has a service called Backup and Site Recovery that offers a “One-Click” backup and disaster recovery solution that doesn’t require any maintenance from you.

Protecting Azure VMs with ASR is very simple. You have to provision a Recovery Services Vault in the region you want to do DR and after that follow a couple of simple steps. The reason for creating the vault in a different area is that if you’re creating it in the same region where your VMs are, and the region goes down, you will have a problem and fortunately if you do it by mistake, you will get an error from Azure that you cannot do that.

Getting started

The first thing you have to do is to create a Recovery Services vault. To do that, you have to create a new resource, and in the marketplace, search filed you have to write “Backup and Site Recovery (OMS)”. After you click on it, you will be asked for a name, a region where it should be deployed and of course a Resource Group. The deployment is done in a matter of seconds, so you don’t have to wait too long for the solution to be ready.

Once you have the recovery vault up and running, you have to enable replication for your IaaS VMs. In your Vault, you go to Site Recovery and press on Replicate Application.

In the source environment, you have the option of protection on-premises environments or Azure environments. Take note that this service is still in preview so it might have issues 🙂

Select the source location and source resource group.

The next step is to select the Virtual Machines that should get replicated to the DR region.

Once you’re at the next screen, you can choose the target location for DR. You have the possibility of deploying in different regions than the vault is located so you don’t have a vault limitation in this case but remember that you will be paying for transfer costs, but if you’re in a DR case, I don’t think those costs matter that much. You can do edit some settings like the target Resource Group, Network, Storage and Availability sets and you can also modify the replication policy.

After you’re done configuring your settings, press on Create Target Resources, located in the Step 3 blade and wait for them to be created without closing the blade and once they are done you will be able to enable replication and you’re done 🙂

Replication takes a while depending on the number of VMs you’re protecting so this is the point where you start doing something else.

Once the replication is done, you can now setup recovery plans and do test failovers and complete failovers from a single pane of glass.

That it’s. Simple no? If you’re not doing DR for your IaaS environment then I would seriously ask you to take ASR into consideration and see what can give you.

Have a good one!

Post-Event ITCamp Community Meetup – 13.02.2018 – Cluj-Napoca

On the 13th of February, we hosted a Winter ITCamp Community event in Cluj-Napoca. At the event, we talked about containers, SOLID principles and Blockchain.

Winter ITCamp Community Event (Free)

Tuesday, Feb 13, 2018, 6:00 PM

The Office
Bulevardul 21 Decembrie 1989, nr. 77 Cluj-Napoca, RO

78 ITCamp-ers Went

• ITCamp Community îți propune ca pe data de 13 Februarie să se întâlnească cu specialiști din IT din Cluj-Napoca, oferind un eveniment gratuit. Evenimentul este organizat de comunitate pentru comunitate și susținut în totalitate de Yonder. • Agenda: 18:00-18:10 – Networking and coffee 18:10-19:00 – Container solutions in Azure (Florin Loghiade) 19…

Check out this Meetup →

A lot of people showed up that were interested in containers, microservices, blockchain and SOLID principles.

We had a lot of fun at the event and the people that joined had a lot of questions 🙂

The sessions:

Container solutions in Azure – Florin Loghiade
Abstract:

Container solutions in Azure: You’ve probably heard of containers by now, and I’m pretty sure that you’ve already used one or two in some development scenarios or even in production. As to why use containers it is pretty simple to answer. Instead of virtualizing the whole hardware stack as in the case of a virtual machine, you just virtualize the operating system which will run atop of the OS kernel. Translation: They are smaller and faster! That being said, containers need to run somewhere, and in this session, we will be talking about what container solutions are in the Azure Cloud and how we can use them.

SOLID for Everyone – Daniel Costea
Abstract:

Presentation will show what are and how you can use these principles in a practical way, using C# language, following a series of refactoring steps on an unoptimized sample of code.

Azure Blockchain Service – myth or reality (Radu Vunvulea)
Abstract:

This is a session dedicated to blockchain. We will talk about mining inside a cloud provider and why blockchain is so attractive to any company nowadays. In the second part of the session we will talk about a new service from Azure that is allowing us to use blockchain as a service (SaaS)

Event pictures:

Deploying your containers to Kubernetes using VSTS

Visual Studio Team Services or VSTS is Microsoft’s cloud offering that provides a complete set of tools and services that ease the life of small teams or enterprises when they are developing software.

I don’t want to get into a VSTS introduction in this blog post, but what we need to know about VSTS is that it’s the most integrated CI/CD system with Azure. The beautiful part is that Microsoft has a marketplace with lots of excellent add-ons that extend the functionally of VSTS.

Creating a CI/CD pipeline in VSTS to deploy containers to Kubernetes is quite easy. I will show in this blog post a straightforward pipeline design to build the container and deploy it to the AKS cluster.

The prerequisites for are the following:
VSTS Tenant and Project – Create for free here with a Microsoft Account that has access to the Azure subscription
VSTS Task installed – Replace Tokens Task
AKS Cluster
Azure Container Registry

Before we even start building the VSTS pipeline, we need to get some connection prerequisites out of the way. To deploy containers to the Kubernetes cluster, we need to have a working connection with it.

Open a Cloud Shell in Azure and type in:

It will tell you that the current context is located in “/home/NAME/.kube/config.”

Now open the /home/NAME/.kube/config with nano or cat and paste everything from there in a notepad. You need that wall of text to establish the connection to the cluster using VSTS.

Let’s go to VSTS where we will create a service endpoint to our Kubernetes cluster.
At the project dashboard, press on the whell icon and press on services.

Press on the New Service Endpoint and select Kubernetes.

Paste in the details from the .kube/config file in the kubeconfig box and the https://aksdns

Create a repository and add the following files and contents to it:
*I know it would be easier to clone from my Github Repo but when I’m learning I like doing copying and pasting stuff in VSCode, analyse and then upload.

You will need to add an “index.html” with whatever you want it to be written in it. I went with “One does not simply push changes to containers. Said no one ever.”

You’re done building the repository; now it’s time to setup the build definition.

Go to Build and Releases, Press on New and select the new Git repository that you just created.

At the template screen press on Container and press Apply.


On the new screen, go to variables and create two new variables

ACR_DNS with the value of your ACR registry link in the form of name.azurecr.io
BUILD_ID with the value $(Build.BuildId)

Now go back to the task pane by pressing the cross where the phase 1 task says and add the Replace Tokens task and Publish Artifacts task. The result should look like the screenshot below.

For each task fill in the following:

Build an Image
Container Registry Type = Azure Container Registry
Azure Subscription = Your Subscription
Azure Container Registry = Select what you created
Action = Build an Image
Docker File = **\Dockerfile
Use Default Build Context = Checked
ImageName = nginxdemo
Qualify Image Name = Checked
Additional Image Tags = $(Build.BuildId)

Push an Image
Container Registry Type = Azure Container Registry
Azure Subscription = Your Subscription
Azure Container Registry = Select what you created
Action = Puysh an image
ImageName = nginxdemo
Qualify Image Name = Checked
Additional Image Tags = $(Build.BuildId)

Replace Tokens
Target Files = **/*.yaml
Files Encoding = auto
Advanced
Token Prefix = __ (Double Underscore)
Token Suffix = __ (Double Underscore)

Publish Artifact
Path to publish = deploy.yaml
Artifact name = deploy
Artifact publish location = Visual Studio Team Service/TFS

Now go to triggers, select Continuous integration and check “Enable continuous integration” then press the arrow on Save & queue and press save.

The build has been defined; now we need to create a release.

Go to Build and Releases and press on Release

Press on the cross and then on the “Create release definition”

In the New Release Definition pane, select the “Deploy to Kubernetes Cluster template and press on Apply

Now that the template is pre-populated to deploy to the Kubernetes Cluster, you need to add an artifact, select the Build Definition and add it.

Now it’s time to enable Continuous deployment so press on the lightning bolt that’s located in the upper right corner of the artifact and enable the CD trigger.

Now go to the Tasks tab located near the Pipeline and modify the kubectl apply command.
kubectl apply
Kubernetes Service Connection = Select the K8 connection that you created
Command = Apply
Use Configuration files = Checked
Configuration File = press on the three dots and reference the deploy.yaml or copy what is below.
$(System.DefaultWorkingDirectory)/K8Demo/deploy/deploy.yaml

Now press save, queue a new build and wait for the container to get deployed and when it’s done just type in the Azure Cloud Shell kubectl get services and the IP will pop.

Final Thoughts

So you finished configuring the CI/CD pipeline and deployed your first container to an AKS cluster. This might seem complicated at first but once you do this a couple of times, you will be a pro at it, and the problems you will face will be on how to make it more modular. I do similar things at clients most of the times when I’m automating application deployments for cloud-ready or legacy applications. This type of CI/CD deployment is quite easy to deploy, when you want to automate a full blow microservices infrastructure, then you will have a lot more tasks to do jobs. My most significant CI/CD pipeline consisted of 150 tasks that were needed to automate a legacy application.

What I would consider some best practices for CI/CD pipelines in VSTS or any other CI/CD tool is to never hard code parameters into tasks and make use of variables/variable groups. Tasks like the “Replace Tokens” one permit you to reference those variables so when one changes or you create one dynamically, they just get filled in the code. This is very useful when your release pipeline deploys to more than one environment, and you can have global variables and environment specific variables.

Well, I hope this was useful.

Until next time!

Pin It on Pinterest