- Use bonny to define a
MyApp
CRD and Controller- CRD has a few fields:
- image
- deployment_template
- CRD has a few fields:
- Define a
DBMigration
CRD and Controller- CRD has a few fields:
- image
- migration_template
- CRD has a few fields:
- 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)
- deployment_template is a k8s
- 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
- On success deploys Deployment
- Creates a
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.
- Bonny: https://github.com/coryodaniel/bonny
- Example Controller: https://github.com/coryodaniel/hello_operator/blob/master/lib/hello_operator/controllers/v1/greeting.ex#L60
- Waiting on Status: https://hexdocs.pm/k8s/usage.html#wait-on-a-resource
- Creating an Operation from a YAML file: https://hexdocs.pm/k8s/usage.html#creating-a-deployment-from-a-yaml-file