A complete guide to deploy an Elixir Phoenix application to Kubernetes

11.01.20192 Min Read — In DevOps

We are SiliconJungles developer. Elixir is an awesome programming language, we love it and Phoenix framework helps us build simplicity, productivity and really fast applications.

Developing is always fun, but deploying will have a bit painful. We tried many ways to deploy, from running Phoenix server without compiling, after that we wrote a deploy script which is using Distillery 1.x to compile, then copy compiled file to dedicated server, extract and run it. We also wrote another upgrade script to copy upgraded version to dedicated server, run command to trigger hot-upgrade. And there's no way to downgrade/migration/seed without access to server or even remote_console (for the migration/seed).

And one day, we decided let's start with Kubernetes, learn and figure out how to use Kubernetes to help our deployment process.

In this blog series, you will see the way we use Kubernetes for our applications.

Before we get started, we assume you already have a backend application running by Phoenix framework with PostgreSQL database and Redis for background processing.

Table of contents

  • Part 1: Prepare for deployment

    • Distillery 2
    • Database migration/seed/rollback
    • Dockerize
  • Part 2: Running the application on Docker environment

    • Docker compose
    • Secret environment variables
    • Database migration/seed/rollback
    • Distillery hook introduction
  • Part 3: Image building on CI environment using Circle CI workflow
  • Part 4: Kubernetes introduction

    • Minikube install
    • Basic knowledge about Kubernetes: Pod, Deployment, Service, HPA, Job.
  • Part 5: Kubernetes configuration

    • Kubernetes your application and run it on local development environment
  • Part 6: Packing your Kubernetes configuration using Helm

    • Helm introduction
    • Chart and dependencies
  • Part 7: Encrypt / Decrypt your environment variables configuration file

    • Helm Secrets
    • Deploying/Upgrading/Rollback your Helm Chart with Secret file
  • Part 8: Prepare your infrastructure

    • Terraform your infrastructure with private subnets
  • Part 9: Kubernetes Operations

    • Using Kops with existing infrastructure
    • Terraform your DNS Cloudflare
    • Kops with CNI provider
  • Part 10: Running your Chart on Kubernetes production
  • Part 11: EFK stack on your Kubernetes environment
  • Part 12: Deploy your application from Android Phone