|
| 1 | +# Service Quality Oracle - Kubernetes Deployment |
| 2 | + |
| 3 | +This directory contains Kubernetes manifests for deploying the Service Quality Oracle with persistent state management. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +- Kubernetes cluster (version 1.19+) |
| 8 | +- `kubectl` configured to access your cluster |
| 9 | +- Docker image published to `ghcr.io/graphprotocol/service-quality-oracle` |
| 10 | +- **Storage class configured** (see Storage Configuration below) |
| 11 | + |
| 12 | +## Quick Start |
| 13 | + |
| 14 | +### 1. Create Secrets (Required) |
| 15 | + |
| 16 | +```bash |
| 17 | +# Copy the example secrets file |
| 18 | +cp k8s/secrets.yaml.example k8s/secrets.yaml |
| 19 | + |
| 20 | +# Edit with your actual credentials |
| 21 | +# IMPORTANT: Never commit secrets.yaml to version control |
| 22 | +nano k8s/secrets.yaml |
| 23 | +``` |
| 24 | + |
| 25 | +**Required secrets:** |
| 26 | +- **`google-credentials`**: Service account JSON for BigQuery access |
| 27 | +- **`blockchain-private-key`**: Private key for Arbitrum Sepolia transactions |
| 28 | +- **`arbitrum-api-key`**: API key for Arbiscan contract verification |
| 29 | +- **`slack-webhook-url`**: Webhook URL for operational notifications |
| 30 | + |
| 31 | +### 2. Configure Storage (Required) |
| 32 | + |
| 33 | +```bash |
| 34 | +# Check available storage classes |
| 35 | +kubectl get storageclass |
| 36 | + |
| 37 | +# If you see a default storage class (marked with *), skip to step 3 |
| 38 | +# Otherwise, edit persistent-volume-claim.yaml and uncomment the appropriate storageClassName |
| 39 | +``` |
| 40 | + |
| 41 | +**Common storage classes by platform:** |
| 42 | +- **AWS EKS**: `gp2`, `gp3`, `ebs-csi` |
| 43 | +- **Google GKE**: `standard`, `ssd` |
| 44 | +- **Azure AKS**: `managed-premium`, `managed` |
| 45 | +- **Local/Development**: `hostpath`, `local-path` |
| 46 | + |
| 47 | +### 3. Deploy to Kubernetes |
| 48 | + |
| 49 | +```bash |
| 50 | +# Apply all manifests |
| 51 | +kubectl apply -f k8s/ |
| 52 | + |
| 53 | +# Verify deployment |
| 54 | +kubectl get pods -l app=service-quality-oracle |
| 55 | +kubectl get pvc -l app=service-quality-oracle |
| 56 | +``` |
| 57 | + |
| 58 | +### 4. Monitor Deployment |
| 59 | + |
| 60 | +```bash |
| 61 | +# Check pod status |
| 62 | +kubectl describe pod -l app=service-quality-oracle |
| 63 | + |
| 64 | +# View logs |
| 65 | +kubectl logs -l app=service-quality-oracle -f |
| 66 | + |
| 67 | +# Check persistent volumes |
| 68 | +kubectl get pv |
| 69 | +``` |
| 70 | + |
| 71 | +## Architecture |
| 72 | + |
| 73 | +### Persistent Storage |
| 74 | + |
| 75 | +The service uses **two persistent volumes** to maintain state across pod restarts: |
| 76 | + |
| 77 | +- **`service-quality-oracle-data` (5GB)**: Circuit breaker state, last run tracking, BigQuery cache, CSV outputs |
| 78 | +- **`service-quality-oracle-logs` (2GB)**: Application logs |
| 79 | + |
| 80 | +**Mount points:** |
| 81 | +- `/app/data` → Critical state files (circuit breaker, cache, outputs) |
| 82 | +- `/app/logs` → Application logs |
| 83 | + |
| 84 | +### Configuration Management |
| 85 | + |
| 86 | +**Non-sensitive configuration** → `ConfigMap` (`configmap.yaml`) |
| 87 | +**Sensitive credentials** → `Secret` (`secrets.yaml`) |
| 88 | + |
| 89 | +This separation provides: |
| 90 | +- ✅ Easy configuration updates without rebuilding images |
| 91 | +- ✅ Secure credential management with base64 encoding |
| 92 | +- ✅ Clear separation of concerns |
| 93 | + |
| 94 | +### Resource Allocation |
| 95 | + |
| 96 | +**Requests (guaranteed):** |
| 97 | +- CPU: 250m (0.25 cores) |
| 98 | +- Memory: 512M |
| 99 | + |
| 100 | +**Limits (maximum):** |
| 101 | +- CPU: 1000m (1.0 core) |
| 102 | +- Memory: 1G |
| 103 | + |
| 104 | +## State Persistence Benefits |
| 105 | + |
| 106 | +With persistent volumes, the service maintains: |
| 107 | + |
| 108 | +1. **Circuit breaker state** → Prevents infinite restart loops |
| 109 | +2. **Last run tracking** → Enables proper catch-up logic |
| 110 | +3. **BigQuery cache** → Dramatic performance improvement (30s vs 5min restarts) |
| 111 | +4. **CSV audit artifacts** → Regulatory compliance and debugging |
| 112 | + |
| 113 | +## Health Checks |
| 114 | + |
| 115 | +The deployment uses **file-based health checks** (same as docker-compose): |
| 116 | + |
| 117 | +**Liveness probe:** Checks `/app/healthcheck` file modification time |
| 118 | +**Readiness probe:** Verifies `/app/healthcheck` file exists |
| 119 | + |
| 120 | +## Troubleshooting |
| 121 | + |
| 122 | +### Pod Won't Start |
| 123 | + |
| 124 | +```bash |
| 125 | +# Check events |
| 126 | +kubectl describe pod -l app=service-quality-oracle |
| 127 | + |
| 128 | +# Common issues: |
| 129 | +# - Missing secrets |
| 130 | +# - PVC provisioning failures |
| 131 | +# - Image pull errors |
| 132 | +``` |
| 133 | + |
| 134 | +### Check Persistent Storage |
| 135 | + |
| 136 | +```bash |
| 137 | +# Verify PVCs are bound |
| 138 | +kubectl get pvc |
| 139 | + |
| 140 | +# Check if volumes are mounted correctly |
| 141 | +kubectl exec -it deployment/service-quality-oracle -- ls -la /app/data |
| 142 | +``` |
| 143 | + |
| 144 | +### Debug Configuration |
| 145 | + |
| 146 | +```bash |
| 147 | +# Check environment variables |
| 148 | +kubectl exec -it deployment/service-quality-oracle -- env | grep -E "(BIGQUERY|BLOCKCHAIN)" |
| 149 | + |
| 150 | +# Verify secrets are mounted |
| 151 | +kubectl exec -it deployment/service-quality-oracle -- ls -la /etc/secrets |
| 152 | +``` |
| 153 | + |
| 154 | +## Security Best Practices |
| 155 | + |
| 156 | +✅ **Secrets never committed** to version control |
| 157 | +✅ **Service account** with minimal BigQuery permissions |
| 158 | +✅ **Private key** stored in Kubernetes secrets (base64 encoded) |
| 159 | +✅ **Resource limits** prevent resource exhaustion |
| 160 | +✅ **Read-only filesystem** where possible |
| 161 | + |
| 162 | +## Production Considerations |
| 163 | + |
| 164 | +- **Backup strategy** for persistent volumes |
| 165 | +- **Monitoring** and alerting setup |
| 166 | +- **Log aggregation** (ELK stack, etc.) |
| 167 | +- **Network policies** for additional security |
| 168 | +- **Pod disruption budgets** for maintenance |
| 169 | +- **Horizontal Pod Autoscaler** (if needed for scaling) |
| 170 | + |
| 171 | +## Next Steps |
| 172 | + |
| 173 | +1. **Test deployment** in staging environment |
| 174 | +2. **Verify state persistence** across pod restarts |
| 175 | +3. **Set up monitoring** and alerting |
| 176 | +4. **Configure backup** for persistent volumes |
| 177 | +5. **Enable quality checking** after successful validation |
0 commit comments