K8sGPT + Ollama: AI-Powered Kubernetes Troubleshooting

Run the get pods to see the state of pods

kubectl get pods -A
kubectl describe pod bad-image-6b59c98484-8cbb4 -n k8sgpt-lab

This shows image is not existing

The deployment isn’t a file on disk — it lives inside Kubernetes so les check bad-image and save the deployment to a temp file

kubectl get deployment bad-image -n k8sgpt-lab -o yaml > /tmp/bad-image.yaml

Open the file

Change it to: image: nginx:latest

Apply the file

kubectl apply -f /tmp/bad-image.yaml

Check the pods

bad-image is fixed and Running. Three left. Let’s go through each one:

kubectl describe pod bad-image-6b59c98484-8cbb4 -n k8sgpt-lab

The deployment isn’t a file on disk — it lives inside Kubernetes so les check bad-probe and save the deployment to a temp file

kubectl get deployment bad-probe -n k8sgpt-lab -o yaml > /tmp/bad-probe.yaml

Open the file

Error is this section

Apply the file

kubectl apply -f /tmp/bad-probe.yaml
kubectl get pods -n k8sgpt-lab

You should see bad-probe stop restarting and go to Running.

Ok, lets AI to fix the CrashLoopBackOff

Here we cant drill down to individual pod but result is on the namesapce

k8sgpt analyze --explain --backend localai --namespace k8sgpt-lab

Finding 2 — oom-app: Kubernetes container was terminated due to OutOfMemory

Finding 3 — resource-hog: 0/1 nodes are available: 1 Insufficient cpu

run -o wide to the status more clearly

kubectl get pods -n k8sgpt-lab -o wide
kubectl describe pod resource-hog-c766fc4f9-2lwbs -n k8sgpt-lab | grep -A3 Limits
kubectl describe pod resource-hog-c766fc4f9-2lwbs -n k8sgpt-lab | grep -A3 Requests

oom-app is memory limited and resource-hog pod is the CPU starved

Fix oom-app memory

kubectl set resources deployment oom-app -n k8sgpt-lab--limits=memory=200Mi --requests=memory=200Mi

Fix resource-hog CPU+memory

kubectl set resources deployment resource-hog -n k8sgpt-lab --limits=cpu=200m,memory=128Mi --requests=cpu=100m,memory=64Mi

Analyse and explain using AI

k8sgpt analyze --explain --backend localai --namespace k8sgpt-lab
(Visited 4 times, 1 visits today)

By Ash Thomas

Ash Thomas is a seasoned IT professional with extensive experience as a technical expert, complemented by a keen interest in blockchain technology.