• Stars
    star
    906
  • Rank 50,411 (Top 1.0 %)
  • Language
    Go
  • License
    MIT License
  • Created over 1 year ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

✨ Kubectl plugin for OpenAI GPT

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 an OpenAI API key or an Azure OpenAI Service API key and endpoint, and a valid Kubernetes configuration.

For both OpenAI and Azure OpenAI, 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">

Following models are supported:

  • code-davinci-002
  • text-davinci-003
  • gpt-3.5-turbo
  • gpt-3.5-turbo-0301 (default)
  • gpt-4-0314
  • gpt-4-32k-0314

For Azure OpenAI Service, you can use the following environment variables:

export AZURE_OPENAI_ENDPOINT=<your Azure OpenAI endpoint, like "https://my-aoi-endpoint.openai.azure.com">

If AZURE_OPENAI_ENDPOINT variable is set, then it will use the Azure OpenAI Service. 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"

Flags and environment variables

  • --require-confirmation flag or REQUIRE_CONFIRMATION environment varible 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 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.

More Repositories

1

OpenInCode

📂 macOS Finder toolbar app to open current folder in Visual Studio Code
Objective-C
876
star
2

vscode-slack

💬 Slack extension for Visual Studio Code
TypeScript
47
star
3

electron-menubar

🌟Sample menubar app that shows popover for macOS
CSS
47
star
4

awesome-botframework

🤖 A curated list of awesome Microsoft Bot Framework related things
30
star
5

tensorflow-object-detection

📦 Operationalizing TensorFlow Object Detection on Azure
Python
26
star
6

slack-typobot

🤖 Slack bot that corrects typos
JavaScript
23
star
7

OpenShift-Azure-Terraform

⛑ Deploy OpenShift Origin on Azure using Terraform and Ansible
HCL
19
star
8

aikit

🏗️ AI + BuildKit = AIKit: Build and deploy large language models easily
Go
13
star
9

WAT-UWP

🌐 Web App Template (WAT) for Universal Windows Platform (UWP)
JavaScript
13
star
10

guac-ai-mole

🥑 Charting the Course for Secure Software Supply Chain
Python
10
star
11

acs-engine-upgrade

⚒ Script that upgrades existing ACS Kubernetes clusters
Shell
7
star
12

kubeadm-azure-terraform

📦 Using Kubeadm to provision a Kubernetes cluster on Azure
HCL
7
star
13

trivy-provider

👾 Trivy image vulnerability scanner provider for Gatekeeper external data
Go
6
star
14

tagToDigest-provider

Generic tag to digest provider for Gatekeeper
Go
5
star
15

accounts-bot

📈 Bot that retrieves and filters information from Dynamics CRM Online and Graph SharePoint
JavaScript
5
star
16

echobot-k8s

⚓️ Sample Microsoft Bot Framework bot running on Kubernetes on Azure Container Service
JavaScript
5
star
17

k8s-federation-azure-coredns

⎈ Kubernetes cluster federation on Azure with CoreDNS
4
star
18

cosign-provider

Cosign provider for Gatekeeper
Go
2
star
19

langchain-playground

🐦🔗🛝
Jupyter Notebook
1
star
20

terraform-vm-keyvault

🐧 Microsoft Azure Linux VM created with Terraform that uses Azure Key Vault
HCL
1
star
21

openshift-azure-ansible

⛑ Deploy OpenShift Origin on Azure using Ansible
1
star
22

supportBot

⚙ Sample proactive support and ticketing system bot
JavaScript
1
star
23

inceptionBot

🤖 Bot that uses Tensorflow Serving to recognize images
JavaScript
1
star
24

terraform-aks

⎈ Terraform Azure Kubernetes Service (AKS) sample
HCL
1
star