# Required tools
kubectl version --client # v1.20+
docker --version # 17.03+
go version # 1.21+ (for development)# Clone and navigate
git clone <repository>
cd amazonq-golang-restfulapi-operator
# Deploy operator
./deploy.sh# Apply sample
kubectl apply -f config/samples/apps_v1_restapi.yaml
# Check status
kubectl get restapi
kubectl get pods# Check cluster connection
kubectl cluster-info
# Verify permissions
kubectl auth can-i create customresourcedefinitions# Install CRDs
make install
# Deploy operator
make deploy
# Verify operator is running
kubectl get pods -n amazonq-golang-restfulapi-operator-systemCreate my-restapi.yaml:
apiVersion: apps.aws.com/v1
kind: RestAPI
metadata:
name: my-app
spec:
image: "nginx:1.21"
replicas: 2
model:
enabled: true
image: "myapp/model:v1"
port: 8080
view:
enabled: true
image: "myapp/view:v1"
port: 3000
controller:
enabled: true
image: "myapp/controller:v1"
port: 8081
repository:
enabled: true
image: "myapp/repository:v1"
port: 8082# Deploy
kubectl apply -f my-restapi.yaml
# Monitor deployment
kubectl get restapi my-app -w
# Check created resources
kubectl get deployments,services,pods -l app=my-appspec:
autoScaling:
enabled: true
minReplicas: 2
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: 300spec:
envVars:
DATABASE_URL: "postgresql://db:5432/myapp"
REDIS_URL: "redis://cache:6379"
LOG_LEVEL: "info"
model:
enabled: true
envVars:
DB_POOL_SIZE: "20"
CACHE_TTL: "300"spec:
model:
enabled: true
image: "myapp/model:v2.0.0"
port: 8080
resources:
requests:
memory: "256Mi"
cpu: "250m"
limits:
memory: "512Mi"
cpu: "500m"# Scale specific component
kubectl patch restapi my-app --type='merge' -p='{"spec":{"replicas":5}}'
# Enable/disable components
kubectl patch restapi my-app --type='merge' -p='{"spec":{"view":{"enabled":false}}}'# Check RestAPI status
kubectl describe restapi my-app
# View operator logs
kubectl logs -f deployment/amazonq-golang-restfulapi-operator-controller-manager -n amazonq-golang-restfulapi-operator-system
# Check component health
kubectl get pods -l app=my-app
kubectl describe pod <pod-name># Check current environment
kubectl get restapi my-app -o jsonpath='{.status.activeEnvironment}'
# Manual promotion (if strategy is manual)
kubectl patch restapi my-app --type='merge' -p='{"spec":{"blueGreen":{"promote":true}}}'# Check all components health
kubectl get pods -l app=my-app -o wide
# Test health endpoints
kubectl port-forward svc/my-app-model-svc 8080:8080
curl http://localhost:8080/health# Check HPA status
kubectl get hpa -l app=my-app
# View scaling events
kubectl describe hpa my-app-model-hpa# List all services
kubectl get svc -l app=my-app
# Test service connectivity
kubectl run test-pod --image=curlimages/curl -it --rm -- sh
# Inside pod: curl http://my-app-model-svc:8080/health# Check operator logs
kubectl logs -f deployment/amazonq-golang-restfulapi-operator-controller-manager -n amazonq-golang-restfulapi-operator-system
# Verify CRDs installed
kubectl get crd restapis.apps.aws.com# Check RestAPI status
kubectl describe restapi my-app
# Verify images exist
docker pull myapp/model:v1
# Check resource constraints
kubectl describe nodes# Check probe configuration
kubectl describe pod <pod-name>
# Test health endpoint manually
kubectl exec -it <pod-name> -- curl localhost:8080/healthspec:
autoScaling:
enabled: true
minReplicas: 3 # Higher minimum for stability
maxReplicas: 20 # Higher maximum for peak loads
targetCPUUtilization: 60 # Lower threshold for faster scalingspec:
model:
resources:
requests:
memory: "512Mi" # Higher requests for guaranteed resources
cpu: "500m"
limits:
memory: "1Gi" # Reasonable limits
cpu: "1000m"# Update component image
kubectl patch restapi my-app --type='merge' -p='{"spec":{"model":{"image":"myapp/model:v2.0.0"}}}'
# Rolling update with blue-green
kubectl patch restapi my-app --type='merge' -p='{"spec":{"blueGreen":{"enabled":true}}}'# Backup RestAPI configuration
kubectl get restapi my-app -o yaml > my-app-backup.yaml
# Restore from backup
kubectl apply -f my-app-backup.yaml# Delete RestAPI (cascades to all components)
kubectl delete restapi my-app
# Uninstall operator
make undeploy
make uninstall# Production
apiVersion: apps.aws.com/v1
kind: RestAPI
metadata:
name: my-app-prod
namespace: production
spec:
replicas: 5
autoScaling:
enabled: true
minReplicas: 5
maxReplicas: 50
blueGreen:
enabled: true
strategy: "manual"
---
# Staging
apiVersion: apps.aws.com/v1
kind: RestAPI
metadata:
name: my-app-staging
namespace: staging
spec:
replicas: 2
autoScaling:
enabled: true
minReplicas: 1
maxReplicas: 10# User Service
apiVersion: apps.aws.com/v1
kind: RestAPI
metadata:
name: user-service
spec:
model:
enabled: true
image: "microservices/user-model:v1"
repository:
enabled: true
image: "microservices/user-repo:v1"
# Disable view and controller for API-only service
view:
enabled: false
controller:
enabled: false- Resource Planning: Always set resource requests/limits
- Health Checks: Implement proper health endpoints
- Environment Variables: Use ConfigMaps/Secrets for sensitive data
- Monitoring: Enable metrics and logging
- Testing: Test blue-green deployments in staging first
- Backup: Regular backup of RestAPI configurations
- Security: Use least-privilege RBAC policies
- Logs:
kubectl logs -f deployment/amazonq-golang-restfulapi-operator-controller-manager -n amazonq-golang-restfulapi-operator-system - Status:
kubectl describe restapi <name> - Events:
kubectl get events --sort-by=.metadata.creationTimestamp