5

I'm trying to connect to my local Kubernetes cluster hosted on minikube, here's the code for the same, now when I do go run minikube.go, it gives me an error saying:

../../../pkg/mod/k8s.io/client-go@v11.0.0+incompatible/kubernetes/scheme/register.go:26:2: module k8s.io/api@latest found (v0.19.0), but does not contain package k8s.io/api/auditregistration/v1alpha1`.

Now, I tried to manually install the package using go get then I found out that this package does not exist. How can I make it work and fix this?. My go.mod file in case anyone wants to see that.

Arghya Sadhu
  • 41,002
  • 9
  • 78
  • 107
Rajat Singh
  • 653
  • 6
  • 15
  • 29

1 Answers1

22

Always specify matching versions of all three k8s.io/... components in your go.mod file

require (
    ...
    k8s.io/api v0.19.0
    k8s.io/apimachinery v0.19.0
    k8s.io/client-go v0.19.0
    ...
)
Arghya Sadhu
  • 41,002
  • 9
  • 78
  • 107
  • Where exactly am I supposed to make changes?. – Rajat Singh Aug 30 '20 at 09:25
  • 1
    I have updated the answer with the correct `go.mod` file..just copy it – Arghya Sadhu Aug 30 '20 at 09:29
  • Thanks Arghya, this worked, now I can connect my k8s client with my minikibe cluster :) – Rajat Singh Aug 30 '20 at 09:32
  • But @Arghya, it started to give me an error saying `./minikube.go:18:45: not enough arguments in call to clientset.CoreV1().Pods("").List have ("k8s.io/apimachinery/pkg/apis/meta/v1".ListOptions) want (context.Context, "k8s.io/apimachinery/pkg/apis/meta/v1".ListOptions)` – Rajat Singh Aug 30 '20 at 09:42
  • Try this examole..if you face issue please ask a new question https://github.com/kubernetes/client-go/blob/master/examples/out-of-cluster-client-configuration/main.go – Arghya Sadhu Aug 30 '20 at 10:24
  • Thanks for posting the workaround. This saved me few hours in troubleshooting whats going on! – Bhagya Prasad NR Jun 14 '21 at 20:53