First, clone the kubectl-ai repository and build the Docker image from the
source code.
git clone https://github.com/GoogleCloudPlatform/kubectl-ai.git
cd kubectl-ai
docker build -t kubectl-ai:latest -f images/kubectl-ai/Dockerfile .To access a GKE cluster, kubectl-ai needs two configurations from your local
machine: Google Cloud credentials and a Kubernetes config file.
First, create Application Default Credentials
(ADC).
kubectl uses these credentials to authenticate with your GKE cluster.
gcloud auth application-default loginThis command saves your credentials into the ~/.config/gcloud directory.
Next, generate the kubeconfig file. This file tells kubectl which cluster
to connect to and to use your ADC credentials for authentication.
gcloud container clusters get-credentials <cluster-name> --location <location>This updates the configuration file at ~/.kube/config.
Finally, mount both configuration directories into the kubectl-ai container
when you run it. This example shows how to run kubectl-ai with a web
interface, mounting all necessary credentials and providing a Gemini API key.
export GEMINI_API_KEY="your_api_key_here"
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 webAlternatively with the default terminal ui:
export GEMINI_API_KEY="your_api_key_here"
docker run --rm -it \
-v ~/.kube:/root/.kube \
-v ~/.config/gcloud:/root/.config/gcloud \
-e GEMINI_API_KEY \
kubectl-ai:latest