Unit Operator

Unit Operator - Distributed Workload Operator for Kubernetes
Manage UnitSet, Unit, and GrpcCall resources with built-in high availability, scaling, and lifecycle management capabilities
β¨ Features
- π― UnitSet Management: Manages sets of distributed units with shared configuration
- π¦ Unit Lifecycle: Individual workload instance management with sidecar agents
- π gRPC Operations: Manages gRPC-based operations between units
- π‘οΈ High Availability: Built-in replication and failover mechanisms
- π Scaling: Horizontal and vertical scaling capabilities
- π Lifecycle Management: Automated backup, recovery, and upgrades
- βοΈ Configuration Management: Template-based configuration with shared configs
- π Monitoring: Integrated metrics and health checks
- π Security: Certificate management and secure credential handling
- π§© Compose Operator Integration: Optional integration with Compose Operator for database replication/topologies (MySQL, Redis, PostgreSQL, ProxySQL)
ποΈ Architecture
The Unit Operator follows a two-layer architecture:
βββββββββββββββββββββββββββββββββββββββ
β UnitSet β
β (Cluster Manager) β
βββββββββββββββββββββββββββββββββββββββ€
β βββββββββββββββ βββββββββββββββ β
β β Unit-0 β β Unit-1 β β
β β (Pod+Agent) β β (Pod+Agent) β β
β βββββββββββββββ βββββββββββββββ β
β β
β βββββββββββββββ βββββββββββββββ β
β β Unit-2 β β ... β β
β β (Pod+Agent) β β β β
β βββββββββββββββ βββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββ
- π― UnitSet: Manages a set of distributed units with shared configuration
- π¦ Unit: Individual workload instances with sidecar agents for advanced operations
- π GrpcCall: Manages gRPC-based operations between units
- π€ Agent: Sidecar container providing unit-specific operations and configuration management
π Prerequisites
- βΈοΈ Kubernetes: v1.27+ or OpenShift v4.6+
- πΉ Go: 1.24+ (for development)
- β Helm: 3.0+ (for deployment)
π Quick Start
π¦ Installation
- Install using Helm:
# Add the Helm repository
helm repo add upm-charts https://upmio.github.io/helm-charts
# Install the operator
helm install unit-operator --namespace upm-system --create-namespace \
--set crd.enabled=true \
upm-charts/unit-operator
-
(Optional) Install Compose Operator (for database replication/topologies):
- Repository and docs:
https://github.com/upmio/compose-operator
- Unit Operator runs independently; install Compose Operator only if you need MySQL/Redis/PostgreSQL/ProxySQL replication/cluster topologies.
-
Install CRDs manually (recommended for production):
kubectl apply -f config/crd/bases/
π³ Example: Deploy UnitSet with gRPC Communication
# Create shared configuration
apiVersion: v1
kind: ConfigMap
metadata:
name: unitset-config
namespace: default
data:
service_group_uid: "6fa3ca2a-0ffd-4ca7-8615-e2589f7dd413"
mysql_ports: '[{"name": "grpc", "containerPort": "50051","protocol": "TCP"}]'
# Deploy UnitSet
apiVersion: upm.syntropycloud.io/v1alpha2
kind: UnitSet
metadata:
name: example-unitset
namespace: default
spec:
type: mysql
version: "1.0.0"
units: 3
sharedConfigName: unitset-config
resources:
limits:
cpu: "1"
memory: 2Gi
requests:
cpu: "500m"
memory: 1Gi
storages:
- name: data
mountPath: /DATA_MOUNT
size: 10Gi
storageClassName: standard
env:
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
π Example: Create gRPC Call
apiVersion: upm.syntropycloud.io/v1alpha1
kind: GrpcCall
metadata:
name: example-grpc-call
namespace: default
spec:
targetUnit: "example-unitset-0"
type: mysql
action: set-variable
ttlSecondsAfterFinished: 600
parameters:
variables:
ping: "true"
β
Verify Deployment
# Check UnitSet status
kubectl get unitset example-unitset
# Check individual units
kubectl get units
# Check pod status
kubectl get pods -l app=example-unitset
βοΈ Configuration
π― Supported Resource Types
Resource |
π API Version |
π Description |
UnitSet |
v1alpha2 |
Manages a set of distributed units |
Unit |
v1alpha2 |
Individual workload instances |
GrpcCall |
v1alpha1 |
Manages gRPC-based operations |
π gRPC Communication
The operator supports gRPC communication between units:
- Service discovery and registration
- Health checks and monitoring
- Configuration synchronization
- Cross-unit communication
πΎ Storage Configuration
# Persistent storage
storages:
- name: data
mountPath: /DATA_MOUNT
size: 10Gi
storageClassName: standard
# Temporary storage
emptyDir:
- name: temp
mountPath: /TEMP_MOUNT
size: 1Gi
π Update Strategy
updateStrategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 1
partition: 0
π» Development
π οΈ Setup Development Environment
# Clone the repository
git clone https://github.com/upmio/unit-operator.git
cd unit-operator
# Install dependencies
go mod download
# Install required tools
make kustomize controller-gen envtest
# Optional (recommended for packaging/linting)
make operator-sdk golangci-lint
ποΈ Build and Run
# Build the operator
make build
# Run locally
make run
# Run tests
make test
# Run with coverage
make check-coverage
π§ Code Generation
# Generate CRDs and manifests
make manifests
# Generate deepcopy methods
make generate
# Generate protobuf code
make pb-gen
π API Reference
The Unit Operator provides the following custom resources:
- π― UnitSet: Manages a cluster of database instances
- π¦ Unit: Individual database instance
- π GrpcCall: gRPC-based operations
π§© Compose Operator Integration (optional)
Unit Operator orchestrates workloads around UnitSet/Unit
(Pods, PVCs, Services, rolling upgrades, agent coordination). If you need database replication/topologies, install and use Compose Operator alongside.
- Use
UnitSet
for distributed layout, shared configuration, and lifecycle
- Use Compose Operator CRDs for database replication/cluster topologies, for example:
- MysqlReplication: MySQL async/semi-sync/Group Replication
- PostgresReplication: PostgreSQL streaming replication
- RedisReplication / RedisCluster: Redis replication/cluster
- ProxySQLSync: ProxySQL administration and synchronization
- Use
GrpcCall
for agent-driven operational tasks across units
Note: Unit Operator works independently; install Compose Operator only if you need these replication capabilities.
π Compose Operator password encryption example (optional)
When using Compose Operator database CRDs, credentials must be AES-256-CTR encrypted and stored in Secrets. Example workflow below (commands from the Compose Operator docs; build the tool in its repository):
# Build the encryption tool in the compose-operator repository
go build -o aes-tool ./tool/
# Get the AES key generated by compose-operator (replace namespace/release accordingly)
AES_KEY=$(kubectl get secret compose-operator-aes-secret -n upm-system -o jsonpath='{.data.AES_SECRET_KEY}' | base64 -d)
# MySQL example
aes-tool -key "$AES_KEY" -plaintext "mysql_root_password" -username "mysql"
aes-tool -key "$AES_KEY" -plaintext "replication_password" -username "replication"
kubectl create secret generic mysql-credentials \
--from-file=mysql=mysql.bin \
--from-file=replication=replication.bin
# Redis example
aes-tool -key "$AES_KEY" -plaintext "redis_auth_password" -username "redis"
kubectl create secret generic redis-credentials \
--from-file=redis=redis.bin
# PostgreSQL example
aes-tool -key "$AES_KEY" -plaintext "postgresql_admin_password" -username "postgresql"
aes-tool -key "$AES_KEY" -plaintext "replication_password" -username "replication"
kubectl create secret generic postgres-credentials \
--from-file=postgresql=postgresql.bin \
--from-file=replication=replication.bin
# ProxySQL example
aes-tool -key "$AES_KEY" -plaintext "proxysql_admin_password" -username "proxysql"
aes-tool -key "$AES_KEY" -plaintext "mysql_backend_password" -username "mysql"
kubectl create secret generic proxysql-credentials \
--from-file=proxysql=proxysql.bin \
--from-file=mysql=mysql.bin
Note: The capabilities and tooling above come from the Compose Operator project. Refer to its latest documentation: https://github.com/upmio/compose-operator
.
π Monitoring
The operator exposes metrics on port 20154
by default:
# Access metrics
kubectl port-forward -n upm-system svc/unit-operator-metrics 20154:20154
curl http://localhost:20154/metrics
Monitor your database clusters with built-in metrics
π¨ Troubleshooting
β οΈ Common Issues
-
Pods stuck in Pending state
- Check resource requests/limits
- Verify storage class availability
- Ensure sufficient cluster resources
-
Replication not working
- Verify network connectivity between pods
- Check credential secrets
- Review replication configuration
-
Upgrade failures
- Check operator logs for errors
- Verify upgrade strategy configuration
- Ensure sufficient disk space
π Debug Commands
# Check operator logs
kubectl logs -n upm-system deployment/unit-operator
# Check UnitSet events
kubectl describe unitset <name>
# Check individual Unit status
kubectl describe unit <name>
# Check agent logs
kubectl logs <pod-name> -c agent
π€ Contributing
We welcome contributions! Please see our CONTRIBUTING.md for details.
π Development Workflow
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Run linting and tests
- Submit a pull request
π¨ Code Style
- Follow Go standard formatting
- Use
make fmt
and make vet
before committing
- Ensure tests pass with
make test
- Maintain test coverage above threshold
π License
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
π Support
π Acknowledgments
Built with β€οΈ using these amazing tools and frameworks
Made with β€οΈ by the Unit Operator community