App
Introduction
This guide walks you through migrating an application from Heroku to Azure Kubernetes Service (AKS) using Massdriver, with an emphasis on using private network access to enhance security. We’ll use Azure’s services, and Massdriver will handle most of the infrastructure setup and orchestration.
Prerequisites
Before starting, ensure you have the following:
- Mass CLI
- kubectl
- Docker
- Massdriver account
- A deployed Azure Kubernetes Service (AKS) cluster
Step 1: Create a Dockerfile
It’s hard to provide a general guide on how to dockerize a Heroku app, as it depends on the app's structure and dependencies. However, here are some general tips that might help you:
- Use
docker initin your app directory to generate a customDockerfilefor your app. - Use a
.dockerignorefile to exclude unnecessary files and directories from the Docker image. - Use a build cache to speed up the build process.
- Build and test your Docker image locally before pushing it to a registry.
For a detailed video on getting started with Dockerizing an application, check out:
Step 2: Build and Test the Docker Image
Set up some environment variables to make the process easier:
imageName="<your-image-name>" # e.g. my-app
namespace="<your-namespace>" # e.g. my-image-namespace
location="westus" # set this to your preferred Azure region
mdArtifactId="<your artifact id>" # https://docs.massdriver.cloud/concepts/artifacts#artifact-idBuild the Docker image:
docker build -t $imageName .Run the Docker image locally to test it:
docker run -p 8080:8080 $imageNameBrowse to
http://localhost:8080to see your app running.
Step 3: Create a Massdriver application bundle
Setup the Mass CLI environment variables noted here.
Generate a new application template:
- Run the following command and follow the prompts:
mass bundle newAdd your environment variables to the
massdriver.yamlfile:- Review the example below of how to configure environment variables in the
massdriver.yamlfile:
app:
envs:
LOG_LEVEL: .params.configuration.log_level
MONGO_DSN: .connections.mongo_authentication.data.authentication.username + ":" + .connections.mongo_authentication.data.authentication.password + "@" + .connections.mongo_authentication.data.authentication.hostname + ":" + (.connections.mongo_authentication.data.authentication.port|tostring)
policies:
- .connections.storage_account.data.security.iam.read_write
secrets:
OPENAI_API_KEY:
required: true
title: OpenAI API Key
description: The API key for OpenAI that gives me sketchy life advice- For more information about how to configure these environment variables, refer to our examples or video walkthrough.
- Review the example below of how to configure environment variables in the
Publish your application bundle to Massdriver:
mass bundle publishView your application bundle in Massdriver:
- Browse to https://app.massdriver.cloud and log in.
- In the
Bundle Catalog, search for your application bundle. - Drag it out to the canvas to start configuring your application.
- If you want to implement DNS, be sure add DNS and configure it based on your domain registrar, then enable DNS for AKS first.
- Don't deploy yet!!
Step 4: Push the Docker Image to Azure Container Registry
Build and push your image to ACR:
mass image push $namespace/$imageName --region $location --artifact $mdArtifactId --tag latestCopy output from the previous command and paste in
Repositoryfield in your application bundle configuration in Massdriver.Set the
Tagfield tolatest.
Step 5: Deploy and Test
Deploy your application bundle in Massdriver:
- Click the
Deploybutton in the bottom of your bundle configuration.
- Click the
Access your application:
- Set up
kubectlandkubeconfigto access your AKS cluster by following this guide. - Run the following commands to view your application's status:
kubectl get pods
kubectl describe pod <pod-name>
kubectl logs <pod-name>- If you experience any issues, refer to the troubleshooting guide.
- Set up
OpenTofu Foundations - A FREE Weekly Workshop to Build your IaC Skills - LIMITED AVAILABILITY