Kubernetes client-go

Source: Internet
Author: User
Tags k8s kubernetes dashboard

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.