We’ll now focus on the Kubernetes programming interface in Go. You’ll learn how to access the Kubernetes API of the well-known native types like pods, services, and deployment. In later chapters, these techniques will be extended to user-defined types. Here, though, we first concentrate on all API objects that are shipped with every Kubernetes cluster.
The Kubernetes project provides a number of third-party consumable Git repositories under the kubernetes organization on GitHub. You’ll need to import all of these with the domain alias k8s.io/… (not github.com/kubernetes/…) into your project. We’ll present the most important of these repositories in the following sections.
The Kubernetes programming interface in Go mainly consists of the k8s.io/client-go library (for brevity we will just call it
client-go going forward). client-go is a typical web service client library that supports all API types that are officially part of Kubernetes. It can be used to execute the usual REST verbs:
Each of these REST verbs are implemented using the “The HTTP Interface of the API Server”. Furthermore, the verb
Watch is supported, which is special for Kubernetes-like APIs, and one of the main differentiators compared to other APIs.