A Kubernetes operator that manages MVC+R (Model, View, Controller, Repository) pattern RestAPI deployments with auto-scaling, health monitoring, and blue-green deployments.
- MVC+R Pattern Management: Deploy and manage Model, View, Controller, and Repository components separately
- Auto-scaling: Horizontal Pod Autoscaler (HPA) integration with CPU and memory metrics
- Health Monitoring: Configurable liveness and readiness probes
- Blue-Green Deployments: Zero-downtime deployments with traffic switching
- Service Discovery: Automatic service creation for each component
The operator manages four main components:
- Model: Data layer handling business logic and data structures
- View: Presentation layer for API responses and UI rendering
- Controller: Request handling and routing logic
- Repository: Data access layer for database operations
- Kubernetes cluster (v1.20+)
- kubectl configured
- operator-sdk (optional, for development)
# Apply CRDs
make install
# Deploy the operator
make deploy
# Or build and deploy locally
make docker-build docker-push IMG=<your-registry>/restapi-operator:tag
make deploy IMG=<your-registry>/restapi-operator:tagapiVersion: apps.aws.com/v1
kind: RestAPI
metadata:
name: guestbook-api
spec:
image: "nginx:1.21"
replicas: 2
# MVC+R Components
model:
enabled: true
image: "guestbook/model:v1.0.0"
port: 8080
view:
enabled: true
image: "guestbook/view:v1.0.0"
port: 3000
controller:
enabled: true
image: "guestbook/controller:v1.0.0"
port: 8081
repository:
enabled: true
image: "guestbook/repository:v1.0.0"
port: 8082spec:
autoScaling:
enabled: true
minReplicas: 1
maxReplicas: 10
targetCPUUtilization: 70
targetMemoryUtilization: 80spec:
healthCheck:
enabled: true
path: "/health"
initialDelaySeconds: 30
periodSeconds: 10
timeoutSeconds: 5
failureThreshold: 3spec:
blueGreen:
enabled: true
strategy: "automatic"
promotionTimeout: 300Each MVC+R component supports:
- enabled: Enable/disable the component
- image: Container image for the component
- port: Service port for the component
- envVars: Environment variables specific to the component
The operator creates the following resources for each enabled component:
- Deployment: Manages pod replicas
- Service: Provides service discovery
- HorizontalPodAutoscaler: Manages auto-scaling (if enabled)
When blue-green deployment is enabled:
- Both blue and green environments are maintained
- Traffic is routed to the active environment
- New deployments go to the inactive environment
- Traffic switches after successful health checks
- Old environment is kept for rollback capability
- Go 1.21+
- Docker
- kubectl
- operator-sdk
# Generate manifests
make manifests
# Run tests
make test
# Build operator
make build
# Run locally (requires kubeconfig)
make runmake manifests| Field | Type | Description |
|---|---|---|
| image | string | Default container image |
| replicas | *int32 | Number of replicas |
| envVars | map[string]string | Global environment variables |
| model | ComponentSpec | Model component configuration |
| view | ComponentSpec | View component configuration |
| controller | ComponentSpec | Controller component configuration |
| repository | ComponentSpec | Repository component configuration |
| autoScaling | *AutoScalingSpec | Auto-scaling configuration |
| healthCheck | *HealthCheckSpec | Health check configuration |
| blueGreen | *BlueGreenSpec | Blue-green deployment configuration |
| Field | Type | Description |
|---|---|---|
| enabled | bool | Enable/disable component |
| image | string | Component container image |
| port | int32 | Service port |
| envVars | map[string]string | Component environment variables |
| Field | Type | Description |
|---|---|---|
| enabled | bool | Enable auto-scaling |
| minReplicas | *int32 | Minimum replicas |
| maxReplicas | int32 | Maximum replicas |
| targetCPUUtilization | *int32 | Target CPU utilization percentage |
| targetMemoryUtilization | *int32 | Target memory utilization percentage |
See config/samples/ for complete examples.
- Fork the repository
- Create a feature branch
- Make changes and add tests
- Run
make testandmake manifests - Submit a pull request
Licensed under the Apache License, Version 2.0.