Deploy to Kubernetes (20 Minutes)
Deploy to Kubernetes (20 Minutes)
Deploy your OSSA agents and workflows to a production Kubernetes cluster.
Prerequisites
- Kubernetes cluster with kubectl access
- Helm 3.13+ installed
- Docker registry access
- Completed Build Workflow Tutorial
Quick Deploy (One Command)
# Clone agent-buildkit git clone https://gitlab.com/agentstudio/agent-buildkit.git cd agent-buildkit # Deploy everything to Kubernetes npm run deploy:k8s deploy -n agents # Done! All agents and workflows deployed.
Step-by-Step Deployment
Step 1: Create Namespace (30 seconds)
# Create namespace for agents kubectl create namespace agents # Label namespace kubectl label namespace agents environment=production
Step 2: Configure Secrets (2 minutes)
# GitLab OAuth credentials kubectl create secret generic gitlab-oauth-secret \ --from-literal=client-id=$GITLAB_OAUTH_CLIENT_ID \ --from-literal=client-secret=$GITLAB_OAUTH_CLIENT_SECRET \ --namespace agents # GitLab API token kubectl create secret generic gitlab-api-token \ --from-literal=token=$(cat ~/.tokens/gitlab) \ --namespace agents
Step 3: Build and Push Agent Images (5 minutes)
Build Docker image for your agent:
cd ~/Sites/LLM/my-agents/code-quality-governor # Create Dockerfile cat > Dockerfile <<'EOF' FROM node:20-alpine WORKDIR /app COPY package*.json ./ RUN npm ci --only=production COPY dist/ ./dist/ COPY agent.ossa.yaml ./ EXPOSE 3000 CMD ["node", "dist/index.js"] EOF # Build image docker build -t yourregistry.com/code-quality-governor:1.0.0 . # Push to registry docker push yourregistry.com/code-quality-governor:1.0.0
Step 4: Deploy Agent with BuildKit (3 minutes)
# Deploy using BuildKit CLI buildkit agents deploy code-quality-governor \ --namespace agents \ --image yourregistry.com/code-quality-governor:1.0.0 \ --replicas 2 # Verify deployment kubectl get pods -n agents -l app=code-quality-governor # Expected output: # NAME READY STATUS RESTARTS AGE # code-quality-governor-5f7d9c8b6-abc12 1/1 Running 0 30s # code-quality-governor-5f7d9c8b6-def34 1/1 Running 0 30s
Step 5: Deploy with Helm Chart (Alternative) (5 minutes)
# Use BuildKit Helm chart cd agent-buildkit # Install chart helm install agent-buildkit charts/agents \ --namespace agents \ --set gitlab.oauthClientId=$GITLAB_OAUTH_CLIENT_ID \ --set gitlab.oauthClientSecret=$GITLAB_OAUTH_CLIENT_SECRET \ --set ingress.enabled=true \ --set ingress.host=agents.yourcompany.com # Check deployment status helm status agent-buildkit -n agents
Step 6: Configure Ingress (3 minutes)
Create ingress for agents:
# agents-ingress.yaml apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: agents-ingress namespace: agents annotations: cert-manager.io/cluster-issuer: letsencrypt-prod spec: ingressClassName: nginx tls: - hosts: - agents.yourcompany.com secretName: agents-tls rules: - host: agents.yourcompany.com http: paths: - path: / pathType: Prefix backend: service: name: agent-buildkit port: number: 80
kubectl apply -f agents-ingress.yaml # Wait for SSL certificate kubectl get certificate -n agents agents-tls
Step 7: Deploy Workflow (2 minutes)
# Register workflow with Kubernetes backend buildkit workflows register workflow.yaml \ --runtime kubernetes \ --namespace agents # Verify workflow is registered buildkit workflows list
Step 8: Verify Deployment (2 minutes)
# Check all pods are running kubectl get pods -n agents # Check services kubectl get svc -n agents # Check ingress kubectl get ingress -n agents # Test agent health curl https://agents.yourcompany.com/health # Expected response: # {"status":"ok","agents":[{"id":"code-quality-governor","status":"running"}]}
Step 9: Configure Auto-Scaling (2 minutes)
# hpa.yaml - Horizontal Pod Autoscaler apiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler metadata: name: code-quality-governor-hpa namespace: agents spec: scaleTargetRef: apiVersion: apps/v1 kind: Deployment name: code-quality-governor minReplicas: 2 maxReplicas: 10 metrics: - type: Resource resource: name: cpu target: type: Utilization averageUtilization: 70 - type: Resource resource: name: memory target: type: Utilization averageUtilization: 80
kubectl apply -f hpa.yaml # Verify HPA kubectl get hpa -n agents
Step 10: Test End-to-End (1 minute)
# Trigger workflow from GitLab cd ~/Sites/LLM/test-project git commit --allow-empty -m "test: trigger K8s workflow" git push # Watch workflow execution buildkit workflows watch code-review-workflow # Check agent logs in Kubernetes kubectl logs -n agents -l app=code-quality-governor --follow
Monitoring Deployment
# Get pod metrics kubectl top pods -n agents # View agent logs kubectl logs -n agents -l ossa-agent=true --tail=100 # Describe problematic pod kubectl describe pod <pod-name> -n agents # Get events kubectl get events -n agents --sort-by='.lastTimestamp'
Update Deployed Agent
# Build new image version docker build -t yourregistry.com/code-quality-governor:1.1.0 . docker push yourregistry.com/code-quality-governor:1.1.0 # Update deployment kubectl set image deployment/code-quality-governor \ code-quality-governor=yourregistry.com/code-quality-governor:1.1.0 \ -n agents # Watch rollout kubectl rollout status deployment/code-quality-governor -n agents # Rollback if needed kubectl rollout undo deployment/code-quality-governor -n agents
Troubleshooting
Pods not starting:
# Check pod status kubectl get pods -n agents # Check logs kubectl logs <pod-name> -n agents # Describe pod for events kubectl describe pod <pod-name> -n agents
Image pull errors:
# Create registry credentials secret kubectl create secret docker-registry registry-credentials \ --docker-server=yourregistry.com \ --docker-username=your-username \ --docker-password=your-password \ --namespace agents # Update deployment to use secret kubectl patch deployment code-quality-governor -n agents -p ' { "spec": { "template": { "spec": { "imagePullSecrets": [{"name": "registry-credentials"}] } } } }'
SSL certificate not issuing:
# Check cert-manager logs kubectl logs -n cert-manager deployment/cert-manager # Check certificate status kubectl describe certificate agents-tls -n agents # Check challenge kubectl get challenge -n agents
What's Next?
- Production setup: Production Deployment Guide
- Observability: Observability Guide
- Scaling strategies: Learn auto-scaling and load balancing
Time to complete: 20 minutes Next: Production Deployment