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

--kubeconfig arg doesn't work

Open mtaufen opened this issue 6 months ago • 3 comments

From help text:

--kubeconfig string                  path to kubeconfig file

But this tries to connect to port 8080, when my kind cluster is on port 40011:

$ kubectl-ai --kubeconfig ./kubeconfig "list namespaces in the cluster"
  Running: kubectl get namespaces


  I tried to list the namespaces in your cluster, but I encountered a         
  connection error. 😥                                                        
                                                                              
  It seems like  kubectl  is having trouble connecting to your Kubernetes     
  cluster. The error message is:                                              
                                                                              
    The connection to the server localhost:8080 was refused - did you specify 
  the right host or port?                                                     
                                                                              
  This could mean that:                                                       
                                                                              
  1. Your Kubernetes cluster is not currently running or accessible from where
  I'm trying to execute  kubectl .                                            
  2. Your  kubectl  configuration (e.g., KUBECONFIG environment variable or   
  ~/.kube/config  file) might not be pointing to the correct cluster or might 
  be misconfigured.                                                           
                                                                              
  Please ensure your Kubernetes cluster is running and your  kubectl  is      
  configured correctly to connect to it.                                      
                                                                              
  Once the connection is working, I'd be happy to list the namespaces for you!
  😊                                                                          

The kubeconfig file I have at ./kubeconfig:

apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: <REDACTED>
    server: https://127.0.0.1:40011
  name: kind-agent-cluster
contexts:
- context:
    cluster: kind-agent-cluster
    user: kind-agent-cluster
  name: kind-agent-cluster
current-context: kind-agent-cluster
kind: Config
preferences: {}
users:
- name: kind-agent-cluster
  user:
    client-certificate-data: <REDACTED>
    client-key-data: <REDACTED>

This is also the same config I have in ~/.kube/config, so it seems like the agent is ignoring my default kubeconfig as well.

mtaufen avatar Jun 14 '25 19:06 mtaufen

Looks like it uses the default kubeconfig if I omit the --kubeconfig arg, but still it'd be nice to be able to isolate it to a specific kubeconfig for use with the agent.

mtaufen avatar Jun 14 '25 20:06 mtaufen

Thanks for reporting. I think the issue is actually the relative path (i.e. running kubectl from a different directory), digging into it.

justinsb avatar Jun 15 '25 15:06 justinsb

Should we close it :-)

yankay avatar Jul 22 '25 10:07 yankay