MEAN Applications on Deis Workflow
Deis Workflow is a PaaS that lets you automatically build and deploy applications on a Kubernetes cluster via simple triggers like
git push. Workflow also lets you manage app configuration, create or roll back releases, perform extensive logging, and more.
If you are concerned whether Deis Workflow can handle your application, you'll be happy to know there are three ways to deploy:
Even if you're not using Heroku buildpacks, you can usually deploy your application via Docker images or Dockerfiles. With all this scope for flexibility, Deis Workflow can cater to almost any cloud software setup.
In this post, we'll get specific though.
Node.js has emerged as one of the most popular server scripting languages. Combined with other modern tools like AngularJS and MongoDB (aka the MEAN stack) it can be a great way for developers to create modern web applications quickly.
So, how do you deploy an Express.js (a web framework based on Node.js) application via Deis Workflow? We'll get to that.
But first, we need to install and launch Deis Workflow.
Install CLI Tools
The Deis CLI tool lets you interact with Deis Workflow. Ideally, you should install the client in your
$PATH to avoid any
command not found errors.
So, change your directory to
/usr/local/bin, and install by running:
Check if it's working with:
Next you'll need to install Helm Classic. Helm is a package manager for Kubernetes. We'll use it to manage software in our Kubernetes cluster.
Install it with:
Again, check if install is successful.
Next step is to boot up a Kubernetes cluster.
I have used AWS EC2 as the backend cloud. You can choose to use Google Container Engine (GKE) or even your own laptop.
Since we'll use command line interface to interact with AWS, you'll need to install AWS and Kubernetes CLI tools.
Once you are done, type:
You'll be prompted to add the Key ID, Secret Access Key, default region name, and the output format.
You can now interact with your AWS account via the CLI.
Set Up Your Kubernetes Cluster
Create a folder at a suitable place on your computer that will serve as home to your Kubernetes installation.
Then download and unzip Kubernetes:
Now configure the Kubernetes environment:
Now that you're ready, boot up the cluster using:
Now we have a Kubernetes cluster ready, let's install Deis Workflow.
Install Deis Workflow and Helm
We'll need to use the Helm package manager.
First check if it can connect with your Kubernetes cluster:
You should get a detailed list like this:
This confirms Helm can talk to your Kubernetes cluster. This is the cluster we booted in the previous section.
The next step is to add Deis charts repo to Helm:
Then install Deis Workflow:
This will complete the installation process.
You'll have to wait some more for the pods to be ready. You can check the progress using this command:
Once all the pods show a ready status, Deis Workflow is up and running.
Here's what that looks like:
Deis Workflow on EC2 automatically provisions and attaches an elastic Load balancer (ELB) to the router component.
The router component is responsible for routing HTTP and HTTPS requests from the public internet to your applications in the cluster.
By default, the connection timeout for Elastic Load Balancers is 60 seconds. This is too short for long running connections when using the Deis Workflow
git push functionality. So, we'll need to adjust the default load balancer configuration.
First, get the load balancer name by running:
You should see something like this:
The AWS name for your elastic load balancer is the string before the first
- character. In this case,
Now, change the timeout setting:
Remember to replace the value in the
--load-balancer-name section with the name of your load balancer.
Now the ELB is configured, we need to configure DNS so requests can be sent to applications running on Deis Workflow via the internet.
To use the nip.io service, first pick one of the IP addresses assigned to your ELB. (We got the ELB details in the previous section.)
You should get a response like this:
Now, construct your hostname by taking the IP address for your load balancer and adding
.nip.io to it.
For my example, I used the first IP address that I got:
184.108.40.206.nip.io. (You can use any of the IP addresses from the previous step's sample output.)
You'll see this response:
The nip.io DNS answers with the same IP address, no matter the hostname. That's because nip.io is a wilcard DNS service. It maps
ANYTHING.IP_ADDRESS.nip.io to the corresponding
220.127.116.11.nip.io maps to
Now you have a hostname to make requests to your application.
Finally, we'll need to create an admin user on your Deis Workflow installation.
Set Up Your Deis Admin
The first user to register with Deis Workflow will automatically be given admin privileges.
Using the DNS hostname from the previous step, let's create our admin user.
You'll be prompted to enter the username, password, and email. Once entered, you'll be registered as admin.
However, before you can deploy an application, you'll need to generate and add keys.
You can do this by running:
Next, you'll be asked to select a location to save the key file and an optional passphrase.
Once keys are generated successfully, add them to the SSH agent:
And then to Deis Workflow:
Don't forget to change the path to key file, if you've saved it somewhere else.
This finishes Deis Workflow setup.
Let's now move on to see how to deploy an Express.js application.
Deploying an Express.js Application
Clone your application to a local directory:
For demo purposes, I used used a fork of the example-nodejs-express repo by Deis.
Change to the directory where the repo was cloned:
Now create a Deis application by running:
Since we didn't assign a name to the application, Deis will automatically assign a random name. In my case it was
Here is how the output should look:
Now point the Git remote at the Deis builder:
This should start the build process. You should see output like this:
Once the build is completed, you can check if your project is accessible.
Run this command:
You'll see the message "Powered by Deis" as the output. This means
curl was able to successfully connect to your deployed project.
Congrats! Everything worked.
In this post, we saw how to deploy a MEAN application on an AWS-hosted Kubernetes cluster with Deis Workflow and Helm.
We first used the
kube-up.sh script to boot up the Kubernetes cluster on EC2. Then we installed Workflow using the Helm package manager and looked at configuration. Finally we deployed a MEAN application on Workflow using the
git push trigger.