|
| 1 | +# 1. Build the Docker Image |
| 2 | + |
| 3 | +First, clone the `kubectl-ai` repository and build the Docker image from the source code. |
| 4 | + |
| 5 | +```bash |
| 6 | +git clone https://github.com/GoogleCloudPlatform/kubectl-ai.git |
| 7 | +cd kubectl-ai |
| 8 | +docker build -t kubectl-ai:latest -f images/kubectl-ai/Dockerfile . |
| 9 | +``` |
| 10 | + |
| 11 | +# 2. Running against a GKE cluster |
| 12 | +To access a GKE cluster, `kubectl-ai` needs two configurations from your local machine: **Google Cloud credentials** and a **Kubernetes config file**. |
| 13 | + |
| 14 | +## Create Google Cloud Credentials |
| 15 | + |
| 16 | +First, create Application Default Credentials [(ADC)](https://cloud.google.com/docs/authentication/application-default-credentials). `kubectl` uses these credentials to authenticate with your GKE cluster. |
| 17 | + |
| 18 | +```bash |
| 19 | +gcloud auth application-default login |
| 20 | +``` |
| 21 | + |
| 22 | +This command saves your credentials into the `~/.config/gcloud` directory. |
| 23 | + |
| 24 | +## Configure `kubectl` |
| 25 | + |
| 26 | +Next, generate the `kubeconfig` file. This file tells `kubectl` which cluster to connect to and to use your ADC credentials for authentication. |
| 27 | + |
| 28 | +```bash |
| 29 | +gcloud container clusters get-credentials <cluster-name> --location <location> |
| 30 | +``` |
| 31 | + |
| 32 | +This updates the configuration file at `~/.kube/config`. |
| 33 | + |
| 34 | +# 3. Running the Container |
| 35 | + |
| 36 | +Finally, mount both configuration directories into the `kubectl-ai` container when you run it. |
| 37 | +This example shows how to run `kubectl-ai` with a web interface, mounting all necessary credentials and providing a Gemini API key. |
| 38 | + |
| 39 | +```bash |
| 40 | +export GEMINI_API_KEY="your_api_key_here" |
| 41 | +docker run --rm -it -p 8080:8080 -v ~/.kube:/root/.kube -v ~/.config/gcloud:/root/.config/gcloud -e GEMINI_API_KEY kubectl-ai:latest --ui-listen-address 0.0.0.0:8080 --ui-type web |
| 42 | +``` |
| 43 | + |
| 44 | +Alternativley with the default terminal ui: |
| 45 | + |
| 46 | +```bash |
| 47 | +export GEMINI_API_KEY="your_api_key_here" |
| 48 | +docker run --rm -it -v ~/.kube:/root/.kube -v ~/.config/gcloud:/root/.config/gcloud -e GEMINI_API_KEY kubectl-ai:latest |
| 49 | +``` |
0 commit comments