...
1# Installing client-go
2
3## Using the latest version
4
5If you want to use the latest version of this library, use go1.16+ and run:
6
7```sh
8go get k8s.io/client-go@latest
9```
10
11This will record a dependency on `k8s.io/client-go` in your go module.
12You can now import and use the `k8s.io/client-go` APIs in your project.
13The next time you `go build`, `go test`, or `go run` your project,
14`k8s.io/client-go` and its dependencies will be downloaded (if needed),
15and detailed dependency version info will be added to your `go.mod` file
16(or you can also run `go mod tidy` to do this directly).
17
18## Using a specific version
19
20If you want to use a particular version of the `k8s.io/client-go` library,
21you can indicate which version of `client-go` your project requires:
22
23- If you are using Kubernetes versions >= `v1.17.0`, use a corresponding `v0.x.y` tag.
24 For example, `k8s.io/client-go@v0.20.4` corresponds to Kubernetes `v1.20.4`:
25
26```sh
27go get k8s.io/client-go@v0.20.4
28```
29
30- If you are using Kubernetes versions < `v1.17.0`, use a corresponding `kubernetes-1.x.y` tag.
31 For example, `k8s.io/client-go@kubernetes-1.16.3` corresponds to Kubernetes `v1.16.3`:
32
33```sh
34go get k8s.io/client-go@kubernetes-1.16.3
35```
36
37You can now import and use the `k8s.io/client-go` APIs in your project.
38The next time you `go build`, `go test`, or `go run` your project,
39`k8s.io/client-go` and its dependencies will be downloaded (if needed),
40and detailed dependency version info will be added to your `go.mod` file
41(or you can also run `go mod tidy` to do this directly).
42
43## Troubleshooting
44
45### Go versions prior to 1.16
46
47If you get a message like
48`module k8s.io/client-go@latest found (v1.5.2), but does not contain package k8s.io/client-go/...`,
49you are likely using a go version prior to 1.16 and must explicitly specify the k8s.io/client-go version you want.
50For example:
51```sh
52go get k8s.io/client-go@v0.20.4
53```
54
55### Conflicting requirements for older client-go versions
56
57If you get a message like
58`module k8s.io/api@latest found, but does not contain package k8s.io/api/auditregistration/v1alpha1`,
59something in your build is likely requiring an old version of `k8s.io/client-go` like `v11.0.0+incompatible`.
60
61First, try to fetch a more recent version. For example:
62```sh
63go get k8s.io/client-go@v0.20.4
64```
65
66If that doesn't resolve the problem, see what is requiring an `...+incompatible` version of client-go,
67and update to use a newer version of that library, if possible:
68```sh
69go mod graph | grep " k8s.io/client-go@"
70```
71
72As a last resort, you can force the build to use a specific version of client-go,
73even if some of your dependencies still want `...+incompatible` versions. For example:
74```sh
75go mod edit -replace=k8s.io/client-go=k8s.io/client-go@v0.20.4
76go get k8s.io/client-go@v0.20.4
77```
78
79### Go modules disabled
80
81If you get a message like `cannot use path@version syntax in GOPATH mode`,
82you likely do not have go modules enabled. This should be on by default in all
83supported versions of Go.
84
85```sh
86export GO111MODULE=on
87```
88
89Ensure your project has a `go.mod` file defined at the root of your project.
90If you do not already have one, `go mod init` will create one for you:
91
92```sh
93go mod init
94```
View as plain text