如何在Go中访问Kubernetes API并运行kubectl命令 [英] How to access the Kubernetes API in Go and run kubectl commands

查看:145
本文介绍了如何在Go中访问Kubernetes API并运行kubectl命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在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 (红帽开发人员倡导者)提出了

Michael Hausenblas (Developer Advocate at Red Hat) proposes in the comments documentations with using-client-go.cloudnative.sh

一些版本摘要,显示了如何使用client-go.

这篇关于如何在Go中访问Kubernetes API并运行kubectl命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆