在pod内为命令kubectl定义/设置默认名称空间的地方 [英] Where the default namespace is defined/setup for command kubectl inside of a pod
问题描述
背景:Azure AKS中有群集A和群集B.创建一个名为 Agent 的Pod,在集群A中的命名空间 test (这是非默认命名空间)中运行linux容器.在linux容器中,安装了pwsh和kubectl.
Background: There are Cluster A and Cluster B in Azure AKS. Create a pod called Agent running linux container in cluster A in namespace test (which is non-default namespace). In the linux container, pwsh and kubectl are installed.
操作:进入集群A中的pod/Agent(kubectl exec -it pod/agent-bash),并获取集群B的凭据,将使用集群名称和用户名,但没有名称空间.
从pod/Agent连接到集群B时,然后执行 kubectl get pods
,将返回名称空间 test 中的资源,而不是名称空间 default 中的资源.>.
由于群集B中没有名为 test 的名称空间,因此不会返回任何资源.
Operation: Get into the pod/Agent in cluster A (kubectl exec -it pod/agent -- bash), and get-credential of Cluster B, configfile will be setup with cluster name and user name, but NO namespace.
When connect to cluster B from pod/Agent, then execute kubectl get pods
, the resource within namespace test is returned instead of the resources within namespace default.
Since, there is no namespace called test in cluster B, so no resource is returned.
因此,我想知道在Pod/Agent中将名称空间 test 定义/设置为默认名称空间的地方.
So I wonder where the namespace test is defined/setup in the pod/Agent as the default namespace.
花一些时间尝试在github中潜入kubectl代码,但是没有运气.
Spent some time try to dive in kubectl code in github, without luck..
我也尝试使用别名,但是它仅适用于bash/sh,不适用于pwsh,因为我不想更改命令名称kubectl,如果我使用别名kubectl ='kubectl -n default',则pwsh会陷入循环.
I also tried to use alias, but it only works for bash/sh, not for pwsh, since I don't want to change command name kubectl, if I do alias kubectl='kubectl -n default', pwsh would stuck into a loop.
任何答案都值得赞赏.