问题描述
我想在Go中访问我的Kubernetes集群API来运行kubectl
命令,以获取在Google云上运行的k8s集群中的可用名称空间.
I want to access my Kubernetes cluster API in Go to run kubectl
command to get available namespaces in my k8s cluster which is running on google cloud.
我的唯一目的是通过运行kubectl
命令在群集中获得可用的名称空间:请告知我是否还有其他选择.
My sole purpose is to get namespaces available in my cluster by running kubectl
command: kindly let me know if there is any alternative.
推荐答案
您可以从开始kubernetes/client-go
(Kubernetes的Go客户端)用于与kubernetes集群通信. (但不是通过kubectl:直接通过Kubernetes API)
You can start with kubernetes/client-go
, the Go client for Kubernetes, made for talking to a kubernetes cluster. (not through kubectl though: directly through the Kubernetes API)
它包括一个 NamespaceLister
,可帮助列出命名空间.
It includes a NamespaceLister
, which helps list Namespaces.
请参阅"使用Kubernetes API用Go "构建东西,来自 弗拉基米尔·维维恩
See "Building stuff with the Kubernetes API — Using Go" from Vladimir Vivien
Michael Hausenblas (红帽开发人员倡导者)提出了 using-client-go.cloudnative.sh
Michael Hausenblas (Developer Advocate at Red Hat) proposes in the comments documentations with using-client-go.cloudnative.sh
这篇关于如何在Go中访问Kubernetes API并运行kubectl命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!