Skip to content

Commit 93789b0

Browse files
committed
📝 Add a starter readme.
1 parent bff4c79 commit 93789b0

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Migrations-Operator
2+
3+
A Kubernetes operator to manage database migrations or similar application setup tasks.
4+
5+
## Quick Start
6+
7+
### Install
8+
9+
TODO
10+
11+
### Usage
12+
13+
For the common case of running SQL migrations for a deployment, create a Migrator object:
14+
15+
```yaml
16+
apiVersion: migrations.coderanger.net/v1beta1
17+
kind: Migrator
18+
metadata:
19+
name: mymigrations
20+
spec:
21+
selector:
22+
matchLabels:
23+
app: myapp
24+
command:
25+
- python
26+
- manage.py
27+
- migrate
28+
```
29+
30+
This will automatically run migrations on all future deployment changes.
31+
32+
## How It Works
33+
34+
The operator has three main components: the migrations controller, the waiter init container, and the injector webhook. The migrations controller watches for new pods matching its selector and if they are running a new image, it launches a Job to run the migrations as configured. The waiter init container stalls a pod from fully launching until the required migrations have been executed successfully. The injector webhook automatically adds the waiter init container to any pod that matches a Migrator object.
35+
36+
Put together, these three components allow relatively normal Kubernetes usage while ensuring migrations are applied in the expected way.
37+
38+
## Alternatives
39+
40+
### Migrations-Operator vs. Helm/Argo Hooks
41+
42+
A common choice for running database migrations is the `pre-install/upgrade` hook in both Helm and Argo-CD. This allows for ensuring that migrations succeed before the main segment of the chart or application is applied. The main frustration with this approach is you can end up having to move a lot of things into the hook. If you pod uses a Secret or ConfigMap for holding configuration data that's required for running migrations, that will have to be hook'd too. If you need a whole chart dependency to be up for migrations, it may not even be posible. Migrations-Operator solves this by lazily cloning the pod specification on the new, waiting pods.
43+
44+
### Migrations-Operator vs. Init Container
45+
46+
Another common solution for database migrations is an init container to run the migration commands. The main problem here is locking, if you run 4 replicas of your application, all 4 of those are going to try and apply your migrations in parallel. You could add some leader election code to your migrations runner, however this has to be built in at the application image level and so requires a specific solution for each application framework or toolkit. Migrations-Operator has a top-level view of the world and so can ensure for only a single job at a time is created.

api/v1beta1/zz_generated.deepcopy.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)