$npx -y skills add mjunaidca/mjs-agent-skills --skill kubectl-aiAI-powered Kubernetes operations using kubectl-ai from Google Cloud Platform. This skill should be used when managing Kubernetes clusters with natural language commands, generating manifests, troubleshooting issues, and performing AI-assisted DevOps. Use this skill for Phase IV A
| 1 | # kubectl-ai Skill |
| 2 | |
| 3 | ## Overview |
| 4 | |
| 5 | kubectl-ai is an intelligent interface from Google Cloud Platform that translates natural language into precise Kubernetes operations. It supports multiple LLM providers (Gemini, OpenAI, Azure OpenAI, Ollama, Grok) and can generate, apply, and troubleshoot Kubernetes resources. |
| 6 | |
| 7 | ## Installation |
| 8 | |
| 9 | ### macOS (ARM64) |
| 10 | ```bash |
| 11 | # Download |
| 12 | curl -LO https://github.com/GoogleCloudPlatform/kubectl-ai/releases/latest/download/kubectl-ai_Darwin_arm64.tar.gz |
| 13 | |
| 14 | # Extract and install |
| 15 | tar -zxvf kubectl-ai_Darwin_arm64.tar.gz |
| 16 | chmod a+x kubectl-ai |
| 17 | sudo mv kubectl-ai /usr/local/bin/ |
| 18 | ``` |
| 19 | |
| 20 | ### macOS (AMD64) |
| 21 | ```bash |
| 22 | curl -LO https://github.com/GoogleCloudPlatform/kubectl-ai/releases/latest/download/kubectl-ai_Darwin_x86_64.tar.gz |
| 23 | tar -zxvf kubectl-ai_Darwin_x86_64.tar.gz |
| 24 | chmod a+x kubectl-ai |
| 25 | sudo mv kubectl-ai /usr/local/bin/ |
| 26 | ``` |
| 27 | |
| 28 | ### Linux |
| 29 | ```bash |
| 30 | curl -LO https://github.com/GoogleCloudPlatform/kubectl-ai/releases/latest/download/kubectl-ai_Linux_x86_64.tar.gz |
| 31 | tar -zxvf kubectl-ai_Linux_x86_64.tar.gz |
| 32 | chmod a+x kubectl-ai |
| 33 | sudo mv kubectl-ai /usr/local/bin/ |
| 34 | ``` |
| 35 | |
| 36 | ## Configuration |
| 37 | |
| 38 | ### Set API Keys |
| 39 | |
| 40 | ```bash |
| 41 | # Gemini (default) |
| 42 | export GEMINI_API_KEY=your_api_key_here |
| 43 | |
| 44 | # OpenAI |
| 45 | export OPENAI_API_KEY=your_api_key_here |
| 46 | |
| 47 | # Azure OpenAI |
| 48 | export AZURE_OPENAI_ENDPOINT=your_endpoint_here |
| 49 | export AZURE_OPENAI_API_KEY=your_api_key_here |
| 50 | |
| 51 | # Grok |
| 52 | export GROK_API_KEY=your_xai_api_key_here |
| 53 | ``` |
| 54 | |
| 55 | ### Verify Setup |
| 56 | |
| 57 | ```bash |
| 58 | # Check kubectl-ai is working |
| 59 | kubectl-ai --help |
| 60 | |
| 61 | # Interactive mode |
| 62 | kubectl-ai |
| 63 | ``` |
| 64 | |
| 65 | ## Usage Patterns |
| 66 | |
| 67 | ### Basic Commands |
| 68 | |
| 69 | ```bash |
| 70 | # Interactive mode (default) |
| 71 | kubectl-ai |
| 72 | |
| 73 | # Single command (quiet mode) |
| 74 | kubectl-ai -quiet "show me all pods in the default namespace" |
| 75 | |
| 76 | # Specify model |
| 77 | kubectl-ai --model gemini-2.5-pro "list all deployments" |
| 78 | ``` |
| 79 | |
| 80 | ### Using Different Providers |
| 81 | |
| 82 | ```bash |
| 83 | # Gemini (default) |
| 84 | kubectl-ai "show all services" |
| 85 | |
| 86 | # OpenAI |
| 87 | kubectl-ai --llm-provider=openai --model=gpt-4.1 "scale nginx to 5 replicas" |
| 88 | |
| 89 | # Azure OpenAI |
| 90 | kubectl-ai --llm-provider=azopenai --model=your_deployment_name "check pod logs" |
| 91 | |
| 92 | # Grok |
| 93 | kubectl-ai --llm-provider=grok --model=grok-3-beta "describe the cluster" |
| 94 | |
| 95 | # Ollama (local) |
| 96 | kubectl-ai --llm-provider ollama --model gemma3:12b-it-qat --enable-tool-use-shim "list pods" |
| 97 | ``` |
| 98 | |
| 99 | ## Common Operations |
| 100 | |
| 101 | ### Information Gathering |
| 102 | |
| 103 | ```bash |
| 104 | # List resources |
| 105 | kubectl-ai -quiet "show me all pods in the default namespace" |
| 106 | kubectl-ai -quiet "list all deployments across all namespaces" |
| 107 | kubectl-ai -quiet "what services are running?" |
| 108 | |
| 109 | # Describe resources |
| 110 | kubectl-ai -quiet "describe the nginx deployment" |
| 111 | kubectl-ai -quiet "show me the logs from the api pod" |
| 112 | kubectl-ai -quiet "what's consuming the most memory?" |
| 113 | ``` |
| 114 | |
| 115 | ### Creating Resources |
| 116 | |
| 117 | ```bash |
| 118 | # Create deployment |
| 119 | kubectl-ai -quiet "create a deployment named nginx with 3 replicas using nginx:latest image" |
| 120 | |
| 121 | # Create service |
| 122 | kubectl-ai -quiet "expose the nginx deployment on port 80" |
| 123 | |
| 124 | # Create configmap |
| 125 | kubectl-ai -quiet "create a configmap called app-config with DATABASE_URL=postgres://db:5432" |
| 126 | ``` |
| 127 | |
| 128 | ### Scaling and Updates |
| 129 | |
| 130 | ```bash |
| 131 | # Scale deployment |
| 132 | kubectl-ai -quiet "scale the nginx deployment to 5 replicas" |
| 133 | kubectl-ai -quiet "double the capacity for the nginx app" |
| 134 | |
| 135 | # Update image |
| 136 | kubectl-ai -quiet "update the api deployment to use image api:v2.0" |
| 137 | |
| 138 | # Rolling restart |
| 139 | kubectl-ai -quiet "restart the api deployment" |
| 140 | ``` |
| 141 | |
| 142 | ### Troubleshooting |
| 143 | |
| 144 | ```bash |
| 145 | # Check pod issues |
| 146 | kubectl-ai -quiet "why is the api pod failing?" |
| 147 | kubectl-ai -quiet "check logs for nginx app in hello namespace" |
| 148 | kubectl-ai -quiet "show events for failing pods" |
| 149 | |
| 150 | # Resource issues |
| 151 | kubectl-ai -quiet "which pods are using the most CPU?" |
| 152 | kubectl-ai -quiet "find pods that are in CrashLoopBackOff" |
| 153 | |
| 154 | # Network issues |
| 155 | kubectl-ai -quiet "test connectivity to the database service" |
| 156 | ``` |
| 157 | |
| 158 | ### Cleanup |
| 159 | |
| 160 | ```bash |
| 161 | # Delete resources |
| 162 | kubectl-ai -quiet "delete all pods in pending state" |
| 163 | kubectl-ai -quiet "remove the nginx deployment" |
| 164 | kubectl-ai -quiet "clean up completed jobs" |
| 165 | ``` |
| 166 | |
| 167 | ## Pipeline Input |
| 168 | |
| 169 | kubectl-ai accepts input from stdin: |
| 170 | |
| 171 | ```bash |
| 172 | # Explain error log |
| 173 | cat error.log | kubectl-ai "explain the error" |
| 174 | |
| 175 | # Process kubectl output |
| 176 | kubectl get pods -o yaml | kubectl-ai "find pods without resource limits" |
| 177 | |
| 178 | # Analyze manifest |
| 179 | cat deployment.yaml | kubectl-ai "review this manifest for best practices" |
| 180 | ``` |
| 181 | |
| 182 | ## Interactive Mode Commands |
| 183 | |
| 184 | When running `kubectl-ai` without arguments: |
| 185 | |
| 186 | ``` |
| 187 | >> help # Show available commands |
| 188 | >> models # List available models (Ollama) |
| 189 | >> clear # Clear conversation |
| 190 | >> exit # Exit interactive mode |
| 191 | ``` |
| 192 | |
| 193 | ## MCP Server Mode |
| 194 | |
| 195 | kubectl-ai can run as an MCP server for integration with |