A versioned collection of snippets showing how to use client-go.
client-go
is a bunch of Go packages enabling you to programmatically interact with a Kubernetes cluster.
Quick links | client-go
Go docs | client-go
repo | 1.7 snippets
Table of Contents:
- Prerequisites
- Using
client-go
with Kubernetes 1.7 - Using
client-go
with Kubernetes 1.6 - Using
client-go
with Kubernetes 1.5 - Related
The snippets shown here have been tested using Go 1.8 and should also work with Go 1.9 (not tested, yet).
In order to manage dependencies (aka vendoring in Go) we use Go dep.
If you don't have Go dep
installed yet, simply do the following:
$ go get -u github.com/golang/dep/cmd/dep
$ dep init # only the first time if no Gopkg.* exist in the project
$ dep ensure # every time you add/change dependencies
Note that if you're new to Go dep and/or dependency management, you might want to read Using Go dep as a project maintainer before you proceed.
Note also, if you want to contribute a snippet, we're using Bats for testing.
The snippets assume that you have a Kubernetes cluster running. You can, for example, install Minikube or Minishift to test it locally.
To enjoy all the snippets, do the following now:
$ mkdir -p $GOPATH/src/mhausenblas && cd $GOPATH/src/mhausenblas
$ git clone https://github.com/mhausenblas/using-client-go.git
Once you're using one or more of the snippets, that is, you have imports that reference one or more client-go
packages, use the following in your Gopkg.toml
file. Add it if it doesn't exist, otherwise update it:
[[constraint]]
name = "k8s.io/client-go"
version = "v4.0.0"
[[constraint]]
name = "k8s.io/apimachinery"
branch = "release-1.7"
After you've updated your Gopkg.toml
file, do dep ensure
and commit it to your repo.
Now you can move on to the Kubernetes 1.7 snippets.
Once you're using one or more of the snippets, that is, you have imports that reference one or more client-go
packages, use the following in your Gopkg.toml
file. Add it if it doesn't exist, otherwise update it:
[[constraint]]
name = "k8s.io/client-go"
version = "v3.0.0"
[[override]]
name = "k8s.io/apimachinery"
branch = "release-1.6"
After you've updated your Gopkg.toml
file, do dep ensure
and commit it to your repo.
TBD
Resources available on the Web around the 'using client-go' topic:
- client-go Examples from the official repo
- Using Kubernetes Go Client to Launch a Jupyter Notebook 12/2016
- Using the Kubernetes Client for Go 11/2016
- StackOverflow How can I create a simple client app with the Kubernetes Go library?
Related artifacts and activities:
- SIG API Machinery
- kubernetes/apimachinery
- kubernetes/metrics
- kubernetes/code-generator which is currently empty, see this PR for the status