Go clients for talking to a Kubernetes cluster
open sourceApache-2.0self-hostablefree
client-go is the official Go client library for the Kubernetes API, maintained by Kubernetes SIG API Machinery and published from the main Kubernetes repository. It has a typed clientset for the built-in APIs, a dynamic client for any resource, discovery, kubeconfig and in-cluster configuration, authentication plugins, and the building blocks controllers use: informers and listers (tools/cache), work queues, an event recorder, port forwarding and exec. Its tools/leaderelection package lets replicas of a service elect one leader through a Lease object in the cluster, with callbacks when a replica starts or stops leading; the package says it doesn't guarantee a single leader (no fencing) and is an alpha API. Each v0.x.y tag matches Kubernetes v1.x.y.
Problems it solves
- call the Kubernetes API from my Go program
- only one replica of my Go service on Kubernetes should do the work at a time
- elect a leader among the pods of a deployment using a Kubernetes lease
- write a Kubernetes controller in Go that watches resources and reacts to changes
- cache Kubernetes objects locally and get notified when they change instead of polling the API
- read a kubeconfig or the in-cluster service account to connect to a cluster from Go
- work with custom resources from Go without generated types
- emit Kubernetes events from my Go operator
- port-forward or exec into a pod programmatically from Go
- test Go code that talks to Kubernetes with a fake clientset
Features
- typed clientset for the Kubernetes API (kubernetes package)
- dynamic client for arbitrary resources, metadata client and discovery
- informers, listers and the tools/cache package for controllers
- rate-limited work queues (util/workqueue)
- leader election with Lease locks (tools/leaderelection)
- event recorder (tools/record, tools/events)
- kubeconfig loading (tools/clientcmd) and in-cluster config (rest)
- authentication plugins, including exec credential providers
- apply configurations for server-side apply
- port forwarding and remote command execution
View 2 more
- fake clientsets for tests
- v0.x.y tags matching each Kubernetes v1.x.y release
Limitations
- Doesn't guarantee a single leader in its leader election package: it does no fencing, and the package is marked as an alpha API1
- Doesn't promise compatible Go APIs between releases: its v0.x.y tags mean the APIs may change in incompatible ways2
Capabilities
| Takes plugins | plan not known |
|---|
