返回排行榜

sozercan/kubectl-ai

Go

✨ Kubectl plugin to create manifests with LLMs

kubernetesopenaichatgptkubectl-pluginsgpt-4hacktoberfestaikubectlopenai-apigptk8sllm
Star 增长趋势
Star
1.2k
Forks
88
周增长
Issues
8
6008001k
2023年3月2024年4月2025年6月2026年7月
制品库Go Modulesgo get github.com/sozercan/kubectl-ai
README

Kubectl OpenAI plugin ✨

This project is a kubectl plugin to generate and apply Kubernetes manifests using OpenAI GPT.

My main motivation is to avoid finding and collecting random manifests when dev/testing things.

Demo

asciicast

Installation

Homebrew

Add to brew tap and install with:

brew tap sozercan/kubectl-ai https://github.com/sozercan/kubectl-ai
brew install kubectl-ai

Krew

Add to krew index and install with:

kubectl krew index add kubectl-ai https://github.com/sozercan/kubectl-ai
kubectl krew install kubectl-ai/kubectl-ai

GitHub release

  • Download the binary from GitHub releases.

  • If you want to use this as a kubectl plugin, then copy kubectl-ai binary to your PATH. If not, you can also use the binary standalone.

Usage

Prerequisites

kubectl-ai requires a valid Kubernetes configuration and one of the following:

For OpenAI, Azure OpenAI or OpenAI API compatible endpoint, you can use the following environment variables:

export OPENAI_API_KEY=<your OpenAI key>
export OPENAI_DEPLOYMENT_NAME=<your OpenAI deployment/model name. defaults to "gpt-3.5-turbo-0301">
export OPENAI_ENDPOINT=<your OpenAI endpoint, like "https://my-aoi-endpoint.openai.azure.com" or "http://localhost:8080/v1">

If OPENAI_ENDPOINT variable is set, then it will use the endpoint. Otherwise, it will use OpenAI API.

Azure OpenAI service does not allow certain characters, such as ., in the deployment name. Consequently, kubectl-ai will automatically replace gpt-3.5-turbo to gpt-35-turbo for Azure. However, if you use an Azure OpenAI deployment name completely different from the model name, you can set AZURE_OPENAI_MAP environment variable to map the model name to the Azure OpenAI deployment name. For example:

export AZURE_OPENAI_MAP="gpt-3.5-turbo=my-deployment"

Set up a local OpenAI API-compatible endpoint

If you don't have OpenAI API access, you can set up a local OpenAI API-compatible endpoint using AIKit on your local machine without any GPUs! For more information, see the AIKit documentaton.

docker run -d --rm -p 8080:8080 ghcr.io/sozercan/llama3.1:8b
export OPENAI_ENDPOINT="http://localhost:8080/v1"
export OPENAI_DEPLOYMENT_NAME="llama-3.1-8b-instruct"
export OPENAI_API_KEY="n/a"

After setting up the environment like above, you can use kubectl-ai as usual.

Flags and environment variables

  • --require-confirmation flag or REQUIRE_CONFIRMATION environment variable can be set to prompt the user for confirmation before applying the manifest. Defaults to true.

  • --temperature flag or TEMPERATURE environment variable can be set between 0 and 1. Higher temperature will result in more creative completions. Lower temperature will result in more deterministic completions. Defaults to 0.

  • --use-k8s-api flag or USE_K8S_API environment variable can be set to use Kubernetes OpenAPI Spec to generate the manifest. This will result in very accurate completions including CRDs (if present in configured cluster). This setting will use more OpenAI API calls and it requires function calling which is available in 0613 or later models only. Defaults to false. However, this is recommended for accuracy and completeness.

  • --k8s-openapi-url flag or K8S_OPENAPI_URL environment variable can be set to use a custom Kubernetes OpenAPI Spec URL. This is only used if --use-k8s-api is set. By default, kubectl-ai will use the configured Kubernetes API Server to get the spec unless this setting is configured. You can use the default Kubernetes OpenAPI Spec or generate a custom spec for completions that includes custom resource definitions (CRDs). You can generate custom OpenAPI Spec by using kubectl get --raw /openapi/v2 > swagger.json.

Pipe Input and Output

Kubectl AI can be used with pipe input and output. For example:

$ cat foo-deployment.yaml | kubectl ai "change replicas to 5" --raw | kubectl apply -f -

Save to file

$ cat foo-deployment.yaml | kubectl ai "change replicas to 5" --raw > my-deployment-updated.yaml

Use with external editors

If you want to use an external editor to edit the generated manifest, you can set the --raw flag and pipe to the editor of your choice. For example:

# Visual Studio Code
$ kubectl ai "create a foo namespace" --raw | code -

# Vim
$ kubectl ai "create a foo namespace" --raw | vim -

Examples

Creating objects with specific values

$ kubectl ai "create an nginx deployment with 3 replicas"
✨ Attempting to apply the following manifest:
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.7.9
        ports:
        - containerPort: 80
Use the arrow keys to navigate: ↓ ↑ → ←
? Would you like to apply this? [Reprompt/Apply/Don't Apply]:
+   Reprompt
  ▸ Apply
    Don't Apply

Reprompt to refine your prompt

...
Reprompt: update to 5 replicas and port 8080
✨ Attempting to apply the following manifest:
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 5
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.7.9
        ports:
        - containerPort: 8080
Use the arrow keys to navigate: ↓ ↑ → ←
? Would you like to apply this? [Reprompt/Apply/Don't Apply]:
+   Reprompt
  ▸ Apply
    Don't Apply

Multiple objects

$ kubectl ai "create a foo namespace then create nginx pod in that namespace"
✨ Attempting to apply the following manifest:
apiVersion: v1
kind: Namespace
metadata:
  name: foo
---
apiVersion: v1
kind: Pod
metadata:
  name: nginx
  namespace: foo
spec:
  containers:
  - name: nginx
    image: nginx:latest
Use the arrow keys to navigate: ↓ ↑ → ←
? Would you like to apply this? [Reprompt/Apply/Don't Apply]:
+   Reprompt
  ▸ Apply
    Don't Apply

Optional --require-confirmation flag

$ kubectl ai "create a service with type LoadBalancer with selector as 'app:nginx'" --require-confirmation=false
✨ Attempting to apply the following manifest:
apiVersion: v1
kind: Service
metadata:
  name: nginx-service
spec:
  selector:
    app: nginx
  ports:
  - port: 80
    targetPort: 80
  type: LoadBalancer

Please note that the plugin does not know the current state of the cluster (yet?), so it will always generate the full manifest.

相关仓库
kubernetes/kubernetes

Production-Grade Container Scheduling and Management

GoGo ModulesApache License 2.0kubernetesgo
kubernetes.io
123.9k43.7k
bregman-arie/devops-exercises

Linux, Jenkins, AWS, SRE, Prometheus, Docker, Python, Ansible, Git, Kubernetes, Terraform, OpenStack, SQL, NoSQL, Azure, GCP, DNS, Elastic, Network, Virtualization. DevOps Interview Questions

PythonPyPIOtherdevopsaws
83.3k19.8k
netdata/netdata

The fastest path to AI-powered full stack observability, even for lean teams.

GoGo ModulesGNU General Public License v3.0monitoringdocker
netdata.cloud
79.8k6.5k
traefik/traefik

The Cloud Native Application Proxy

GoGo ModulesMIT Licensemicroservicedocker
traefik.io
64.1k6.1k
minio/minio

MinIO is a high-performance, S3 compatible object store, open sourced under GNU AGPLv3 license.

GoGo ModulesGNU Affero General Public License v3.0gostorage
61.4k7.7k
etcd-io/etcd

Distributed reliable key-value store for the most critical data of a distributed system

GoGo ModulesApache License 2.0etcdraft
etcd.io
52k10.4k
GitHubDaily/GitHubDaily

坚持分享 GitHub 上高质量、有趣实用的开源技术教程、开发者工具、编程网站、技术资讯。A list cool, interesting projects of GitHub.

githubopen-source
githubdaily.com
47.1k4.7k
LeCoupa/awesome-cheatsheets

👩‍💻👨‍💻 Awesome cheatsheets for popular programming languages, frameworks and development tools. They include everything you should know in one single file.

JavaScriptnpmMIT Licensecheatsheetsjavascript
lecoupa.github.io/awesome-cheatsheets/
46.2k6.7k
Kong/kong

🦍 The API and AI Gateway

LuaApache License 2.0api-gatewaymicroservices
konghq.com/install/
43.8k5.2k
istio/istio

Connect, secure, control, and observe services.

GoGo ModulesApache License 2.0microservicesservice-mesh
istio.io
38.3k8.3k
ToolJet/ToolJet

ToolJet is the open-source foundation of ToolJet AI - the enterprise app generation platform for building internal tools, dashboard, business applications, workflows and AI agents 🚀

JavaScriptnpmGNU Affero General Public License v3.0javascriptinternal-tools
tooljet.com
38.2k5.2k
portainer/portainer

Making Docker and Kubernetes management easy.

TypeScriptnpmzlib Licensedockerdocker-swarm
portainer.io
38k2.9k