🎄 Introducing the Fix Flag: Actionable Solutions in k8sgpt 🎄

Prashant Lakhera
2 min readDec 21, 2024

--

As we step into the holiday season, I wanted to share something exciting from my journey with k8sgpt! One feature I felt was missing was the ability to recommend fixes and provide actionable solutions.

So, I got to work and started contributing! My goal was to introduce the fix flag, enabling k8sgpt to deliver actionable solutions to identified issues, and here’s my initial attempt. This feature is currently in its alpha stage, and, as you might imagine, it’s a challenging task. With AI providers producing different outputs for the same prompt, achieving consistent and accurate results takes some fine-tuning.

🎯 Nevertheless, I’m thrilled to share the first version of this feature! While it’s still evolving, I’d love to hear your thoughts. Your feedback and suggestions will be invaluable in refining this functionality.

Problem
Previously, k8sgpt would only provide recommendations for issues, like in the example below:

kubectl get pod
NAME READY STATUS RESTARTS AGE
badpod 0/1 ImagePullBackOff 0 12h
k8sgpt analyze - explain
Output:
0: Pod default/badpod()
- Error: Back-off pulling image “nginxbad”
Error: Kubernetes is unable to pull the image “nginxbad” due to a back-off error.
Solution: 
1. Check the image name and ensure it is spelled correctly.
2. Verify the image exists in the specified repository.
3. Ensure the image repository is accessible and the correct credentials are provided.

New Functionality: ` — fix` Flag
With the new ` — fix` flag, k8sgpt can now generate a YAML file with fixes for certain Kubernetes issues.

Example Usage

./bin/k8sgpt analyze - explain - fix

Output:

Getting fix for Pod default/badpod…
Fixed yaml saved to: fixed-Pod-default-badpod.yaml

Inspecting the fixed YAML file:

cat fixed-Pod-default-badpod.yaml
apiVersion: v1
kind: Pod
metadata:
name: badpod
namespace: default
spec:
containers:
- name: nginx
image: nginx:latest

Current Limitations
- The ` — fix` functionality currently supports only **basic Pod issues**.
- It requires **OpenAI** as the backend for generating fixes.

NOTE: This functionality is in its alpha stage and only addresses basic Pod issues. Contributions for extending support to other resources or more advanced issues are welcome.

Installation and Usage

Clone the Repository

git clone https://github.com/100daysofdevops/k8sgpt.git
cd k8sgpt
git switch addingfix
make clean && make build

Run the Analyzer with Fix


./bin/k8sgpt analyze — explain — fix

Provide Feedback
As this feature is still in alpha, your feedback is greatly appreciated. Feel free to raise issues or contribute to the repository for enhancements.

Contributing
If you’d like to add more functionality or fix advanced Kubernetes issues, please open a pull request or raise an issue in the repository.

đź”— GitHub repository link:

🎄Happy holidays and happy coding!

--

--

Prashant Lakhera
Prashant Lakhera

Written by Prashant Lakhera

AWS Community Builder, Ex-Redhat, Author, Blogger, YouTuber, RHCA, RHCDS, RHCE, Docker Certified,4XAWS, CCNA, MCP, Certified Jenkins, Terraform Certified, 1XGCP

Responses (1)