BLOG

 
AKS_featured

Deploying MuleSoft apps on Azure AKS

30 Jan 2018, by Rodrigo Nascimento in Azure, Cloud, Containers, DevOps, Docker, Integration Architecture, Kubernetes, Linux, Middlewares, Mulesoft, Technical Infrastructure, Virtual Machine

This article is a quick guide to demonstrate how to deploy a MuleSoft (Mule) app in a container on Azure AKS (Azure Container Service – Kubernetes).

Apart from assuming that you have (very) basic knowledge about Azure, containers and MuleSoft, below are the other pre-requisites:

  • SSH key pair – you will need a SSH Key Pair in order to login into the VMs created by AKS. If you don’t have one, don’t know how to generate one or have no idea what I’m talking about, have a look a this guide from Azure.
  • Service Principal – If you don’t know what it is, check this guide: https://goo.gl/2WHkIE
  • Azure CLI 2.0 – version 2.0.21 or later is required to use Azure AKS functionalities.
  • Kubernetes command line client (kubectl) – it is used to manage the Kubernet cluster. If you have the Azure CLI installed, just run this command: az aks install-cli
  • Docker Hub account – If you don’t have an account, just go to https://hub.docker.com and create one
  • Mulesoft Anypoint Studio – If you don’t know what it is, check this page: https://www.mulesoft.com/platform/studio
  • Anypoint Platform Account – you will need an account to download the ‘hello-word’ example used in this guide (unless you want to use your own app). If you don’t have an account, create one at: https://anypoint.mulesoft.com
  • Project folder – We also need to create a folder named ‘hello-docker’ to save the files for this lab.

 

Creating Azure AKS cluster

The first thing we need to do is to create our Azure AKS (Kubernetes) cluster. Click New ontop left of you Azure Portal screen, and type container in the search box then click on ‘Azure Container Service – AKS’

 

 

In the Basics blade enter the following information:

  • Cluster Name – MuleCluster
  • DNS prefix – leave blank
  • Kubernetes version – 1.8.1
  • Subscription – choose the subscription you want to use for this lab
  • Resource group – create a new one named K8S-MULE-RG
  • Location – choose your preferred location (Ive chosen ‘Central US at its been the most stable for me during the preview period)

 

 

Click on create button and fill the following information in the Configuration blade:

  • User name – muleuser (or any other name you would prefer)
  • SSH public key – use your own ssh public (not private!) key as mentioned in the pre-requisites
  • Service principal client ID
  • Service principal client secret
  • Nodes count – number of nodes you want to run in your cluster
  • Node virtual machine type – Ive used the cheapest one available for this lab (Standard_A2_v2)
  • OS disk size – leave blank

Note: In real life scenarios, the last three properties above must represent the requirements outcomed from your sizing exercise, which are based on the App(s)/Container(s) that you are going to spread across the cluster. One particular point to pay attention is the OS disk size as AKS cluster nodes dont have data disks because of their stateless nature (obviously!).

 

 

Just click OK and check your configuration on the next blade. If you’re happy, click OK again and Azure will start to create your cluster.

 

Configure your local machine to connect to Azure AKS

In order to connect to your Azure AKS cluster, you need to download its credentials. Run the following command it the credentials will be downloaded to ./kube under your user home folder.

az aks get-credentials -g K8S-MULE-RG -n MuleCluster

To test the configuration, use the following command:

You should see somthing like this:

Note: This command will overwrite any existing ~/.kube/config file. I find it useful to rename the configuration file to a name that can identify the target cluster. For example, if you rename our created ‘config’ file to ‘config-aks-mule’, you can add the configuration file details to your kubectl command like this:

 

Prepare your Mule app

In order to keep this lab simple, we are going to use the ‘Hello-World’ example from Anypoint Exchange.

Open your Anypoint Studio and click on File -> New -> Project from Example

 

 

In order to download an example you must be logged in on the Anypoint Platform. So, if youre not logged, click on the Login Button at the top right of the Exchange screen.

 

 

Enter your login credentials, then search and select the project Hello World.

 

 

Click on ‘Open’ button and the project will be downloaded to your workspace.

 

 

Before we create a deployable archive, we need to set a port for the application to listen.

 

 

Now select the HTTP listener configuration and click on the ‘Edit’ button.

 

 

Change the port value from ‘${http.port}’ to ‘8085′.

 

Right-click on the project root and select ‘Export’

 

Select ‘Mule deployable archive’ and click next

 

Choose the ‘hello-docker’ folder as the destination for our archive (zip) file

 

 

Create your Docker image

Now it is time to create a docker image that contains both Mulesoft app and runtime. In our hello-docker folder, create a file named ‘Dockerfile’ with the content below. It is out of the scope of this post to explain what a Dockerfile is, but for now you just need to understand that it is using an existing base image (java:openjdk-8-jdk) that contains the MuleSoft runtime, downloads the standalone runtime version and add our app (Hello Word) to the target image.

 

Now that we described what our image will contain, its time to build our image. In the hello-docker folder, we will use the following syntax to build our image:

In our case it will be:
 

Push your image to Docker Hub

Now it is time to send your docker image to a repository. For this lab we will use Docker Hub as it is free. If you don’t have an account, just go to https://hub.docker.com and create one. Use the following command to login into your account:

Enter your user and password, then you should get a ‘Login Succeeded’ message. To push your image, just use the following syntax:

For example:

 

If you go to your docker hub repository, you should see it published:

 

 

Deploying the Hello World app

In order to deploy our Hello World app to Kubernetes, we need to create a deployment file. In our hello-docker folder, create a file named ‘deployment.yaml’ and paste the content below. Again I’m not going into the details of this manifest file, but I just would like to mention that it will create a Kubernetes deployment that will be responsible for creating a POD running a container with the image we created (our ‘Hello World’ app) and a Service (Load Balancer) that will expose the app to the external world.

To create the deployment in our cluster use the following command:

 

Checking if everything is working

It is time to see if our efforts paid off. As the container will take some time to be ready, we can start looking at Azure AKS (Kubernetes) dashboard to see the deployment progress. Run the following command to open a tunnel to your cluster and browse the dashboard:

Your default browser will open the overview page, which should look something like this:

 

Click on ‘Deployments’ in the left menu and it will show the deployment progress.

 

Click on ‘Services’ in the left menu to see the external endpoint we are going to use to access the app.

 

 

We can even look at the application logs to see if it was successfully deployed into MuleSoft runtime. Click on ‘Pods’ in the left menu and then select the ‘mule-hello-world-xxxxx’ pod, then click on the ‘Logs’ button in the top right menu. You should see a screen like this:

 

We can see that the runtime engine successfully identified the new app and started it. Now it is time to check if we can access it from the Internet. Using the external endpoint from the ‘Services’ page, we just need to append ‘/HelloWorld’ and see the following result:

 

Probably not the most exciting page to look at but, considering all the good stuff we learned through this lab, I hope you are satisfied with the achievement!


Rodrigo Nascimento is an experienced Enterprise and Solution Architect driven by innovation and integrity.
The combination of his passion for technology (which started when he was only 7 years old with his first ZX Spectrum) and his strong academic business background (bachelor’s degree in Marketing and MBA) has been used in many organisations to optimise the utilisation of IT resources and capabilities to leverage competitive advantage over the past 20 years.

LEAVE A COMMENT