Kubernetes Operator
SchemaHero can run as a Kubernetes operator, watching for Table custom resources and managing migrations automatically.
When to use the operator:
- You want migration approval workflows within Kubernetes
- Your team already manages everything via kubectl/GitOps
- You want automatic drift detection
When to use the CLI instead:
- CI/CD pipelines (GitHub Actions, GitLab CI, etc.)
- Local development
- Non-Kubernetes environments
- You want explicit control over when migrations run
Installing the Operator
kubectl schemahero installThis installs:
- SchemaHero CRDs (Database, Table, Migration)
- The schemahero-manager deployment
- RBAC resources
Verify:
kubectl get pods -n schemahero-systemCreating a Database Connection
apiVersion: databases.schemahero.io/v1alpha4
kind: Database
metadata:
name: my-database
namespace: default
spec:
connection:
postgres:
uri:
valueFrom:
secretKeyRef:
name: postgres-secret
key: uriThe secret:
apiVersion: v1
kind: Secret
metadata:
name: postgres-secret
type: Opaque
stringData:
uri: postgres://user:password@host:5432/dbname?sslmode=requireCreating Tables
apiVersion: schemas.schemahero.io/v1alpha4
kind: Table
metadata:
name: users
namespace: default
spec:
database: my-database
name: users
schema:
postgres:
primaryKey: [id]
columns:
- name: id
type: uuid
default: gen_random_uuid()
- name: email
type: varchar(255)
constraints:
notNull: trueApply it:
kubectl apply -f users-table.yamlMigration Workflow
When you create or update a Table, SchemaHero:
- Compares desired state to actual database
- Creates a Migration resource with the planned DDL
- Waits for approval (unless
immediateDeployis set)
View Pending Migrations
kubectl schemahero get migrationsOutput:
NAMESPACE NAME DATABASE TABLE PHASE
default users-abc123 my-database users PlannedReview a Migration
kubectl schemahero describe migration users-abc123Shows the SQL that will be executed.
Approve a Migration
kubectl schemahero approve migration users-abc123The migration executes and the table is updated.
Reject a Migration
kubectl schemahero reject migration users-abc123The migration is discarded. Update your Table spec and a new migration will be planned.
Immediate Deploy
Skip the approval step for dev/staging environments:
apiVersion: databases.schemahero.io/v1alpha4
kind: Database
metadata:
name: my-database
spec:
immediateDeploy: true
connection:
postgres:
uri:
valueFrom:
secretKeyRef:
name: postgres-secret
key: uriWith immediateDeploy: true, migrations apply automatically when Tables change.
GitOps Integration
Store your Table manifests in git. Use Argo CD or Flux to sync them:
k8s/
├── databases/
│ └── my-database.yaml
└── tables/
├── users.yaml
├── teams.yaml
└── posts.yamlWhen you merge a PR that modifies a table, your GitOps tool applies it, SchemaHero plans the migration, and (if immediateDeploy is set) executes it.
Uninstalling
kubectl schemahero uninstallThis removes the operator but leaves your database schema intact.