Kubectl AI: Your AI Assistant for Mastering Kubernetes


Introduction:
Google recently introduced Kubectl-AI, which is a significant advancement in kubernetes management that enables Developers and DevOps Engineers to interact with their clusters using Natural Language through AI powered assistance.
Overview:
What is kubectl-ai
Why it matters
Installation using
Ollama (Local)
Gemini
Hands-on implementation
Use Cases
How secure is Kubectl-ai
Conclusion
Getting Started
What is Kubectl-ai ?
Kubectl-ai is basically a plugin for kubectl which is developed by Google. Its primary function is to translate natural language queries into kubectl commands. Users can describe what they want in plain English and kubectl-ai will suggest the appropriate kubectl command and can even generate kubernetes manifest YAML.
When using Kubectl-ai plugin for kubectl, we integrate AI models directly into our kubernetes cluster where they can be natively used from the command line. This by default queries Gemini, but you can also query OpenAI, Grok or even locally running LLMs.
Why it matters
Kubernetes while it is powerful, it has a very steep learning curve. You need to have deep understanding of concepts such as command line syntax, helm, YAML formatting and troubleshooting. Kubectl itself has a vast number of commands, sub-commands. Remembering the exact syntax for specific tasks is difficult even for experienced users. Someone looking to start with kubernetes, can feel intimidated by the volume of kubectl options.
Kubectl-ai aims to bridge the gap by using the power of AI to make kubectl more accessible and allowing users to focus on intent instead of having to focus on the syntax.
Pre-requisites:
Kubernetes Cluster
Kubectl installed
Installation using Ollama
Steps:
Download Ollama from the official documentation here.
Go to the models tab, select gemma3.
Open your terminal and run the model using the below command.
ollama pull gemma3:12b-it-qat
Quantization aware trained models (QAT)
- Enable tool and Run the kubectl-ai
kubectl-ai --llm-provider ollama --model gemma3:12b-it-qat --enable-tool-use-shim
- You can simply run kubectl-ai without any argument to enter an interactive shell and ask questions while maintaining the context.
Example: “Fetch logs for the nginx app in the dev namespace”
Installation using Gemini
Steps:
- You can do a quick install using curl (Linux and MacOS only). Open your terminal and run the below command
curl -sSL <https://raw.githubusercontent.com/GoogleCloudPlatform/kubectl-ai/main/install.sh> | bash
You can also do a manual install by downloading the latest release. You can check the install guide from here.
Set the API key. You can get one from the Google AI Studio. Click on the Get API Key → Create API key.
Get back to the terminal and export the API key
export GEMINI_API_KEY=your_api_key_here
- Now you can run the agent by simply running the below command.
kubectl-ai
- Let us test it out, let us ask the agent to create a namespace named dev.
can you create a namespace in the name of dev?
You can see how the agent translates natural language into valid kubectl command. Example: when I asked "Can you create a namespace called dev?", it automatically generated the corresponding command: kubectl create namespace dev
. It then prompted for confirmation, and upon approval, successfully created the dev
namespace.
Use Cases
1. Writing YAML manifests
You can see how kubectl-ai generates the YAML which we can use directly or we can tweak it as needed.
You can see that how kubectl-ai not only understands my request, but also clearly outlines what it is going to do including the kubectl commands.
and in this screenshot you can see that kubectl-ai produces clean and ready to use YAML manifests for both deployment and service and asking if it can proceed.
2. Explaining an Existing kubernetes resources
We have resources deployed in the cluster and we want to understand what this particular YAML file or resources actually does. In that case we can as the kubectl-ai to explain it us.
In the below screenshot you can see that we have an existing resource and how kubectl-ai not only reads the YAML but breaks it down in simple terms.
This is useful for quick code reviews and easy to understand what each section does.
3. Troubleshooting and Fixing the issues.
We have a pod in CrashLoopBackOff
or there is some issue**.** We can ask kubectl-ai for help with explaining the issue and suggesting a fix for the same.
You can clearly see the error message, I had purposely given an invalid bs
command which results in crashloopbackoff
and kubectl-ai gives us the exact reason for the error and also suggesting fixes in real time.
These are some of the use cases which is used in day to day activities, there can be many such scenarios such as missing images or permission issues etc. That also can be resolved using kubectl-ai.
Security of Kubectl-ai:
If you’re using kubectl-ai with external LLM providers like OpenAI or Google Gemini, your prompts and sometimes the context such as logs, errors are sent to the model for processing. So you should avoid exposing sensitive information such as configs or secrets to these LLMs.
If you’re using kubectl-ai with local LLM providers like Ollama, this improves privacy and avoids sending cluster data over the internet. So, you can run it with a local model if you prefer to keep everything private and offline.
For stricter and more controlled environments one can use RBAC to limit unnecessary permissions. Also kubectl-ai is still best used in dev/test environments for now, but using it in production might not be too far off.
Conclusion:
Kubectl-ai is definitely a super tool which acts a developers AI powered co-pilot. From generating YAML manifests to troubleshooting errors and explaining the resources it has a lot to offer. While its no replacement for deep kubernetes knowledge but its great for learning and boosting your productivity. Moreover this tool is absolutely free and open source and designed by Google.
Do give it a try and let me know your comments.
Thanks for reading!
If you found this post useful, give it a like👍
Repost♻️
Follow Bala for more such posts 💯🚀
Subscribe to my newsletter
Read articles from Bala directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
