How to switch namespace in kubernetes

前端 未结 7 1412
半阙折子戏
半阙折子戏 2021-01-30 02:42

Say, I have two namespaces k8s-app1 and k8s-app2

I can list all pods from specific namespace using the below command

kubectl get pods -n 

        
7条回答
  •  说谎
    说谎 (楼主)
    2021-01-30 03:25

    A Solution

    npm install -g k8ss
    
    k8ss switch --namespace=your_namespace
    kubectl get pods
    

    TLDR; Explanation as requested

    There is a npm package called k8ss which stands for K8S Switching between clusters and namespaces.

    The full usage is

    k8ss switch --cluster=your_new_cluster --namespace=your_new_namespace
    

    As in your case, you only need to switch namespace, so you can use the command without any configuration (as you already put a config file in the ~/.kube/config).

    Advanced Usage

    If you need to switch between different clusters then you need to put multiple config files in your home directory. In this case you can go to the package README to learn more.

提交回复
热议问题