How sozercan/kubectl-ai works
Kubectl AI is a command-line assistant that turns a natural-language request (optionally combined with YAML piped on stdin) into Kubernetes manifests, then lets the user refine, discard, or apply them. Its main runtime path is command setup and orchestration, OpenAI completion, optional Kubernetes OpenAPI schema lookup for function calling, interactive review, and application to the configured cluster. The sampled files show these calls directly; README documents pipe input/output and configuration options. Schema lookup can use either the cluster API or a configured URL.
Main entry points: root.go Prompt and review · openai.go Chat completion · schema.go Schema retrieval · completion.go Completion retries
Components 14
CLI workflow
- CLI entry
cmd/cli/root.go - Prompt and review
cmd/cli/root.go
Manifest generation
- Completion retries
cmd/cli/completion.go - Chat completion
cmd/cli/openai.go
Schema discovery
- Schema tools
cmd/cli/functions.go - Schema retrieval
cmd/cli/schema.go
Kubernetes application
- Manifest application
cmd/cli/kubernetes.go
Other components
- User
- Piped YAML
- OpenAI-compatible API
- Kubernetes API
- kubectl OpenAPI request
- Custom OpenAPI URL
- Kubernetes cluster
Connections 15
- User → CLI entry: runs command
README.md - CLI entry → Prompt and review: routes prompt
cmd/cli/root.go - Piped YAML → Completion retries: provides YAML
README.md - Prompt and review → Completion retries: requests completion
cmd/cli/root.go - Completion retries → Chat completion: calls with prompt
cmd/cli/completion.go - Chat completion → OpenAI-compatible API: sends chat request
cmd/cli/openai.go - OpenAI-compatible API → Chat completion: returns completion
cmd/cli/openai.go - Chat completion → Schema tools: dispatches tool calls
cmd/cli/openai.go - Schema tools → Schema retrieval: fetches schema
cmd/cli/functions.go - Schema retrieval → kubectl OpenAPI request: requests cluster spec
cmd/cli/schema.go - kubectl OpenAPI request → Kubernetes API: reads OpenAPI spec
README.md - Schema retrieval → Custom OpenAPI URL: fetches configured spec
cmd/cli/schema.go - Prompt and review → Manifest application: applies approved manifest
cmd/cli/root.go - Manifest application → Kubernetes cluster: applies resources
cmd/cli/kubernetes.go - User → Prompt and review: chooses review action
cmd/cli/root.go