k8s-copilot

command module
v0.0.0-...-ceb3457 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 4, 2024 License: MIT Imports: 1 Imported by: 0

README

K8s-Copilot

Overview

K8s-Copilot is a command-line tool based on Golang which allows you to create/list/update/delete Kubernetes built-in resources interactively powered by ChatGPT.

Note: Model is currently hard-coded in gpt-4o-mini.

Use Cases

  • Create a Kubernetes resource in a specific namespace.
  • List Kubernetes either namespaced or non-namespaced resources.
  • Update a Kubernetes resource given specific name & namespace.
  • Delete a Kubernetes resource given specific name & namespace.

Features

Architecture

Cobra
k8s-copilot
├── ask
│   ├── chatgpt
└── analyze
    ├── event

Demo

Prerequisite

An out-of-box Kubernetes cluster environment, try kind. 👈

Install Golang.

Build
$ go build -o k8s-copilot
Setup ENV

Try APIYI 👈 if you had difficulty acquiring OpenAI API Key from mainland China.

# wsl env to win
$ export API_KEY="api_key"
$ export BASE_URL="base_url"

If you're using WSL, add below to /etc/wsl.conf then export the ENV.

[automount]
options = "metadata"
$ export WSLENV=API_KEY/w:BASE_URL/w
Run

Help

$ ./k8s-copilot -h

Ask

$ ./k8s-copilot ask chatgpt

A greeting prompt will show up.

Greetings, I'm a Copilot for Kubernetes, you require my assistant?
>

Type your queries:

Note: open another terminal to run kubectl cmd for checking.

> create a deploy named nginx, image is nginx:latest, replica is 2
# check
$ kubectl get deploy
> ls all pods
> ls all pods in kube-system
> ls all services in kube-system
> ls all namespaces
> update deploy named nginx replica to 3
# check
$ kubectl get deploy
> add label env=test to deploy named nginx
# check
$ kubectl get po --show-labels
> remove label env=test from deploy named nginx
# check
$ kubectl get po --show-labels
> update image of deploy named nginx to nginx:1.26.2
# check
$ kubectl get deploy nginx -o yaml | grep image:
> delete deploy named nginx
$ kubectl get deploy
> exit

Implementation

See more in UML. 👈

Limitation

  • Sometimes the update query is not strictly idempotent due to returned response from LLM, please try multiple times.
  • The update query will create a new ReplicaSet if you try to add a label to Deployment.

Operation and Maintenance

N/A

Troubleshooting

N/A

Q&A

N/A

Reference

N/A

TODO

  • Add a flag to select LLM.
  • Replace stdin with GNU-Readline.
  • Add event analyzer feature.
  • Fine tune system prompt to LLM to improve robustness & Idempotence.

Documentation

Overview

Copyright © 2024 kokoichi

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL