このプロジェクトは、OpenAI GPTを使用してKubernetesマニフェストを生成および適用するkubectlプラグインです。
私の主な動機は、開発/テストの際にランダムなマニフェストを見つけて収集することを避けることです。
brew Tapに追加して、次のようにインストールします。
brew tap sozercan/kubectl-ai https://github.com/sozercan/kubectl-ai
brew install kubectl-aikrew Indexに追加して、以下をインストールします。
kubectl krew index add kubectl-ai https://github.com/sozercan/kubectl-ai
kubectl krew install kubectl-ai/kubectl-aiGithubリリースからバイナリをダウンロードします。
これをkubectlプラグインとして使用する場合は、 kubectl-aiバイナリをPATHにコピーしてください。そうでない場合は、バイナリスタンドアロンを使用することもできます。
kubectl-aiには、有効なKubernetes構成が必要であり、次のいずれかが必要です。
Openai、Azure Openai、またはOpenai API互換エンドポイントの場合、次の環境変数を使用できます。
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 " > OPENAI_ENDPOINT変数が設定されている場合、エンドポイントを使用します。それ以外の場合は、OpenAI APIを使用します。
Azure Openaiサービスでは、などの特定の文字を許可しません. 、展開名。その結果、 kubectl-ai 、 gpt-3.5-turboをAzureのgpt-35-turboに自動的に置き換えます。ただし、モデル名とはまったく異なるAzure Openai展開名を使用する場合、 AZURE_OPENAI_MAP環境変数を設定して、モデル名をAzure Openai展開名にマッピングできます。例えば:
export AZURE_OPENAI_MAP= " gpt-3.5-turbo=my-deployment "OpenAI APIアクセスがない場合は、GPUなしでローカルマシンのAIKITを使用して、ローカルOpenai API互換のエンドポイントをセットアップできます。詳細については、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 "上記のように環境をセットアップした後、通常どおりkubectl-aiを使用できます。
--require-confirmation flagまたはREQUIRE_CONFIRMATION環境変数を設定して、マニフェストを適用する前にユーザーに確認を促すことができます。デフォルトはtrueです。
--temperatureフラグまたはTEMPERATURE環境変数は0〜1の間に設定できます。温度が高いと、より創造的な完了が生じます。温度が低いと、より決定的な完了が生じます。デフォルトは0です。
--use-k8s-apiフラグまたはUSE_K8S_API環境変数を設定して、kubernetes openapi仕様を使用してマニフェストを生成することができます。これにより、CRDを含む非常に正確な完了(構成されたクラスターに存在する場合)が得られます。この設定では、より多くのOpenAI API呼び出しが使用され、 0613以降のモデルでのみ使用可能な関数呼び出しが必要です。デフォルトはfalseになります。ただし、これは精度と完全性に推奨されます。
--k8s-openapi-urlフラグまたはK8S_OPENAPI_URL環境変数は、カスタムKubernetes Openapi Spec URLを使用するように設定できます。これは、 --use-k8s-apiが設定されている場合にのみ使用されます。デフォルトでは、 kubectl-ai 、この設定が構成されていない限り、構成されたKubernetes APIサーバーを使用して仕様を取得します。デフォルトのkubernetes openapi仕様を使用するか、カスタムリソース定義(CRD)を含む完了のためにカスタム仕様を生成できます。 kubectl get --raw /openapi/v2 > swagger.jsonを使用して、カスタムOpenapi仕様を生成できます。
Kubectl AIは、パイプ入力と出力で使用できます。例えば:
$ cat foo-deployment.yaml | kubectl ai " change replicas to 5 " --raw | kubectl apply -f -$ cat foo-deployment.yaml | kubectl ai " change replicas to 5 " --raw > my-deployment-updated.yaml外部エディターを使用して生成されたマニフェストを編集する場合は、 --rawフラグとパイプを選択したエディターに設定できます。例えば:
# Visual Studio Code
$ kubectl ai " create a foo namespace " --raw | code -
# Vim
$ kubectl ai " create a foo namespace " --raw | vim -$ 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: 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$ 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--require-confirmationフラグ$ 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プラグインはクラスターの現在の状態を知らないので(まだ?)、常に完全なマニフェストが生成されることに注意してください。