| name | kubernetes |
| description | Kubernetes operations, testing, and validation. Use when working with Kubernetes clusters for deploying resources, verifying deployments, testing operators/CRDs, debugging pods, monitoring workloads, or performing end-to-end testing and validation of K8s applications. |
Kubernetes Operations and Testing
Overview
This skill provides comprehensive Kubernetes operations and testing capabilities for both standard K8s resources and custom operators with CRDs. It includes automation scripts for deployment verification, pod debugging, testing workflows, and detailed kubectl command references. Use this skill for any K8s-related deployment, testing, or troubleshooting tasks.
Project Context:
- Custom Kubernetes Operator: ARL-Infra (Agentic RL Infrastructure)
- Custom CRDs: WarmPool, Sandbox, Task
- Python tooling: Managed with
uv (PyYAML installed)
- Deployment targets: Minikube (local) and standard K8s clusters
Quick Start
Deploy and Verify Operator
make docker-build && helm upgrade --install arl-operator charts/arl-operator \
--namespace arl --create-namespace --set crds.install=true --wait
REGISTRY=your-registry.com make k8s-build-push && \
helm upgrade --install arl-operator charts/arl-operator \
--namespace arl --create-namespace \
--set crds.install=true \
--set image.repository=your-registry.com/arl-operator \
--set sidecar.image.repository=your-registry.com/arl-sidecar \
--wait
kubectl get pods -n arl
kubectl get crds | grep arl.infra.io
Deploy Custom Resources
kubectl apply -f config/samples/
kubectl get warmpools,sandboxes,tasks
kubectl get warmpool python-3.9-std -o jsonpath='{.status.phase}'
Deploy and Verify Standard Resources
kubectl apply -f <file.yaml>
uv run python scripts/verify_deployment.py <deployment-name> <namespace>
scripts/wait_for_pod.sh <namespace> <pod-pattern> 300
Debug Issues
scripts/debug_pod.sh <namespace> <pod-name>
kubectl logs -n arl -l app=arl-operator --tail=100 -f
kubectl logs <pod-name> -c sidecar
scripts/exec_test.sh <namespace> <pod-pattern> <command>
Core Capabilities
0. Python Tooling with UV
All Python scripts and tools are managed with uv:
uv run python scripts/verify_deployment.py <args>
uv add <package-name>
1. Custom Resource Management
CRD Operations
helm upgrade --install arl-operator charts/arl-operator \
--namespace arl --create-namespace \
--set crds.install=true --wait
kubectl apply -f charts/arl-operator/crds/
kubectl get crds | grep arl.infra.io
kubectl get crd warmpools.arl.infra.io -o yaml
helm uninstall arl-operator -n arl --wait
Working with Custom Resources
WarmPool (Pod Pool Management):
kubectl apply -f config/samples/warmpool.yaml
kubectl get warmpool python-3.9-std
kubectl get warmpool python-3.9-std -o jsonpath='{.status.readyReplicas}'
kubectl get warmpool python-3.9-std -o yaml -w
kubectl get warmpools
Sandbox (Agent Workspace):
kubectl apply -f config/samples/sandbox.yaml
kubectl get sandbox my-agent-workspace -o jsonpath='{.status.phase}'
kubectl get sandbox my-agent-workspace -o jsonpath='{.status.podName}'
kubectl get sandbox my-agent-workspace -o jsonpath='{.status.podIP}'
kubectl get sandboxes
Task (Code Execution):
kubectl apply -f config/samples/task.yaml
kubectl get task my-task -o jsonpath='{.status.state}' -w
kubectl get task my-task -o jsonpath='{.status.exitCode}'
kubectl get task my-task -o jsonpath='{.status.stdout}'
kubectl get task my-task -o jsonpath='{.status.stderr}'
kubectl get tasks
2. Operator Management
make deploy
make k8s-deploy
kubectl get deployment -n arl
kubectl get pods -n arl
make logs
kubectl logs -n arl -l app=arl-operator --tail=100 -f
kubectl rollout restart deployment -n arl
make undeploy
make k8s-undeploy
3. Deployment Verification
Use scripts/verify_deployment.py to automatically verify deployment health:
uv run python scripts/verify_deployment.py <deployment-name> [namespace] [timeout]
uv run python scripts/verify_deployment.py arl-operator arl 300
The script:
- Checks deployment replica status (desired vs ready vs available)
- Verifies all pods are running and healthy
- Validates container readiness
- Waits with timeout for full deployment
- Returns exit code 0 on success, 1 on failure
4. Pod Waiting and Readiness
Use scripts/wait_for_pod.sh to wait for pods to reach Running state:
scripts/wait_for_pod.sh <namespace> <pod-pattern> <timeout-seconds>
scripts/wait_for_pod.sh default "operator" 300
Useful for CI/CD pipelines and sequential testing workflows.
5. Pod Debugging
Use scripts/debug_pod.sh for comprehensive debugging information:
scripts/debug_pod.sh <namespace> <pod-name>
scripts/debug_pod.sh default my-operator-abc123
Collects:
- Pod status and details
- Container logs (current and previous)
- Events related to the pod
- Resource constraints and issues
6. Test Execution
Use scripts/exec_test.sh to run commands in pods for testing:
scripts/exec_test.sh <namespace> <pod-pattern> <command>
scripts/exec_test.sh default "sidecar" curl -f http://localhost:8080/health
scripts/exec_test.sh default "operator" ps aux
Automatically finds the first running pod matching the pattern.
Testing Workflows
Complete Operator Deployment Test (Minikube)
make minikube-start
make docker-build
make deploy
uv run python scripts/verify_deployment.py arl-operator arl 300
make deploy-samples
kubectl get pods -l warmpool=python-3.9-std
kubectl get warmpool python-3.9-std -o jsonpath='{.status.readyReplicas}'
kubectl get sandbox my-agent-workspace -o jsonpath='{.status.phase}'
kubectl get task my-task -o jsonpath='{.status.state}'
kubectl get task my-task -o yaml
make logs
make undeploy
Complete Operator Deployment Test (Standard K8s)
REGISTRY=your-registry.com make k8s-build-push
make k8s-deploy
uv run python scripts/verify_deployment.py arl-operator arl 300
kubectl apply -f config/samples/
kubectl get warmpools,sandboxes,tasks
kubectl logs -n arl -l app=arl-operator --tail=100
make k8s-undeploy
CRD Testing Workflow
kubectl apply --dry-run=client -f charts/arl-operator/crds/arl.infra.io_warmpools.yaml
kubectl apply --dry-run=server -f charts/arl-operator/crds/arl.infra.io_warmpools.yaml
helm upgrade --install arl-operator charts/arl-operator \
--namespace arl --create-namespace --set crds.install=true --wait
kubectl get crds | grep arl.infra.io
kubectl apply -f invalid-resource.yaml
kubectl apply -f config/samples/warmpool.yaml
kubectl get warmpool python-3.9-std -o yaml -w
kubectl logs -n arl -l app=arl-operator | grep "Reconciling WarmPool"
kubectl delete warmpool python-3.9-std
kubectl get pods
Sidecar Communication Testing
POD_NAME=$(kubectl get pods -l warmpool=python-3.9-std -o jsonpath='{.items[0].metadata.name}')
kubectl logs $POD_NAME -c sidecar
kubectl port-forward $POD_NAME 8080:8080 &
curl -X POST http://localhost:8080/files -d '{"path":"/tmp/test.txt","content":"hello"}'
curl -X POST http://localhost:8080/execute -d '{"command":["cat","/tmp/test.txt"]}'
scripts/exec_test.sh default $POD_NAME curl http://localhost:8080/health
State Transition Testing
kubectl get sandbox test-sandbox -o jsonpath='{.status.phase}' -w &
kubectl apply -f - <<EOF
apiVersion: arl.infra.io/v1alpha1
kind: Sandbox
metadata:
name: test-sandbox
spec:
poolRef: python-3.9-std
keepAlive: true
EOF
kubectl get task test-task -o jsonpath='{.status.state}' -w &
kubectl apply -f - <<EOF
apiVersion: arl.infra.io/v1alpha1
kind: Task
metadata:
name: test-task
spec:
sandboxRef: test-sandbox
timeout: 30s
steps:
- name: test_step
type: Command
command: ["echo", "testing"]
EOF
kubectl get task test-task -o jsonpath='{.status.stdout}'
Standard Deployment Test
kubectl apply --dry-run=client -f deployment.yaml
kubectl apply -f deployment.yaml
uv run python scripts/verify_deployment.py my-app default 300
scripts/exec_test.sh default my-app curl http://localhost:8080/health
scripts/debug_pod.sh default <pod-name>
Operator Testing Workflow (Legacy - use CRD Testing Workflow above)
kubectl apply -f config/operator/deployment.yaml
scripts/wait_for_pod.sh default "operator" 120
kubectl apply -f config/samples/resource.yaml
kubectl get <resource-type> <name> -o jsonpath='{.status.phase}' -w
kubectl logs -l app=operator --tail=50 -f
kubectl get <resource-type> <name> -o yaml
Integration Testing
For end-to-end integration tests:
kubectl create namespace test-integration
kubectl apply -f manifests/ -n test-integration
kubectl wait --for=condition=ready pod --all -n test-integration --timeout=300s
scripts/exec_test.sh test-integration app "curl -f http://api-service/test"
kubectl delete namespace test-integration
Advanced Testing Patterns
For detailed testing patterns, see references/testing_patterns.md:
- Pre-deployment validation strategies
- Custom Resource (CRD) testing
- State transition verification
- Performance and load testing
- Network connectivity testing
- Troubleshooting checklist
Kubectl Command Reference
For comprehensive kubectl usage, see references/kubectl_reference.md:
- Essential commands (get, describe, logs, exec)
- Status and monitoring (rollout, top, events)
- Advanced operations (wait, patch, scale)
- Debugging techniques
- Output formatting (jsonpath, custom columns)
- Useful command combinations
Common Scenarios
Working with Custom Resources
Create and Monitor WarmPool
cat <<EOF | kubectl apply -f -
apiVersion: arl.infra.io/v1alpha1
kind: WarmPool
metadata:
name: my-pool
spec:
replicas: 5
template:
spec:
containers:
- name: executor
image: python:3.9-slim
command: ["/bin/sh", "-c", "sleep infinity"]
EOF
watch kubectl get warmpool my-pool -o custom-columns=NAME:.metadata.name,READY:.status.readyReplicas,ALLOCATED:.status.allocatedReplicas
kubectl get pods -l warmpool=my-pool
kubectl patch warmpool my-pool --type='merge' -p '{"spec":{"replicas":10}}'
Debug Sandbox Allocation Issues
kubectl get sandbox my-sandbox
kubectl get warmpool <pool-name> -o jsonpath='{.status.readyReplicas}'
kubectl logs -n arl -l app=arl-operator | grep "Sandbox.*my-sandbox"
kubectl describe sandbox my-sandbox
kubectl get pods -l sandbox=my-sandbox
Debug Task Execution Failures
kubectl get task my-task -o yaml
kubectl get task my-task -o jsonpath='{.status.exitCode}'
kubectl get task my-task -o jsonpath='{.status.stderr}'
SANDBOX_NAME=$(kubectl get task my-task -o jsonpath='{.spec.sandboxRef}')
POD_NAME=$(kubectl get sandbox $SANDBOX_NAME -o jsonpath='{.status.podName}')
kubectl logs $POD_NAME -c sidecar
kubectl logs -n arl -l app=arl-operator | grep "Task.*my-task"
Verify HTTP Service
kubectl port-forward service/<service-name> 8080:80 &
curl -f http://localhost:8080/health
scripts/exec_test.sh default <pod-pattern> curl -f http://<service-name>/health
Check Configuration
kubectl exec <pod-name> -- env | grep <VAR_NAME>
kubectl exec <pod-name> -- cat /etc/config/config.yaml
kubectl exec <pod-name> -- ls -la /etc/secrets/
Monitor Resources
kubectl top pods -n <namespace>
kubectl get deployment <name> -n <namespace> -w
kubectl logs -f <pod-name> -n <namespace>
Troubleshooting Checklist
When deployments fail:
- Check pod status:
kubectl get pods -n <namespace>
- Run debug script:
scripts/debug_pod.sh <namespace> <pod-name>
- Review events:
kubectl get events -n <namespace> --sort-by='.lastTimestamp'
- Check resource usage:
kubectl top pods -n <namespace>
- Verify configuration: Check env vars, configmaps, secrets
- Test connectivity: Network policies, service discovery
- Review RBAC: Service account permissions
Operator-specific troubleshooting:
- Check operator is running:
kubectl get pods -n arl
- Review operator logs:
make logs or kubectl logs -n arl -l app=arl-operator
- Verify CRDs are installed:
kubectl get crds | grep arl.infra.io
- Check custom resource status:
kubectl get <resource-type> <name> -o yaml
- Check operator reconciliation:
kubectl logs -n arl -l app=arl-operator | grep "Reconciling"
- Verify RBAC for operator:
kubectl get clusterrole,clusterrolebinding | grep arl
- Check sidecar logs in pods:
kubectl logs <pod-name> -c sidecar
- Test sidecar API: Port-forward and curl endpoints
- Verify warmpool has ready pods:
kubectl get warmpool <name> -o jsonpath='{.status.readyReplicas}'
- Check for resource conflicts: Multiple controllers, duplicate resources
Project-Specific Notes
Testing Environment Cleanup
IMPORTANT: Always clean up test resources before running tests:
kubectl delete tasks --all
kubectl delete sandboxes --all
kubectl delete pods -l app=arl-sandbox
kubectl get tasks,sandboxes,pods
Why cleanup is important:
- Tasks remain in terminal state (Succeeded/Failed) and accumulate
- Old task status may interfere with new test results
- Sandbox allocations may exhaust warmpool capacity
- File changes in pods persist across tasks if using same sandbox
FilePatch Path Handling
CRITICAL: FilePatch paths are relative to workDir (/workspace by default):
steps:
- name: create_script
type: FilePatch
path: hello.py
content: "print('hello')"
steps:
- name: create_script
type: FilePatch
path: /tmp/test.py
content: "print('hello')"
steps:
- name: create_script
type: FilePatch
path: /workspace/hello.py
content: "print('hello')"
WarmPool Image Registry
Remember to use correct image registry:
spec:
template:
spec:
containers:
- name: sidecar
image: 10.10.10.240/library/arl-sidecar:latest
imagePullPolicy: IfNotPresent
The operator automatically updates images when deployed via make k8s-run.
Task Step Behavior
Important task execution characteristics:
- Steps execute sequentially - if one fails, remaining steps are skipped
- FilePatch creates files but doesn't execute them
- Command steps need explicit paths - use full path or workDir
- Environment variables are only set for specific steps, not globally
- WorkDir defaults to
/workspace - change with workDir field
steps:
- name: create_script
type: FilePatch
path: test.py
content: |
import os
print(f"Current dir: {os.getcwd()}")
- name: run_script
type: Command
command: ["python", "/workspace/test.py"]
env:
MY_VAR: "value"
Rebuilding After Code Changes
After modifying operator or sidecar code:
make fmt && make vet
make docker-build docker-push
kubectl rollout restart deployment -n arl arl-operator
kubectl delete pods -l app=arl-sandbox
kubectl get pods -o jsonpath='{.items[*].spec.containers[*].image}' | tr ' ' '\n' | grep arl
Best Practices
Use Validation Before Apply
Always validate YAML before deploying:
kubectl apply --dry-run=client -f <file.yaml>
kubectl apply --dry-run=server -f <file.yaml>
For custom resources, this also validates against CRD schema.
Wait for Readiness
Don't assume immediate readiness. Use wait commands:
kubectl rollout status deployment/<name>
kubectl wait --for=condition=ready pod/<name> --timeout=300s
kubectl get warmpool <name> -o jsonpath='{.status.phase}' -w
Operator Development Best Practices
-
Always update CRDs after modifying types:
make generate
make manifests
-
Test locally before deploying:
go run cmd/operator/main.go
-
Use namespace for operator isolation:
- Operator runs in
arl namespace
- Resources can be in any namespace
-
Monitor operator reconciliation loops:
kubectl logs -n arl -l app=arl-operator -f | grep "Reconciling"
-
Version CRDs properly:
- Current version:
v1alpha1
- Plan migration path for breaking changes
Python Scripting with UV
-
Always use uv run for scripts:
uv run python scripts/verify_deployment.py <args>
-
Add dependencies as needed:
uv add <package-name>
-
Don't install packages globally - let uv manage the environment
Use Labels for Testing
Label test resources for easy cleanup:
kubectl apply -f test.yaml -l test-run=abc123
kubectl delete all -l test-run=abc123
Capture State for Debugging
When reporting issues, capture full state:
kubectl get all -n <namespace> -o yaml > state.yaml
scripts/debug_pod.sh <namespace> <pod-name> > debug.log
kubectl get warmpools,sandboxes,tasks -A -o yaml > custom-resources.yaml
kubectl logs -n arl -l app=arl-operator > operator.log
Project-Specific Workflows
Makefile Commands Reference
Development:
make fmt - Format Go code
make vet - Run Go vet
make tidy - Run go mod tidy
make build - Build operator and sidecar binaries
Docker (Minikube):
make docker-build - Build images for minikube
make docker-build-operator - Build operator image only
make docker-build-sidecar - Build sidecar image only
Docker (Standard K8s):
make docker-build-k8s - Build and tag for registry
make docker-push - Push images to registry
make k8s-build-push - Build and push in one command
Minikube:
make minikube-start - Start minikube cluster
make minikube-stop - Stop minikube
make minikube-delete - Delete minikube cluster
Deployment (Minikube):
helm upgrade --install arl-operator charts/arl-operator --namespace arl --create-namespace --set crds.install=true --wait - Deploy operator with CRDs
kubectl apply -f config/samples/ - Deploy sample resources
helm uninstall arl-operator -n arl --wait - Remove operator and CRDs
kubectl apply -f charts/arl-operator/crds/ - Install CRDs only
Deployment (Standard K8s):
helm upgrade --install arl-operator charts/arl-operator --namespace arl --create-namespace --set crds.install=true --set image.repository=<registry>/arl-operator --set sidecar.image.repository=<registry>/arl-sidecar --wait - Deploy to K8s cluster
helm uninstall arl-operator -n arl --wait - Remove from K8s cluster
Testing:
make test-integration - Run integration tests
make logs - Show operator logs
All-in-one:
make quickstart - Start minikube and deploy with samples
make quickstart-dev - Start in dev mode with auto-reload
Custom Resource API
WarmPool Spec:
spec:
replicas: 3
template:
spec:
containers:
- name: executor
image: python:3.9-slim
WarmPool Status:
status:
readyReplicas: 3
allocatedReplicas: 2
phase: Ready
Sandbox Spec:
spec:
poolRef: python-3.9-std
keepAlive: true
resources:
limits:
memory: "1Gi"
Sandbox Status:
status:
phase: Ready
podName: pool-pod-123
podIP: 10.244.1.5
workDir: /workspace
Task Spec:
spec:
sandboxRef: my-sandbox
timeout: 30s
steps:
- name: write_file
type: FilePatch
content: "print('hello')"
- name: run_code
type: Command
command: ["python", "test.py"]
Task Status:
status:
state: Succeeded
exitCode: 0
stdout: "hello\n"
stderr: ""
duration: 1.2s
Resources
scripts/
Automation scripts for common K8s operations:
verify_deployment.py - Automated deployment health verification
wait_for_pod.sh - Wait for pod readiness with timeout
debug_pod.sh - Comprehensive pod debugging information
exec_test.sh - Execute test commands in pods
references/
Detailed documentation and patterns:
testing_patterns.md - Comprehensive testing workflows and patterns
kubectl_reference.md - Complete kubectl command reference and examples