ChatGPT for your Kubernetes Cluster — k8sgpt

Renjith Ravindranathan
techbeatly
Published in
2 min readMar 28, 2023
ChatGPT3

Have you tried chatting with ChatGPT and got shocked by its fantastic responses? Well k8sgpt brings you chatgpt for your k8s platform. It enables the user to analyze issues in the cluster and reports it back with suggestions to fix the issue. I used this to quickly check for K3s cluster and it works nicely even in the first release. The setup is very straight forward and lets go through them shortly.

Steps

  1. Get the binary according to your environment — Linux, Windows or Mac from the k8sgpt release page
>wget https://github.com/k8sgpt-ai/k8sgpt/releases/download/v0.1.1/k8sgpt_Linux_x86_64.tar.gz
tar -xvf k8sgpt_Linux_x86_64.tar.gz
k8sgpt

2. Secondly it needs to get API Key from OpenAI website or you can use below command to generate one. Currently the default AI backend provider is OpenAI

> k8sgpt generate

Opening: https://beta.openai.com/account/api-keys to generate a key for openaish
Please copy the generated key and run `k8sgpt auth` to add it to your config file

3. After getting the API key, we can add the API to the config file using the below command

k8sgpt auth

4. Currently there are a few inbuilt analyzer available for k8sgpt and in future it is planned for more extension. In other words, as of now k8sgpt has the capability to find issues in Kubernetes objects such as Pod, PVC, Replicaset and Services.

So a simple analyze will look something like below

// Create a nginx pod with wrong image version
kubectl run nginx --image=nginx:5.0.0 --restart=Never

//Analyze the issues in the cluster(English). By default it responds back in English

k8sgpt analyze --explain

5. You can get the response in other languages as well. For example if you want to get response in Dutch(the language which i am trying to learn now :))

k8sgpt analyze --explain --language 'Dutch'

Every 2,0s: k8sgpt analyze --explain edgeblazer-desktop: Tue Mar 28 18:10:56 2023

{ 0% | | (0/1, 0 it/hr) [0s:0s] 100% |██████████████████████████████████████████████| (1/1, 3182 it/s)
0 default/nginx(nginx): Back-off pulling image "nginx:5.0.0"
De Pods zijn niet in staat om de verwachte image te downloaden en te starten, daarom is er een back-off geactiveerd om te wachten voordat het opnieuw wordt geprobeerd. De oplossing is om ervoor te zorgen dat de image-tag correct is gespecificeerd en dat er geen netwerkproblemen zijn die het downloaden verhinderen. Controleer ook of de image bestaat en toegankelijk is voor de cluster.

The team behind k8sgpt is planning and enhancing the CLI capabilities and features such as Custom Analyzer support, Custom AI backend and AI/ML model support. Definitely this is a handy tool which helps in initial troubleshooting, thereby improving the Ops experience and making life better. Expecting more in this space and that’s all for now.

In case of any queries, please feel free to connect with me via the below social links

References

--

--

Renjith Ravindranathan
techbeatly

A DevOps engineer by profession, Dad, Traveler & sometimes, like to tweak around stuff inside memory constrained devices. Currently living in the Netherlands.