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.
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.
So I wonder where the namespace test is defined/setup in the pod/Agent as the default namespace.
Spent some time try to dive in kubectl code in github, without luck..
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.
Any answer is appreciated.
question from:
https://stackoverflow.com/questions/65941558/where-the-default-namespace-is-defined-setup-for-command-kubectl-inside-of-a-pod 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…