kube-agent


Namekube-agent JSON
Version 0.2.0 PyPI version JSON
download
home_pagehttps://github.com/feiskyer/kube-agent
SummaryA Kubernetes copilot agent powered by OpenAI
upload_time2024-11-13 13:00:45
maintainerNone
docs_urlNone
authorPengfei Ni
requires_python<4.0,>=3.10
licenseNone
keywords kubernetes copilot openai chatgpt agent ai agentic
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Autonomous Agent for Kubernetes

Autonomous Agent for Kubernetes powered by OpenAI.

Features:

- Autonomous Kubernetes cluster operations using LLM Agents powered by ChatGPT (GPT-3.5, GPT-4 and future versions).
- Diagnose and analyze the potential issues for Kubernetes workloads.
- Generate the Kubernetes manifests based on the provided prompt instructions.
- Utilize native kubectl and trivy commands for Kubernetes cluster access and security vulnerability scanning.

## Install

### Install locally

Install the kube-agent with the commands below. It is highly recommended to use [pipx](https://pipx.pypa.io/stable/) or [venv](https://docs.python.org/3/library/venv.html) to install the copilot to avoid conflicts with other Python packages.

```sh
# Option 1: use pipx to install the copilot
pipx install kube-agent

# Option 2: use venv to install the copilot
python3 -m venv agentenv
source agentenv/bin/activate
pip install kube-agent

# Option 3: Use pip to install the copilot (not recommended)
pip install kube-agent
```

**Setup:**

- Ensure [`kubectl`](https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/) is installed on the local machine and the kubeconfig file is configured for Kubernetes cluster access.
- Install [`trivy`](https://github.com/aquasecurity/trivy) to assess container image security issues (for the `audit` command).
- Set the OpenAI [API key](https://platform.openai.com/account/api-keys) as the `OPENAI_API_KEY` environment variable to enable ChatGPT functionality.
  - For [Azure OpenAI service](https://learn.microsoft.com/en-us/azure/cognitive-services/openai/quickstart?tabs=command-line&pivots=rest-api#retrieve-key-and-endpoint), please set `AZURE_OPENAI_API_KEY=<key>` and `AZURE_OPENAI_ENDPOINT=https://<replace-this>.openai.azure.com/`.

### Run in Kubernetes

```sh
kubectl run -it --rm copilot \
  --env="OPENAI_API_KEY=$OPENAI_API_KEY" \
  --restart=Never \
  --image=ghcr.io/feiskyer/kube-agent \
  -- execute --verbose 'What Pods are using max memory in the cluster'

kubectl run -it --rm copilot \
  --env="AZURE_OPENAI_API_KEY=$AZURE_OPENAI_API_KEY" \
  --env="AZURE_OPENAI_ENDPOINT=$AZURE_OPENAI_ENDPOINT" \
  --restart=Never \
  --image=ghcr.io/feiskyer/kube-agent \
  -- execute --verbose 'What Pods are using max memory in the cluster'
```

Refer [kubernetes.md](kubernetes.md) for more detailed steps.

## How to use

Running directly in the terminal:

```sh
Usage: kube-agent [OPTIONS] COMMAND [ARGS]...

  Kubernetes Copilot powered by OpenAI

Options:
  --version  Show the version and exit.
  --help     Show this message and exit.

Commands:
  analyze   analyze issues for a given resource
  audit     audit security issues for a Pod
  diagnose  diagnose problems for a Pod
  execute   execute operations based on prompt instructions
  generate  generate Kubernetes manifests
```

### Audit Security Issues for Pod

`kube-agent audit POD [NAMESPACE]` will audit security issues for a Pod:

```sh
Usage: kube-agent audit [OPTIONS] POD [NAMESPACE]

  audit security issues for a Pod

Options:
  --verbose      Enable verbose information of copilot execution steps
  --model MODEL  OpenAI model to use for copilot execution, default is gpt-4
  --help         Show this message and exit.
```

### Diagnose Problems for Pod

`kube-agent diagnose POD [NAMESPACE]` will diagnose problems for a Pod:

```sh
Usage: kube-agent diagnose [OPTIONS] POD [NAMESPACE]

  diagnose problems for a Pod

Options:
  --verbose      Enable verbose information of copilot execution steps
  --model MODEL  OpenAI model to use for copilot execution, default is gpt-4
  --help         Show this message and exit.
```

### Analyze Potential Issues for k8s Object

`kube-agent analyze RESOURCE NAME [NAMESPACE]` will analyze potential issues for the given resource object:

```sh
Usage: kube-agent analyze [OPTIONS] RESOURCE NAME [NAMESPACE]

  analyze issues for a given resource

Options:
  --verbose     Enable verbose information of copilot execution steps
  --model TEXT  OpenAI model to use for copilot execution, default is gpt-4
  --help        Show this message and exit.
```

### Execute Operations Based on Prompt Instructions

`kube-agent execute INSTRUCTIONS` will execute operations based on prompt instructions.
It could also be used to ask any questions.

```sh
Usage: kube-agent execute [OPTIONS] INSTRUCTIONS

  execute operations based on prompt instructions

Options:
  --verbose      Enable verbose information of copilot execution steps
  --model MODEL  OpenAI model to use for copilot execution, default is gpt-4
  --help         Show this message and exit.
```

### Generate Kubernetes Manifests

Use the `kube-agent generate` command to create Kubernetes manifests based on
the provided prompt instructions. After generating the manifests, you will be
prompted to confirm whether you want to apply them.

```sh
Usage: kube-agent generate [OPTIONS] INSTRUCTIONS

  generate Kubernetes manifests

Options:
  --verbose     Enable verbose information of copilot execution steps
  --model TEXT  OpenAI model to use for copilot execution, default is gpt-4
  --help        Show this message and exit.
```

## Contribution

The project is opensource at github [feiskyer/kube-agent](https://github.com/feiskyer/kube-agent) with Apache License.

If you would like to contribute to the project, please follow these guidelines:

1. Fork the repository and clone it to your local machine.
2. Create a new branch for your changes.
3. Make your changes and commit them with a descriptive commit message.
4. Push your changes to your forked repository.
5. Open a pull request to the main repository.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/feiskyer/kube-agent",
    "name": "kube-agent",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.10",
    "maintainer_email": null,
    "keywords": "kubernetes, copilot, openai, chatgpt, agent, ai, agentic",
    "author": "Pengfei Ni",
    "author_email": "feiskyer@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/77/7b/4af1df1bf29aca61faa048bfe69314ac075598a3d285be1389a7aa7b10de/kube_agent-0.2.0.tar.gz",
    "platform": null,
    "description": "# Autonomous Agent for Kubernetes\n\nAutonomous Agent for Kubernetes powered by OpenAI.\n\nFeatures:\n\n- Autonomous Kubernetes cluster operations using LLM Agents powered by ChatGPT (GPT-3.5, GPT-4 and future versions).\n- Diagnose and analyze the potential issues for Kubernetes workloads.\n- Generate the Kubernetes manifests based on the provided prompt instructions.\n- Utilize native kubectl and trivy commands for Kubernetes cluster access and security vulnerability scanning.\n\n## Install\n\n### Install locally\n\nInstall the kube-agent with the commands below. It is highly recommended to use [pipx](https://pipx.pypa.io/stable/) or [venv](https://docs.python.org/3/library/venv.html) to install the copilot to avoid conflicts with other Python packages.\n\n```sh\n# Option 1: use pipx to install the copilot\npipx install kube-agent\n\n# Option 2: use venv to install the copilot\npython3 -m venv agentenv\nsource agentenv/bin/activate\npip install kube-agent\n\n# Option 3: Use pip to install the copilot (not recommended)\npip install kube-agent\n```\n\n**Setup:**\n\n- Ensure [`kubectl`](https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/) is installed on the local machine and the kubeconfig file is configured for Kubernetes cluster access.\n- Install [`trivy`](https://github.com/aquasecurity/trivy) to assess container image security issues (for the `audit` command).\n- Set the OpenAI [API key](https://platform.openai.com/account/api-keys) as the `OPENAI_API_KEY` environment variable to enable ChatGPT functionality.\n  - For [Azure OpenAI service](https://learn.microsoft.com/en-us/azure/cognitive-services/openai/quickstart?tabs=command-line&pivots=rest-api#retrieve-key-and-endpoint), please set `AZURE_OPENAI_API_KEY=<key>` and `AZURE_OPENAI_ENDPOINT=https://<replace-this>.openai.azure.com/`.\n\n### Run in Kubernetes\n\n```sh\nkubectl run -it --rm copilot \\\n  --env=\"OPENAI_API_KEY=$OPENAI_API_KEY\" \\\n  --restart=Never \\\n  --image=ghcr.io/feiskyer/kube-agent \\\n  -- execute --verbose 'What Pods are using max memory in the cluster'\n\nkubectl run -it --rm copilot \\\n  --env=\"AZURE_OPENAI_API_KEY=$AZURE_OPENAI_API_KEY\" \\\n  --env=\"AZURE_OPENAI_ENDPOINT=$AZURE_OPENAI_ENDPOINT\" \\\n  --restart=Never \\\n  --image=ghcr.io/feiskyer/kube-agent \\\n  -- execute --verbose 'What Pods are using max memory in the cluster'\n```\n\nRefer [kubernetes.md](kubernetes.md) for more detailed steps.\n\n## How to use\n\nRunning directly in the terminal:\n\n```sh\nUsage: kube-agent [OPTIONS] COMMAND [ARGS]...\n\n  Kubernetes Copilot powered by OpenAI\n\nOptions:\n  --version  Show the version and exit.\n  --help     Show this message and exit.\n\nCommands:\n  analyze   analyze issues for a given resource\n  audit     audit security issues for a Pod\n  diagnose  diagnose problems for a Pod\n  execute   execute operations based on prompt instructions\n  generate  generate Kubernetes manifests\n```\n\n### Audit Security Issues for Pod\n\n`kube-agent audit POD [NAMESPACE]` will audit security issues for a Pod:\n\n```sh\nUsage: kube-agent audit [OPTIONS] POD [NAMESPACE]\n\n  audit security issues for a Pod\n\nOptions:\n  --verbose      Enable verbose information of copilot execution steps\n  --model MODEL  OpenAI model to use for copilot execution, default is gpt-4\n  --help         Show this message and exit.\n```\n\n### Diagnose Problems for Pod\n\n`kube-agent diagnose POD [NAMESPACE]` will diagnose problems for a Pod:\n\n```sh\nUsage: kube-agent diagnose [OPTIONS] POD [NAMESPACE]\n\n  diagnose problems for a Pod\n\nOptions:\n  --verbose      Enable verbose information of copilot execution steps\n  --model MODEL  OpenAI model to use for copilot execution, default is gpt-4\n  --help         Show this message and exit.\n```\n\n### Analyze Potential Issues for k8s Object\n\n`kube-agent analyze RESOURCE NAME [NAMESPACE]` will analyze potential issues for the given resource object:\n\n```sh\nUsage: kube-agent analyze [OPTIONS] RESOURCE NAME [NAMESPACE]\n\n  analyze issues for a given resource\n\nOptions:\n  --verbose     Enable verbose information of copilot execution steps\n  --model TEXT  OpenAI model to use for copilot execution, default is gpt-4\n  --help        Show this message and exit.\n```\n\n### Execute Operations Based on Prompt Instructions\n\n`kube-agent execute INSTRUCTIONS` will execute operations based on prompt instructions.\nIt could also be used to ask any questions.\n\n```sh\nUsage: kube-agent execute [OPTIONS] INSTRUCTIONS\n\n  execute operations based on prompt instructions\n\nOptions:\n  --verbose      Enable verbose information of copilot execution steps\n  --model MODEL  OpenAI model to use for copilot execution, default is gpt-4\n  --help         Show this message and exit.\n```\n\n### Generate Kubernetes Manifests\n\nUse the `kube-agent generate` command to create Kubernetes manifests based on\nthe provided prompt instructions. After generating the manifests, you will be\nprompted to confirm whether you want to apply them.\n\n```sh\nUsage: kube-agent generate [OPTIONS] INSTRUCTIONS\n\n  generate Kubernetes manifests\n\nOptions:\n  --verbose     Enable verbose information of copilot execution steps\n  --model TEXT  OpenAI model to use for copilot execution, default is gpt-4\n  --help        Show this message and exit.\n```\n\n## Contribution\n\nThe project is opensource at github [feiskyer/kube-agent](https://github.com/feiskyer/kube-agent) with Apache License.\n\nIf you would like to contribute to the project, please follow these guidelines:\n\n1. Fork the repository and clone it to your local machine.\n2. Create a new branch for your changes.\n3. Make your changes and commit them with a descriptive commit message.\n4. Push your changes to your forked repository.\n5. Open a pull request to the main repository.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A Kubernetes copilot agent powered by OpenAI",
    "version": "0.2.0",
    "project_urls": {
        "Homepage": "https://github.com/feiskyer/kube-agent",
        "Repository": "https://github.com/feiskyer/kube-agent"
    },
    "split_keywords": [
        "kubernetes",
        " copilot",
        " openai",
        " chatgpt",
        " agent",
        " ai",
        " agentic"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c01336b0ec015157d77370da387c2e3fa1dae0b9661545d0bc99635780541971",
                "md5": "02e539e59f239ef0208db4afb51128fb",
                "sha256": "72c1c6d1bf1d146a30edd3e9453226335cc4ef5102590b82398d335a43265934"
            },
            "downloads": -1,
            "filename": "kube_agent-0.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "02e539e59f239ef0208db4afb51128fb",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.10",
            "size": 31806,
            "upload_time": "2024-11-13T13:00:44",
            "upload_time_iso_8601": "2024-11-13T13:00:44.194495Z",
            "url": "https://files.pythonhosted.org/packages/c0/13/36b0ec015157d77370da387c2e3fa1dae0b9661545d0bc99635780541971/kube_agent-0.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "777b4af1df1bf29aca61faa048bfe69314ac075598a3d285be1389a7aa7b10de",
                "md5": "a2c3cb1d4291473d685077e5356d623d",
                "sha256": "1342185c9e4e27e35ecff07c688292081845add12acd6908496e8d7d4360acfc"
            },
            "downloads": -1,
            "filename": "kube_agent-0.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "a2c3cb1d4291473d685077e5356d623d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.10",
            "size": 29077,
            "upload_time": "2024-11-13T13:00:45",
            "upload_time_iso_8601": "2024-11-13T13:00:45.720499Z",
            "url": "https://files.pythonhosted.org/packages/77/7b/4af1df1bf29aca61faa048bfe69314ac075598a3d285be1389a7aa7b10de/kube_agent-0.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-13 13:00:45",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "feiskyer",
    "github_project": "kube-agent",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "kube-agent"
}
        
Elapsed time: 0.36513s