This demo blog post is about deploying WordPress CMS with creating a docker image from scratch, using Microsoft Azure Container register for privately storing the dockerized image. Also, use Managed K8s, Azure Kubernetes to deploy this image on AKS Cluster and worker nodes.
- Build the docker image for WordPress
- Use Azure container registry to store the dockerized image
- Create Azure Database for MySQL
- Create AKS Cluster and deploy the image
- Create Kubernetes manifest file with the desired state for WordPress CMS.
- Microsoft Azure Account – free trial works.
- Azure CLI
- Kubernetes – Link here
- Docker Desktop for MacOS
- A link to wordpress to download and build docker image
Build Docker Image
Grab a free version of the latest WordPress version. Create new directory
WordPress for your project and use this simple folder structure
Open the compressed file to view the contents for the package.
This screenshot below to read the database host, username and password from the Kubernetes manifest file.
Before creating the docker file, just need to restructure the folder structure as below
Create a blank Dockerfile
Create a new Dockerfile and copy code snippet from below screenshot. This below file is setting up Apache web server with PHP and enabling mysqli extension.
Before executing the docker build command, need to ensure the docker desktop is installed and also running successfully.
docker build --tag myblog:latest
It’ll take sometime to build the image with tags. Once its completed, we can open up docker desktop and view the latest image added on the our machine disk. myblog with tag latest is added here.
Use ACR – Azure Container Registry to store the dockerized image
az acr create --resource-group wordpress-project \ --name wpAzureContainerRegistry2020 --sku Basic
Login to ACR which is recently created
Tag and Push the dockerized image to this ACR.
Docker tag 7eb3872a0449 wpazurecontainerregistry2020.azurecr.io/7eb3872a0449:latest
Docker push wpazurecontainerregistry2020.azurecr.io/7eb3872a0449:latest
Create AKS cluster
az aks create --resource-group wordpress-project --name wordpresscluster--node-count 1 --generate-ssh-keys Also update the ACR registry, with this same AKS Cluster. az aks update -n myAKSCluster -g wordpress-project --attach-acr wpazurecontainerregistry2020.azurecr.io
Installing the az aks install-cli package for executing kubectl commands.
kubectl get nodes
Once the nodes are setup, need to ensure Azure Database for MySQL is all up and running.
Post successfully creating the Azure Database for MySQL, back to VSCode.
kubectl get service
It would take some time to get all the pods all setup and running successfully.
Need to use the same external ip [188.8.131.52] from the above screenshot and it just works. It loads up the WordPress admin installation page.
That’s all, one more demo post done with the K8s bits, Happy kubectl K8s!