Skip to content

Commit a40ea9c

Browse files
Merge pull request #132 from anveshmuppeda/dev
🎉 kubectl-ai Blog is out now! Check it out here 🥳
2 parents 7b33813 + e1f27f0 commit a40ea9c

File tree

16 files changed

+1310
-945
lines changed

16 files changed

+1310
-945
lines changed

LICENSE

Lines changed: 202 additions & 674 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 126 additions & 255 deletions
Large diffs are not rendered by default.

docs/ai/_category_.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"label": "AI in Kubernetes",
3+
"position": 10,
4+
"link": {
5+
"type": "generated-index",
6+
"description": "This section provides a comprehensive guide on how to leverage AI and machine learning in your Kubernetes environment. It covers best practices, tools, and techniques for deploying and managing AI workloads on Kubernetes. Topics include model serving, data pipelines, and integration with popular AI frameworks.",
7+
}
8+
}

docs/ai/img/ollama.config.png

132 KB
Loading

docs/ai/img/ollama.list.png

65.4 KB
Loading

docs/ai/img/ollama.model.pull.png

269 KB
Loading

docs/ai/img/ollama.running.png

31.2 KB
Loading

docs/ai/kubectl-ai.md

Lines changed: 224 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
1+
---
2+
// filepath: /Users/anveshmuppeda/Desktop/anvesh/tech/git/kubernetes/docs/ai/kubectl-ai.md
3+
sidebar_label: "Kubectl-AI"
4+
sidebar_id: "kubectl-ai"
5+
sidebar_position: 1
6+
---
7+
8+
9+
# Kubectl-AI: Enhance Kubernetes Management with AI
10+
11+
Below is the trimmed-down, focused documentation covering only the sections you requested, with detailed step-by-step instructions.
12+
13+
---
14+
15+
## kubectl-ai Introduction
16+
17+
`kubectl-ai` is a plugin and CLI tool that turns natural-language queries into Kubernetes commands. Instead of memorizing `kubectl` flags or YAML manifests, you simply ask questions like “show me all pods in the default namespace” or “scale the nginx deployment to 5 replicas,” and `kubectl-ai` figures out the exact `kubectl` commands to run. Under the hood it uses large language models (LLMs) to parse your intent, then executes the corresponding `kubectl` operations and returns both the raw output and an explanation in plain English.
18+
19+
Key benefits:
20+
- **Natural-language interface:** No more guessing flag names or resource kinds.
21+
- **Context awareness:** In interactive mode, follow-on questions (“What about in the staging cluster?”) carry context.
22+
- **Extensible backends:** Works with commercial LLMs (Gemini, OpenAI, Azure OpenAI, Grok) or fully offline local models (Ollama, llama.cpp).
23+
- **Scriptable & pipable:** Use it in CI, scripts, or combine with shell pipes (`echo … | kubectl-ai`).
24+
25+
---
26+
27+
## Installation
28+
29+
You need a working `kubectl` binary configured against your cluster, plus one of these ways to install `kubectl-ai` itself:
30+
31+
### Quick Install (Linux & macOS)
32+
33+
```bash
34+
curl -sSL https://raw.githubusercontent.com/GoogleCloudPlatform/kubectl-ai/main/install.sh | bash
35+
```
36+
37+
This will download the latest release, install the `kubectl-ai` binary into `~/.local/bin` (or similar), and add it to your PATH for the current session.
38+
39+
### Manual Installation (Linux, macOS & Windows)
40+
41+
1. Visit the [releases page](https://github.com/GoogleCloudPlatform/kubectl-ai/releases/latest) and download the archive matching your OS/arch (e.g. `kubectl-ai_Darwin_arm64.tar.gz` for Apple Silicon macOS).
42+
2. Unpack, make executable, and move into your PATH:
43+
44+
```bash
45+
tar -zxvf kubectl-ai_Darwin_arm64.tar.gz
46+
chmod +x kubectl-ai
47+
sudo mv kubectl-ai /usr/local/bin/
48+
```
49+
50+
3. Verify installation:
51+
52+
```bash
53+
kubectl-ai version
54+
```
55+
56+
---
57+
58+
## Usage
59+
60+
Once installed, you can run `kubectl-ai` in two main modes: using cloud-hosted LLMs (Gemini by default) or local models (Ollama/llama.cpp).
61+
62+
---
63+
64+
### Using Gemini (Default)
65+
66+
1. **Obtain a key**
67+
Go to [Google AI Studio](https://aistudio.google.com), create a project, and copy your Gemini API key.
68+
69+
2. **Export the environment variable**
70+
```bash
71+
export GEMINI_API_KEY="your_gemini_api_key_here"
72+
```
73+
74+
3. **Run `kubectl-ai`**
75+
- **Interactive shell:**
76+
```bash
77+
kubectl-ai
78+
```
79+
You’ll get a `kubectl-ai> ` prompt where you can ask a sequence of questions.
80+
81+
- **Single-query mode:**
82+
```bash
83+
kubectl-ai --quiet "fetch logs for nginx app in hello namespace"
84+
```
85+
86+
4. **Switch models** (optional)
87+
```bash
88+
# Use a specific Gemini model
89+
kubectl-ai --model gemini-2.5-pro-exp-03-25 "list services in default"
90+
```
91+
92+
---
93+
94+
### Using AI Models Running Locally (Ollama or llama.cpp)
95+
96+
You can run entirely offline by hosting your own LLM with either [Ollama](https://ollama.com/) or [llama.cpp](https://github.com/ggml-org/llama.cpp). Below are detailed steps for each:
97+
98+
---
99+
100+
#### A. Ollama
101+
102+
1. **Install Ollama**
103+
```bash
104+
# macOS via Homebrew
105+
brew install ollama
106+
# or Linux via their install script
107+
curl -fsSL https://ollama.com/install.sh | sh
108+
```
109+
110+
Alternatively, you can download the Ollama binary directly from their website:
111+
1. Visit the Ollama [download page](https://ollama.com/download/mac).
112+
2. Click on the Download for macOS button.
113+
3. Once the download is complete, locate the .zip file in your ~/Downloads folder.
114+
4. Double-click the .zip file to extract its contents. This should create Ollama.app.
115+
5. Move the Ollama.app to your Applications folder for easy access.
116+
6. Open the Applications folder and double-click on Ollama.app to launch it.
117+
7. Follow any on-screen instructions to complete the installation.
118+
8. Once installed, you can run the Ollama CLI commands in your terminal.
119+
120+
121+
2. **Run the Ollama server**
122+
```bash
123+
ollama serve
124+
```
125+
By default, this listens on `http://localhost:11434`.
126+
127+
![Ollama Running](img/ollama.running.png)
128+
129+
3. **Pull a model**
130+
```bash
131+
ollama pull gemma3:12b-it-qat
132+
```
133+
This downloads the `gemma3:12b-it-qat` model, which is optimized for Kubernetes tasks.
134+
135+
![Ollama Pull](img/ollama.model.pull.png)
136+
137+
4. **List models**
138+
```bash
139+
ollama list
140+
```
141+
This command will show you all the models you have downloaded and their status.
142+
143+
![Ollama List](img/ollama.list.png)
144+
You should see `gemma3:12b-it-qat` in the list.
145+
146+
5. **Configure `kubectl-ai`**
147+
```bash
148+
export OLLAMA_HOST="http://localhost:11434"
149+
kubectl-ai \
150+
--llm-provider=ollama \
151+
--model=gemma3:12b-it-qat \
152+
--enable-tool-use-shim
153+
```
154+
The `--enable-tool-use-shim` flag ensures the prompt includes the right instructions for invoking `kubectl`.
155+
This is important for the model to understand how to interact with Kubernetes.
156+
157+
![Ollama Config](img/ollama.config.png)
158+
159+
6. **Use it**
160+
- Interactive: `kubectl-ai`
161+
- Single query:
162+
```bash
163+
kubectl-ai --quiet "describe deployment my-app"
164+
```
165+
166+
7. **Remove a model**
167+
```bash
168+
ollama remove gemma3:12b-it-qat
169+
```
170+
This command will delete the model from your local machine.
171+
172+
8. **Stop the server**
173+
```bash
174+
ollama stop
175+
```
176+
This command will stop the Ollama server.
177+
178+
179+
---
180+
181+
#### B. llama.cpp
182+
183+
1. **Install or build**
184+
```bash
185+
# Homebrew (macOS/Linux)
186+
brew install llama.cpp
187+
```
188+
The formula is automatically updated with new llama.cpp releases.
189+
190+
2. **Get a model**
191+
- Download a GGUF (quantized) model from Hugging Face (e.g. `alpaca-7b-q4_0.gguf`).
192+
- Place it in `~/models/` or your chosen directory.
193+
194+
3. **Run the server**
195+
```bash
196+
./main --model ~/models/alpaca-7b-q4_0.gguf --server
197+
```
198+
This starts an OpenAI-compatible API on `http://127.0.0.1:8080`.
199+
200+
4. **Configure `kubectl-ai`**
201+
```bash
202+
export LLAMA_CPP_SERVER="http://127.0.0.1:8080"
203+
kubectl-ai \
204+
--llm-provider=llama.cpp \
205+
--model=alpaca-7b-q4_0.gguf \
206+
--enable-tool-use-shim
207+
```
208+
209+
5. **Use it**
210+
- Interactive: `kubectl-ai`
211+
- Single query:
212+
```bash
213+
kubectl-ai --quiet "scale deployment nginx to 4 replicas"
214+
```
215+
216+
---
217+
## References
218+
- [GoogleCloudPlatform GitHub Repository](https://github.com/GoogleCloudPlatform/kubectl-ai)
219+
- [Google AI Studio](https://aistudio.google.com)
220+
- [Ollama](https://ollama.com/)
221+
- [llama.cpp](https://github.com/ggml-org/llama.cpp)
222+
223+
With these sections in place, users have everything needed to get started with `kubectl-ai`—from installation through cloud (Gemini) or local (Ollama/llama.cpp) usage.
224+

k8swebsite.config.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,27 @@ const config: Config = {
8787
maxHits: 10, // Show up to 10 results
8888
},
8989
],
90+
[
91+
'@docusaurus/theme-live-codeblock', // Wrap this plugin in an array
92+
{},
93+
],
9094
],
9195

9296
themeConfig: {
97+
liveCodeBlock: {
98+
/**
99+
* The position of the live playground, above or under the editor
100+
* Possible values: "top" | "bottom"
101+
*/
102+
playgroundPosition: 'bottom',
103+
},
93104
announcementBar: {
94105
id: 'announcement', // Unique ID for the announcement
95-
content:
96-
'⭐️ If you like this project, give it a star on <a target="_blank" rel="noopener noreferrer" href="https://github.com/anveshmuppeda/kubernetes">GitHub</a> and follow me on <a target="_blank" rel="noopener noreferrer" href="https://www.linkedin.com/in/anveshmuppeda/">LinkedIn</a> ⭐️',
97-
backgroundColor: '#fafbfc', // Background color
98-
textColor: '#091E42', // Text color
99-
isCloseable: true, // Allow users to close the bar
106+
content:
107+
'🎉️ <b><a target="_blank" href="https://github.com/anveshmuppeda/kubernetes/releases/tag/${version}">Docusaurus v${version}</a> is out!</b> 🥳️',
108+
backgroundColor: '#fafbfc',
109+
textColor: '#091E42',
110+
isCloseable: false,
100111
},
101112
image: 'img/docusaurus-social-card.jpg',
102113
navbar: {

kubectl-ai

37.4 MB
Binary file not shown.

0 commit comments

Comments
 (0)