kubectl-ai icon indicating copy to clipboard operation
kubectl-ai copied to clipboard

~/.kube/config is not used ?

Open mattn opened this issue 6 months ago • 7 comments
trafficstars

I'm using Oracle Cloud Kubernetes (OKI). OKI can be accessed with oci cli command.

https://docs.oracle.com/en-us/iaas/Content/ContEng/Tasks/contengdownloadkubeconfigfile.htm

In such a configuration, kubectl-ai apparently does not execute the command. kubectl-ai reply nothing for kubectl commands.

mattn avatar May 05 '25 13:05 mattn

+1

nrv-96 avatar May 05 '25 13:05 nrv-96

I am wondering if this was due to bug that got fixed in this PR https://github.com/GoogleCloudPlatform/kubectl-ai/pull/126

@mattn can you try with the latest release ?

droot avatar May 05 '25 18:05 droot

Unfortunately, does not work correctly. I guess kubectl-ai does not spawn kubectl. This use kubernetes APIs instead of executing kubectl, right?

mattn avatar May 06 '25 10:05 mattn

kubectl-ai uses kubernetes APIs here.

https://github.com/GoogleCloudPlatform/kubectl-ai/blob/7b155dc6b791a3c0d20593d867cddafcbc4606a0/kubectl-utils/pkg/kube/client.go#L44-L60

mattn avatar May 06 '25 12:05 mattn

Confirming that kubectl-ai invokes kubectl command under the hood. It doesn't call the kubernetes APIs. kubectl-utils (the snippet above) is being used for different purpose (k8s-bench).

About kubeconfig:

  1. If not specified, it will default to ~/.kube/config
  2. you can specify --kubeconfig and point to path
  3. env variable KUBECONFIG.

I tried the following in my setup and seems to be working fine:

$ ./kubectl-ai --kubeconfig ~/.kube/config --quiet "list pods in the cluster"
  Running: kubectl get pods


  The following pods are running in the cluster:

  • nginx-5869d7778c-fttkf
  • nginx-5869d7778c-tmj4n
  • nginx-5869d7778c-tqhfw
  • nginx-5869d7778c-xkd8f

$ ./kubectl-ai --quiet "list pods in the cluster"
  Running: kubectl get pods


  The following pods are running in your cluster:

  • nginx-5869d7778c-fttkf
  • nginx-5869d7778c-tmj4n
  • nginx-5869d7778c-tqhfw
  • nginx-5869d7778c-xkd8f

  All pods are in a  Running  state and have 1/1 ready containers. No pods have
  been restarted. The age of the pods varies from 16 hours to 4 days and 17 hours.

@mattn can you share what error you are getting.

droot avatar May 06 '25 19:05 droot

kubectl-ai --kubeconfig ~/.kube/config --quiet "list pods in the cluster"
  Running: kubectl get pods

  Running: kubectl get pods --all-namespaces


  There are no pods in your cluster. Is there anything else I can help you with?

mattn avatar May 07 '25 00:05 mattn

That is strange.

kubectl-ai logs by default in /tmp/kubectl-ai.log. It also logs detailed trace in /tmp/kubectl-ai-trace.txt (if using latest release) else trace.txt (directory where it was invoked).

Those two files may contain information about what really happened. Would be great if you can take a look at those two files and see if anything interesting.

droot avatar May 07 '25 04:05 droot