Skip to content

Instantly share code, notes, and snippets.

@coryodaniel
Last active April 30, 2020 03:25
Show Gist options
  • Save coryodaniel/354d81b14022c46b5a0d90ec333cbe0a to your computer and use it in GitHub Desktop.
Save coryodaniel/354d81b14022c46b5a0d90ec333cbe0a to your computer and use it in GitHub Desktop.
MyApp deployment operater
  • Use bonny to define a MyApp CRD and Controller
    • CRD has a few fields:
      • image
      • deployment_template
  • Define a DBMigration CRD and Controller
    • CRD has a few fields:
      • image
      • migration_template
  • The templates are ConfigMap’s
    • deployment_template is a k8s Deployment YAML manifest w/ no image set (runs ~mix run —no-halt)
    • migration_template is a k8s Job YAML manifest w/ no images set (runs ~mix ecto.migrate)
  • On add/modify of MyApp
    • Creates a DBMigration Job, waits for success
      • On success deploys Deployment
        • CRD controller fetches the template name in the incoming event
        • Injects the image name into the template
      • On failure pagerduty

Instead of deploying a Deployment we deploy a MyApp

apiVersion: "builds.example.com/v1"
kind: MyApp
metadata:
  labels:
    env: staging
spec:
  deployment_template: "name-of-current-configmap-with-deployment-template"
  image: myapp:v1.10.1

We lean on Github Actions to automatically deploy pr-based versions of the app:

apiVersion: "builds.example.com/v1"
kind: MyApp
metadata:
  labels:
    env: pr-78
spec:
  deployment_template: "name-of-current-configmap-with-deployment-template"
  image: myapp:pr-78

Using two CRDs allows us to migrate out-of-band with a deployment, for instance on staging to see if it breaks the current deployed version, since it should be backwards compat.

apiVersion: "builds.example.com/v1"
kind: DBMigration
metadata:
  labels:
    env: staging
spec:
  deployment_template: "name-of-current-configmap-with-migration-template"
  image: myapp:v1.10.1

Orignally we had it as a single CRD, but found value in breaking into two pieces to let us easily play out the scenario of the latest migration being applied while a previous container version was running.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment