Intelligent Kubernetes deployment orchestrator with manifest generation and CI/CD integration
<codex_skill_adapter>
$ops-deploy-deploy.$ops-deploy-deploy as {{SC_ARGS}}.{{SC_ARGS}} as empty.spawn_agent(...) patterns to Codex spawn_agent(...).update_plan.config.toml when the original command mentions MCP.ops:deploy:deploy.$ops-deploy-deploy.STEP 1: Initialize intelligent deployment session with comprehensive project analysis
/tmp/deploy-session-$SESSION_ID.json# Initialize deployment session state
echo '{
"sessionId": "'$SESSION_ID'",
"targetApp": "'{{SC_ARGS}}'",
"deploymentStrategy": "auto-detect",
"environment": "staging",
"manifestsGenerated": [],
"deploymentStatus": "initialized"
}' > /tmp/deploy-session-$SESSION_ID.json
STEP 2: Adaptive deployment strategy selection with intelligent pattern detection
TRY:
CASE deployment_pattern: WHEN "existing_kustomize":
kubectl dry-runWHEN "existing_helm":
helm template and helm lintWHEN "generate_new_manifests":
STEP 3: Parallel manifest generation using sub-agent architecture
IF no_existing_deployment_config OR generate_new_requested:
LAUNCH parallel sub-agents for comprehensive Kubernetes deployment setup:
Agent 1: Core Manifests Generation: Create Deployment, Service, and Ingress manifests
Agent 2: Kustomize Structure Setup: Create Kustomize base and overlay structure
Agent 3: Secret Management: Generate secure secret templates and management scripts
Agent 4: Monitoring & Observability: Setup Prometheus metrics and logging configurations
Agent 5: CI/CD Integration: Generate GitHub Actions workflows for automated deployment
Agent 6: Security Hardening: Implement Pod Security Standards and network policies
Sub-Agent Coordination:
# Each agent reports findings to session state
echo "Parallel manifest generation agents launched..."
echo "Coordinating deployment artifact creation across security, observability, and automation"
STEP 4: Environment-specific configuration and deployment execution
Environment Detection and Configuration:
# Parse deployment target from arguments
target_env=$(echo "{{SC_ARGS}}" | rg "--to (\w+)" -o -r '$1' || echo "staging")
tag=$(echo "{{SC_ARGS}}" | rg "--tag ([\w\.-]+)" -o -r '$1' || git rev-parse --short HEAD)
echo "🎯 Deployment Target: $target_env"
echo "🏷️ Image Tag: $tag"
# Environment-specific resource configuration
case $target_env in
"production")
replicas=3
resources_requests_cpu="500m"
resources_requests_memory="512Mi"
resources_limits_cpu="1000m"
resources_limits_memory="1Gi"
monitoring_enabled=true
;;
"staging")
replicas=2
resources_requests_cpu="250m"
resources_requests_memory="256Mi"
resources_limits_cpu="500m"
resources_limits_memory="512Mi"
monitoring_enabled=true
;;
"development")
replicas=1
resources_requests_cpu="100m"
resources_requests_memory="128Mi"
resources_limits_cpu="250m"
resources_limits_memory="256Mi"
monitoring_enabled=false
;;
esac
Deployment Execution with Validation:
# Validate cluster connectivity
kubectl cluster-info --request-timeout=5s
# Apply manifests with validation
IF kustomize_detected:
kubectl apply -k k8s/overlays/$target_env --dry-run=client
kubectl apply -k k8s/overlays/$target_env
ELSE IF helm_detected:
helm upgrade --install $app_name ./helm-chart \
--set image.tag=$tag \
--set environment=$target_env \
--namespace $target_env \
--create-namespace \
--dry-run
helm upgrade --install $app_name ./helm-chart \
--set image.tag=$tag \
--set environment=$target_env \
--namespace $target_env \
--create-namespace
ELSE:
kubectl apply -f k8s/ --dry-run=client
kubectl apply -f k8s/
STEP 5: Post-deployment validation and monitoring setup
TRY:
Deployment Status Verification:
# Wait for deployment rollout
kubectl rollout status deployment/$app_name -n $target_env --timeout=300s
# Verify pod health
kubectl get pods -n $target_env -l app=$app_name -o json | \
jq -r '.items[] | select(.status.phase != "Running") | .metadata.name' | \
while read pod; do
echo "⚠️ Pod $pod not running"
kubectl describe pod $pod -n $target_env
done
# Check service endpoints
kubectl get endpoints -n $target_env -l app=$app_name
# Verify ingress configuration
kubectl get ingress -n $target_env -o json | \
jq -r '.items[] | .spec.rules[] | .host'
Health Check and Service Verification:
# Test service connectivity
service_ip=$(kubectl get svc $app_name -n $target_env -o jsonpath='{.spec.clusterIP}')
echo "🔍 Testing service connectivity: $service_ip"
# Port forward for local testing (if needed)
echo "💡 For local testing, run:"
echo "kubectl port-forward svc/$app_name -n $target_env 8080:80"
# Generate monitoring dashboard links
echo "📊 Monitoring dashboards:"
echo " Grafana: https://grafana.yourdomain.com/d/kubernetes-app"
echo " Prometheus: https://prometheus.yourdomain.com/graph"
CATCH (deployment_failed):
echo "❌ Deployment failed. Providing rollback options:"
echo "kubectl rollout undo deployment/$app_name -n $target_env"
echo "kubectl get events -n $target_env --sort-by=.metadata.creationTimestamp"
echo "kubectl logs -l app=$app_name -n $target_env --tail=50"
STEP 6: Session state management and deployment documentation
Update Deployment Session:
# Update session state with deployment results
jq --arg status "deployed" --arg env "$target_env" --arg tag "$tag" '
.deploymentStatus = $status |
.environment = $env |
.imageTag = $tag |
.deployedAt = now
' /tmp/deploy-session-$SESSION_ID.json > /tmp/deploy-session-$SESSION_ID.tmp && \
mv /tmp/deploy-session-$SESSION_ID.tmp /tmp/deploy-session-$SESSION_ID.json
Generate Deployment Summary:
echo "✅ Deployment completed successfully"
echo "🎯 Application: {{SC_ARGS}}"
echo "🌍 Environment: $target_env"
echo "🏷️ Image Tag: $tag"
echo "📁 Manifests: $(ls k8s/*.yaml 2>/dev/null | wc -l | tr -d ' ') files generated"
echo "⏱️ Session: $SESSION_ID"
echo "💾 Session state: /tmp/deploy-session-$SESSION_ID.json"
FINALLY:
Base Configuration:
k8s/base/deployment.yaml - Core deployment specificationk8s/base/service.yaml - Service definitionk8s/base/kustomization.yaml - Base Kustomize configurationEnvironment Overlays:
k8s/overlays/staging/ - Staging-specific patchesk8s/overlays/production/ - Production-specific patchesk8s/overlays/development/ - Development-specific patchesChart Structure:
Chart.yaml - Helm chart metadatavalues.yaml - Default configuration valuestemplates/ - Kubernetes manifest templatesvalues-staging.yaml - Staging environment valuesvalues-production.yaml - Production environment valuesSimple Structure:
k8s/deployment.yaml - Kubernetes Deploymentk8s/service.yaml - Kubernetes Servicek8s/ingress.yaml - Ingress configurationk8s/configmap.yaml - Application configurationk8s/secret-template.yaml - Secret templatesecurityContext:
runAsNonRoot: true
runAsUser: 65534
fsGroup: 65534
seccompProfile:
type: RuntimeDefault
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities:
drop:
- ALL
Production Environment:
Staging Environment:
Development Environment: