Examples¶
Ready-to-use examples for common scenarios.
Quick Links¶
- PostgreSQL Examples - Complete PostgreSQL setup
- MySQL Examples - Complete MySQL setup
- CockroachDB Examples - Complete CockroachDB setup
- Drift Detection Examples - Drift detection and correction patterns
- Advanced Examples - Cross-namespace, TLS, cloud backups
Sample Manifests¶
All sample manifests are available in the repository:
# Clone the repository
git clone https://github.com/panteparak/db-provision-operator.git
# Navigate to examples
cd db-provision-operator/DOCS/examples/
Directory Structure¶
DOCS/examples/
├── postgresql/
│ ├── 01-credentials.yaml
│ ├── 02-instance.yaml
│ ├── 03-database.yaml
│ ├── 04-user.yaml
│ ├── 05-role.yaml
│ ├── 06-grant.yaml
│ └── 07-backup.yaml
├── mysql/
│ ├── 01-credentials.yaml
│ ├── 02-instance.yaml
│ ├── 03-database.yaml
│ ├── 04-user.yaml
│ └── 05-grant.yaml
├── mariadb/
│ ├── 01-credentials.yaml
│ ├── 02-instance.yaml
│ └── 03-database.yaml
├── cockroachdb/
│ ├── 01-credentials.yaml
│ ├── 02-instance.yaml
│ ├── 03-database.yaml
│ ├── 04-user.yaml
│ ├── 05-role.yaml
│ └── 06-grant.yaml
└── advanced/
├── cross-namespace.yaml
├── tls-connection.yaml
├── backup-to-s3.yaml
└── drift-detection.yaml
Common Patterns¶
Minimal Setup¶
The simplest setup requires:
- Admin credentials Secret
- DatabaseInstance
- Database
- DatabaseUser
# 1. Credentials
apiVersion: v1
kind: Secret
metadata:
name: db-admin
type: Opaque
stringData:
username: admin
password: secretpassword
---
# 2. Instance
apiVersion: dbops.dbprovision.io/v1alpha1
kind: DatabaseInstance
metadata:
name: my-db
spec:
engine: postgres
connection:
host: postgres.default.svc
port: 5432
secretRef:
name: db-admin
---
# 3. Database
apiVersion: dbops.dbprovision.io/v1alpha1
kind: Database
metadata:
name: myapp
spec:
instanceRef:
name: my-db
---
# 4. User
apiVersion: dbops.dbprovision.io/v1alpha1
kind: DatabaseUser
metadata:
name: myapp-user
spec:
instanceRef:
name: my-db
username: myapp
passwordSecret:
generate: true
secretName: myapp-credentials
Production Setup¶
Production deployments should include:
- TLS connections
- Role-based permissions
- Connection limits
- Backup schedules
- Deletion protection
See Advanced Examples for production patterns.
Using Examples¶
Apply All PostgreSQL Examples¶
# Apply in order
kubectl apply -f DOCS/examples/postgresql/01-credentials.yaml
kubectl apply -f DOCS/examples/postgresql/02-instance.yaml
kubectl apply -f DOCS/examples/postgresql/03-database.yaml
kubectl apply -f DOCS/examples/postgresql/04-user.yaml
kubectl apply -f DOCS/examples/postgresql/05-role.yaml
kubectl apply -f DOCS/examples/postgresql/06-grant.yaml
Verify Resources¶
# Check all resources
kubectl get databaseinstances,databases,databaseusers,databaseroles,databasegrants
# Check specific resource
kubectl describe databaseinstance postgres-primary
# Get generated credentials
kubectl get secret myapp-user-credentials -o jsonpath='{.data.password}' | base64 -d
Clean Up¶
# Delete in reverse order
kubectl delete -f DOCS/examples/postgresql/06-grant.yaml
kubectl delete -f DOCS/examples/postgresql/05-role.yaml
kubectl delete -f DOCS/examples/postgresql/04-user.yaml
kubectl delete -f DOCS/examples/postgresql/03-database.yaml
kubectl delete -f DOCS/examples/postgresql/02-instance.yaml
kubectl delete -f DOCS/examples/postgresql/01-credentials.yaml
Next Steps¶
- PostgreSQL Examples - Detailed PostgreSQL setup
- MySQL Examples - Detailed MySQL setup
- CockroachDB Examples - Distributed SQL setup
- Drift Detection Examples - Configuration drift management
- Advanced Examples - Production patterns