Kubernetes and AI

Passionate about DevOps, Kubernetes, Cloud-Native technologies, and Open Source, I specialize in building scalable, automated, and secure infrastructure solutions. With hands-on experience in CI/CD, Kubernetes, HashiCorp Vault, Terraform, Airflow, and cloud platforms, I aim to bridge the gap between development and operations.
With the world now revolving around Artificial Intelligence (AI), and Kubernetes being such an important and comparatively new technology, it is only fair to look into how we could integrate AI with Kubernetes to get a better understanding of it and use it in our daily work. Here are 2 tools I have recently come across, and wanted to share my understanding with folks new to the community.
kubectl-ai
kubectl-ai is like your helpful Kubernetes assistant—it understands what you need and handles the technical details, making it easier and faster to manage your clusters. You can interact with it in simple English, and in the backend, it uses an LLM model (as per your configuration) to understand and comprehend your needs.
For example, if you want to retrieve all the pods in your cluster, you need to make a request, and kubectl-ai interprets the request as “kubectl get pods” and provides the output.
Configuration
curl -sSL https://raw.githubusercontent.com/GoogleCloudPlatform/kubectl-ai/main/install.sh | bash
export GEMINI_API_KEY=your_api_key_here
kubectl-ai
You can get your API key from Google AI Studio. You can see how fine kubectl-ai works.

Let’s look at another example of creating a pod just by using a prompt. We want to create an NGINX pod in the default namespace. We need to state the name of the pod and the image to be used, and kubectl-ai does the rest.


k8sgpt
K8sGPT is your AI-powered Kubernetes sidekick—it spots issues, explains what’s wrong, and even helps fix them, making troubleshooting faster and simpler!
K8sGPT helps in
Configuration
curl -LO https://github.com/k8sgpt-ai/k8sgpt/releases/latest/download/k8sgpt_Linux_x86_64.tar.gz
tar -xzf k8sgpt_Linux_x86_64.tar.gz
sudo mv k8sgpt /usr/local/bin/
k8sgpt auth list
#lets take google gemini for example
k8sgpt auth add --backend <backend-name> --model <model-name>
Here is an example of how K8sgpt helps in troubleshooting errors in the cluster.

We see that our pod is pending, and we can investigate using k8sgpt.

We can see that this command helps in pointing out the errors in our cluster. Our pod is pending because we have insufficient memory. Now, we can use AI to find a solution for the error using the command:
k8sgpt analyze --explain -b <backend-name>
# we are using ollama, to setup ollama
k8sgpt auth add --backend ollama --model tinyllama --baseurl http://localhost:11434
ollama serve
k8sgpt analyze --explain -b ollama # run this in a separate terminal

After getting the solutions, you can choose the best one according to your needs. Note that a better model of the backend provider gives a better optimized solution. I would recommend using llama3 to get the best solutions; otherwise, other models are effective too.

Some might be thinking that the above errors could be easily detected using the kubectl describe command, but beginners can use k8sgpt to learn Kubernetes in detail. We can also use K8sgpt on a larger scale, as it offers additional features. To learn more, I would like to suggest following the links given below for better understanding.
Important links:
kubectl-ai Video link: https://youtu.be/LFQpuZb_r6s?si=KSaWTL_vCgpKlx15
Github repo of kubectl-ai: https://github.com/GoogleCloudPlatform/kubectl-ai
K8sGPT Video link: https://youtu.be/eKsWS7OM5oY?si=BMsb8ATlVSlWO_Fk
K8sGPT official website: https://k8sgpt.ai/



