$npx -y skills add mjunaidca/mjs-agent-skills --skill kagentKubernetes-native AI agent framework for building, deploying, and managing AI agents on Kubernetes. This skill should be used when deploying AI agents as Kubernetes resources, analyzing cluster health with AI, and automating complex K8s operations. Use this skill for Phase IV adv
| 1 | # Kagent Skill |
| 2 | |
| 3 | ## Overview |
| 4 | |
| 5 | Kagent is a Kubernetes-native framework for building, deploying, and managing AI agents. It uses Custom Resource Definitions (CRDs) to define agents as Kubernetes resources, enabling declarative AI agent management with full K8s integration. |
| 6 | |
| 7 | ## Key Concepts |
| 8 | |
| 9 | ### What Kagent Provides |
| 10 | |
| 11 | 1. **Kubernetes-Native Agents**: Define AI agents as CRDs |
| 12 | 2. **Cluster Analysis**: AI-powered health checks and optimization |
| 13 | 3. **Extensibility**: Custom tools and integrations |
| 14 | 4. **Observability**: Full visibility into agent operations |
| 15 | |
| 16 | ### Architecture |
| 17 | |
| 18 | ``` |
| 19 | ┌─────────────────────────────────────────────────────┐ |
| 20 | │ Kubernetes Cluster │ |
| 21 | │ ┌─────────────────┐ ┌─────────────────────────┐ │ |
| 22 | │ │ Kagent │ │ Custom Resources │ │ |
| 23 | │ │ Controller │───▶│ - Agent │ │ |
| 24 | │ │ │ │ - Tool │ │ |
| 25 | │ │ │ │ - Model │ │ |
| 26 | │ └─────────────────┘ └─────────────────────────┘ │ |
| 27 | │ │ │ |
| 28 | │ ▼ │ |
| 29 | │ ┌─────────────────────────────────────────────────┐ │ |
| 30 | │ │ AI Agent Pods │ │ |
| 31 | │ │ - Execute kubectl commands │ │ |
| 32 | │ │ - Analyze resources │ │ |
| 33 | │ │ - Report findings │ │ |
| 34 | │ └─────────────────────────────────────────────────┘ │ |
| 35 | └─────────────────────────────────────────────────────┘ |
| 36 | ``` |
| 37 | |
| 38 | ## Installation |
| 39 | |
| 40 | ### Prerequisites |
| 41 | - Kubernetes cluster (Minikube, kind, or cloud) |
| 42 | - kubectl configured |
| 43 | - Go 1.21+ (for building from source) |
| 44 | |
| 45 | ### Install from Bundle |
| 46 | |
| 47 | ```bash |
| 48 | # Install CRDs and controller |
| 49 | kubectl apply -f https://raw.githubusercontent.com/kagent-dev/kagent/main/dist/install.yaml |
| 50 | ``` |
| 51 | |
| 52 | ### Build from Source |
| 53 | |
| 54 | ```bash |
| 55 | # Clone repository |
| 56 | git clone https://github.com/kagent-dev/kagent.git |
| 57 | cd kagent/go |
| 58 | |
| 59 | # Install CRDs |
| 60 | make install |
| 61 | |
| 62 | # Deploy controller |
| 63 | make deploy |
| 64 | ``` |
| 65 | |
| 66 | ### Build Installer Bundle |
| 67 | |
| 68 | ```bash |
| 69 | # Generate consolidated install.yaml |
| 70 | make build-installer |
| 71 | ``` |
| 72 | |
| 73 | ## Usage |
| 74 | |
| 75 | ### Basic Kubernetes Operations |
| 76 | |
| 77 | Kagent agents can execute standard kubectl commands: |
| 78 | |
| 79 | ```bash |
| 80 | # Resource listing |
| 81 | kubectl get pods -n namespace |
| 82 | kubectl get deployments -n namespace |
| 83 | kubectl get services -n namespace |
| 84 | |
| 85 | # Detailed listing |
| 86 | kubectl get pods -n namespace -o wide |
| 87 | kubectl get nodes -o wide |
| 88 | ``` |
| 89 | |
| 90 | ### Resource Inspection |
| 91 | |
| 92 | ```bash |
| 93 | # Describe resources |
| 94 | kubectl describe pod podname -n namespace |
| 95 | kubectl describe deployment deployname -n namespace |
| 96 | kubectl describe service servicename -n namespace |
| 97 | |
| 98 | # Get full YAML |
| 99 | kubectl get configmap configname -n namespace -o yaml |
| 100 | kubectl get secret secretname -n namespace -o yaml |
| 101 | ``` |
| 102 | |
| 103 | ### Health and Status Queries |
| 104 | |
| 105 | ```bash |
| 106 | # Component health |
| 107 | kubectl get componentstatuses |
| 108 | kubectl get nodes -o wide |
| 109 | |
| 110 | # Resource status |
| 111 | kubectl get deployments -n namespace -o wide |
| 112 | kubectl get pods -n namespace -o wide |
| 113 | ``` |
| 114 | |
| 115 | ### Advanced Operations |
| 116 | |
| 117 | ```bash |
| 118 | # Node management |
| 119 | kubectl drain <node> |
| 120 | kubectl cordon/uncordon <node> |
| 121 | |
| 122 | # Port forwarding |
| 123 | kubectl port-forward svc/my-service 8080:80 |
| 124 | |
| 125 | # Authorization checks |
| 126 | kubectl auth can-i create pods |
| 127 | |
| 128 | # Debugging |
| 129 | kubectl debug pod/my-pod --image=busybox |
| 130 | ``` |
| 131 | |
| 132 | ## Diagnostic Tools |
| 133 | |
| 134 | Kagent agents have access to: |
| 135 | |
| 136 | | Tool | Purpose | |
| 137 | |------|---------| |
| 138 | | `crictl` | Container runtime interface | |
| 139 | | `kubelet logs` | Node-level logs | |
| 140 | | `journalctl` | System logs | |
| 141 | | `tcpdump` | Network diagnostics | |
| 142 | | `netstat` | Connection status | |
| 143 | |
| 144 | ## Use Cases for TaskFlow |
| 145 | |
| 146 | ### 1. Cluster Health Analysis |
| 147 | |
| 148 | Use kagent to analyze overall cluster health before deployment: |
| 149 | |
| 150 | ```bash |
| 151 | kagent "analyze the cluster health and report any issues" |
| 152 | kagent "check if there are sufficient resources for 5 new pods" |
| 153 | ``` |
| 154 | |
| 155 | ### 2. Resource Optimization |
| 156 | |
| 157 | ```bash |
| 158 | kagent "identify pods without resource limits" |
| 159 | kagent "find over-provisioned deployments" |
| 160 | kagent "recommend resource adjustments based on actual usage" |
| 161 | ``` |
| 162 | |
| 163 | ### 3. Security Audit |
| 164 | |
| 165 | ```bash |
| 166 | kagent "find pods running as root" |
| 167 | kagent "identify services exposed without ingress" |
| 168 | kagent "check for secrets mounted as environment variables" |
| 169 | ``` |
| 170 | |
| 171 | ### 4. Troubleshooting |
| 172 | |
| 173 | ```bash |
| 174 | kagent "why are pods in namespace X failing?" |
| 175 | kagent "analyze network connectivity between services" |
| 176 | kagent "find the root cause of OOMKilled pods" |
| 177 | ``` |
| 178 | |
| 179 | ## Custom Resource Definitions |
| 180 | |
| 181 | ### Agent CRD Example |
| 182 | |
| 183 | ```yaml |
| 184 | apiVersion: kagent.dev/v1alpha1 |
| 185 | kind: Agent |
| 186 | metadata: |
| 187 | name: cluster-analyzer |
| 188 | namespace: kagent-system |
| 189 | spec: |
| 190 | model: |
| 191 | provider: openai |
| 192 | name: gpt-4 |
| 193 | tools: |
| 194 | - kubectl |
| 195 | - helm |
| 196 | systemPrompt: | |