如何获取集群内Go Kubernetes客户端的当前名​​称空间 [英] How to get current namespace of an in-cluster go Kubernetes client

查看:75
本文介绍了如何获取集群内Go Kubernetes客户端的当前名​​称空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用kubernetes client-go API获取部署/服务的当前名称空间?它似乎不在客户端对象或配置中.

How do I get the current namespace of a deployment/service using the kubernetes client-go API? It doesn't seem to be in the client object or in the config.

推荐答案

使用

ioutil.ReadFile("/var/run/secrets/kubernetes.io/serviceaccount/namespace")

inClusterClientConfigNamespace()方法中存在所需的实现时,

可以工作,但是很难看.但是如何从rest.InClusterConfig()开始获取该对象?只能从包外部通过NewNonInteractiveDeferredLoadingClientConfig实例化.

works but is ugly, when the desired implementation is present in the Namespace() method of inClusterClientConfig. But how would you get that object starting from rest.InClusterConfig()? It is only instantiable from outside the package via NewNonInteractiveDeferredLoadingClientConfig.

我看到了 kubernetes#63707 ,它看起来很相关但被放弃了.

I see kubernetes #63707 which looks related but was abandoned.

这篇关于如何获取集群内Go Kubernetes客户端的当前名​​称空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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