Kubernetes client go couldn't find module
Asked Answered
H

1

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/[email protected]+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.

Hartwig answered 30/8, 2020 at 8:19 Comment(2)
try go mod downloadTippets
@Tippets noo, it didn't worked, look at the error :), its pointing to a package that does not exist :/Hartwig
U
23

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
    ...
)
Unexceptionable answered 30/8, 2020 at 9:7 Comment(6)
Where exactly am I supposed to make changes?.Hartwig
I have updated the answer with the correct go.mod file..just copy itUnexceptionable
Thanks Arghya, this worked, now I can connect my k8s client with my minikibe cluster :)Hartwig
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)Hartwig
Try this examole..if you face issue please ask a new question github.com/kubernetes/client-go/blob/master/examples/…Unexceptionable
Thanks for posting the workaround. This saved me few hours in troubleshooting whats going on!Arbitral

© 2022 - 2024 — McMap. All rights reserved.