GitHub Address: Https://github.com/kubernetes/client-go
There are several ways to access the Kubernetes cluster:
Way |
features |
supporters |
Kubernetes Dashboard |
operate directly from the Web UI, simple and straightforward, with a low level of customization |
Official support |
Kubectl |
command-line operation, the most complete, but more complex, suitable for further sub-assembly, custom features, version adaptation of the best |
Official support |
Client-go |
Pull out of the client package from the Kubernetes code, easy to use, but careful to differentiate the Kubernetes API version |
Official support |
Client-python |
Python client, Kubernetes-incubator |
Official support |
Java Client |
Part of the FABRIC8, the kubernetes Java client |
Redhat |
To get the deployment list using Client-go:
Package MainImport ( "Path/filepath" "K8s.io/client-go/tools/clientcmd" "k8s.io/client-go/kubernetes" "k8s.io/apimachinery/pkg/apis/meta/v1" "FMT"Func Main () {path, err:= FilePath. Abs ("./") ifErr! =Nil {panic (err)} ConfigFilePath:= Path +"/k8s/api/config"//Use the Config file config, err:= Clientcmd. Buildconfigfromflags ("", ConfigFilePath)ifErr! =Nil {panic (err. Error ())}Newforconfig creates a new Clientset forThe given config. Clientset, err:=kubernetes. Newforconfig (config)ifErr! =Nil {panic (err. Error ())}Get all Deploymentinchdefault Namespace Deploymentlist, err:= Clientset.appsv1 (). Deployments ("default"). List (v1. listoptions{})ifErr! =Nil {panic (err. Error ())}//PrintList Deployment Name andReplicas for_, V: =range Deploymentlist.items {fmt. Printf ("*%s (%d replicas) \ n", V.name, *V.spec.replicas)}}
View Code
Kubernetes client-go