k8sgpt — Operator
L’operator esegue k8sgpt periodicamente dentro il cluster e salva i risultati come custom resource Result. Nessun terminale aperto, risultati consultabili con kubectl o GitOps.
Installazione
Sezione intitolata “Installazione”helm repo add k8sgpt https://charts.k8sgpt.ai/helm repo updatehelm upgrade --install k8sgpt-operator k8sgpt/k8sgpt-operator -n k8sgpt-operator-system --create-namespace --set serviceMonitor.enabled=truekubectl -n k8sgpt-operator-system get podskubectl get crd | grep k8sgptCR K8sGPT verso Ollama sull’host
Sezione intitolata “CR K8sGPT verso Ollama sull’host”cat > k8sgpt-local.yaml <<'EOF2'apiVersion: core.k8sgpt.ai/v1alpha1kind: K8sGPTmetadata: name: k8sgpt-local namespace: k8sgpt-operator-systemspec: ai: enabled: true backend: localai model: qwen2.5:7b-instruct baseUrl: http://host.docker.internal:11434/v1 noCache: false repository: ghcr.io/k8sgpt-ai/k8sgpt version: v0.4.1 filters: - Pod - Service - PersistentVolumeClaim - DeploymentEOF2version è il tag dell’immagine runtime che l’operator avvia: allinealo a una release esistente di k8sgpt. Verifica i campi supportati dalla tua versione del CRD:
kubectl explain k8sgpt.spec.aikubectl apply -f k8sgpt-local.yamlkubectl -n k8sgpt-operator-system get k8sgpt,deploy,podsRisultati
Sezione intitolata “Risultati”kubectl -n k8sgpt-operator-system get resultskubectl -n k8sgpt-operator-system get results -o custom-columns=KIND:.spec.kind,NAME:.spec.name,PARENT:.spec.parentObjectkubectl -n k8sgpt-operator-system get results -o jsonpath='{range .items[*]}{"== "}{.spec.kind}{"/"}{.spec.name}{"\n"}{.spec.details}{"\n\n"}{end}'kubectl -n k8sgpt-operator-system get result -o yaml | yq '.items[0].spec'I Result si aggiornano a ogni ciclo: quando correggi un guasto, il relativo Result sparisce.
Metriche
Sezione intitolata “Metriche”Con serviceMonitor.enabled=true Prometheus raccoglie le metriche dell’operator. Individua i nomi esposti:
curl -s 'localhost:9090/api/v1/label/__name__/values' | jq -r '.data[]' | grep -i k8sgptSink (notifiche)
Sezione intitolata “Sink (notifiche)”Il CR supporta sink come Slack o Mattermost tramite spec.sink. In ambienti offline punta a un’istanza interna:
kubectl explain k8sgpt.spec.sinkLog e troubleshooting
Sezione intitolata “Log e troubleshooting”kubectl -n k8sgpt-operator-system logs deploy/k8sgpt-operator-controller-manager -fkubectl -n k8sgpt-operator-system logs deploy/k8sgpt-local -fkubectl -n k8sgpt-operator-system describe k8sgpt k8sgpt-localRimozione
Sezione intitolata “Rimozione”kubectl delete -f k8sgpt-local.yamlhelm uninstall k8sgpt-operator -n k8sgpt-operator-system