/ azure

Extreme Scale WordPress on Azure Pt 1

I've done another series on WordPress in Azure using VMs, Scale Sets and Gluster. Today, I'm going to talk about how you can take a more PaaS centered approach and leverage App Service's relatively new App Services for Containers. Another fun approach - let's do it with nothing but the CLI!

First, we're going to need a Resource Group:

az group create --name wplab --location eastus

Next, let's create an App Service Plan that supports Linux Containers

az appservice plan create --name wplab --resource-group wplab --sku p2v2 --is-linux

Here's an App Service Plan

Next, we're going to deploy a multi-container app into there using a YAML that I slung together.

az webapp create --resource-group wplab --plan wplab --name dermarwplab --multicontainer-config-type compose --multicontainer-config-file docker-compose-wordpress.yml

To deploy this, you'll need my YAML from the GitHub repository located here.

There's not too much to this YAML, just defining that I want two containers. The first is from Wodby to provide a Varnish server in front of my web app. Varnish does glorious things for caching stuff. Next, is an ever so slightly customized version of the WordPress container published to my own Docker Hub (doodlemania/wpmulticontainer). The above referenced GitHub has the Dockerfile for it.

Here's the YAML:

YAML for you!

The Dockerfile is a bit big to post, but what I did was rif off the Azure provided multi-container approach which adds SSL based WordPress support and also installed the Redis extension so we can leverage it later using Azure Redis Cache.

I also changed the Entrypoint (docker-entrypoint.sh) a bit more substantially so that Azure MySQL as a Service can be used instead of attempting to use a container for MySQL and then expose it's settings via environment variables in App Services so we don't have to try and manually hack on config files in the container. Same also applies for making the Redis configuration a set of environment variables too.

Big shout of to my friend and colleague Karim for his inspiration on this approach on his Drupal setup. You can find his article here.

It only takes a few seconds for the deployment to happen, at which point it is now time to create the MySQL server, configure it and then Redis + configure it.

az mysql server create --resource-group wplab --name dermarwplab --location eastus --admin-user wpadmin --admin-password 'yourcoolpwd' --sku-name B_Gen5_1 --version 5.7

This takes a few minutes...coffee (or beer time).

Now that this is done, let's immediately configure MySQL so we are ready to connect to it with our web app.

az mysql server firewall-rule create --name allAzureIPs --server dermarwplab --resource-group wplab --start-ip-address 0.0.0.0 --end-ip-address 0.0.0.0

This tells the Azure firewall to let Azure talk to my new Azure based MySQL server

Next, we create the WordPress database:

az mysql db create --resource-group wplab --server-name dermarwplab --name wordpress

Now, let's set up Redis Cache. Question: why Varnish + Redis? Well, for me, this allows a number of different scaling points. Varnish caches whole requests (pages) so isn't amazing for extremely dynamic sites. Redis caches bits and pieces of database calls to make them faster. Having both gives me options depending on which direction I need to scale.

az redis create -g wplab -l eastus -n wpredis --sku basic --vm-size C0 --enable-non-ssl-port

Next up, we need to get the key from Redis so we can connect to it. We'll copy this to our clipboard cause in the next part of the series, we'll need to put that key into our environmental variables.

az redis list-keys --name wpredis --resource-group wplab (copy primary key)

The output will look like this:
{ "primaryKey": "bunch o stuff=", "secondaryKey": "more stuff=" }

We want the Primary Key contents including the = sign but NOT the "

And we have a pretty setup so far!

Such PaaS

Stay tuned for the next steps in the upcoming blog.