A Backstage Software Template for provisioning MongoDB database instances using Crossplane.
This template creates the necessary Crossplane resources to provision a MongoDB database instance in your Kubernetes cluster. It includes:
- XRD (Composite Resource Definition): Defines the MongoDB API
- Composition: Implements the MongoDB provisioning logic
- Example Claim: Shows how to request a MongoDB instance
- π Self-Service Provisioning: Developers can provision MongoDB instances through Backstage
- βοΈ Configurable Storage: Choose storage size from 1GB to 100GB
- π§ Automatic DNS: Creates DNS records for database access
- π Status Tracking: Connection strings available in resource status
Ensure Crossplane is installed in your cluster:
kubectl create namespace crossplane-system
helm repo add crossplane-stable https://charts.crossplane.io/stable
helm install crossplane --namespace crossplane-system crossplane-stable/crossplane
This template requires the following Crossplane providers:
- Provider NOP (for simulation/testing):
kubectl apply -f - <<EOF
apiVersion: pkg.crossplane.io/v1
kind: Provider
metadata:
name: provider-nop
spec:
package: xpkg.upbound.io/crossplane-contrib/provider-nop:v0.2.0
EOF
Install the necessary Crossplane composition functions:
kubectl apply -f - <<EOF
apiVersion: pkg.crossplane.io/v1beta1
kind: Function
metadata:
name: function-go-templating
spec:
package: xpkg.upbound.io/crossplane-contrib/function-go-templating:v0.10.0
---
apiVersion: pkg.crossplane.io/v1beta1
kind: Function
metadata:
name: function-auto-ready
spec:
package: xpkg.upbound.io/crossplane-contrib/function-auto-ready:v0.2.1
---
apiVersion: pkg.crossplane.io/v1beta1
kind: Function
metadata:
name: function-sequencer
spec:
package: xpkg.upbound.io/crossplane-contrib/function-sequencer:v0.3.0
---
apiVersion: pkg.crossplane.io/v1beta1
kind: Function
metadata:
name: function-environment-configs
spec:
package: xpkg.upbound.io/crossplane-contrib/function-environment-configs:v0.1.0
EOF
- Navigate to the Software Catalog
- Click "Create Component"
- Select "MongoDB Database"
- Fill in the required parameters:
- Instance Name: Unique identifier for your MongoDB instance
- Namespace: Kubernetes namespace (default:
default
) - Storage Size: Size in GB (1-100)
- Owner: Team or user who owns this resource
- Apply the XRD:
kubectl apply -f content/definition.yaml
- Apply the Composition:
kubectl apply -f content/composition.yaml
- Create a claim:
kubectl apply -f content/example.yaml
Parameter | Description | Type | Default | Required |
---|---|---|---|---|
name |
Instance name | string | - | Yes |
namespace |
Kubernetes namespace | string | default |
No |
storageSize |
Storage size in GB | integer | 10 |
No |
owner |
Resource owner | string | group:platform |
No |
The template creates a composite resource that provisions:
- Cluster Resource: A simulated compute cluster for MongoDB
- DNS Record: Automatic DNS entry for database access
- ConfigMap: Stores configuration values
- NOP Resource: Simulates database provisioning delay (30s)
After provisioning, the connection string is available in the resource status:
kubectl get mongodb <instance-name> -n <namespace> -o jsonpath='{.status.connString}'
Format: mongodb+srv://<username>:<password>@<fqdn>/<database>
- Clone this repository
- Install the template in Backstage:
catalog:
locations:
- type: url
target: https://github.com/open-service-portal/service-mongodb-template/blob/main/template.yaml
To customize the MongoDB provisioning:
- Edit
content/definition.yaml
to add parameters - Modify
content/composition.yaml
to change provisioning logic - Update
template.yaml
to expose new parameters in Backstage
MongoDB stuck in Creating state
- Check if all required functions are installed
- Verify the NOP provider is running:
kubectl get providers
Connection string not appearing
- Ensure DNS record creation succeeded
- Check composition logs:
kubectl describe composition mongodb
Permission denied errors
- Verify Crossplane has necessary RBAC permissions
- Check ServiceAccount bindings
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Submit a pull request
MIT License - see LICENSE file for details
For issues and questions:
- GitHub Issues: open-service-portal/service-mongodb-template
- Discussions: open-service-portal/discussions