How to switch kubectl clusters between gcloud and minikube

后端 未结 14 1129
再見小時候
再見小時候 2021-01-29 19:01

I have Kubernetes working well in two different environments, namely in my local environment (MacBook running minikube) and as well as on Google\'s Container Engine (GCE, Kubern

14条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-29 19:42

    In case you might be looking for a simple way to switch between different contexts maybe this will be of help.

    I got inspired by kubectx and kswitch scripts already mentioned, which I can recommend for most use-cases. They are helping with solving the switching task, but are breaking for me on some bigger or less standard configurations of ~/.kube/config. So I created a sys-exec invocation wrapper and a short-hand around kubectl.

    If you call k without params you would see an intercepted prompt to switch context.

    Switch kubectl to a different context/cluster/namespace.
    Found following options to select from:
     >>> context: [1] franz
     >>> context: [2] gke_foo_us-central1-a_live-v1
     >>> context: [3] minikube
     --> new num [?/q]:
    

    Further, k continues to act as a short-hand. The following is equivalent:

    kubectl get pods --all-namespaces
    k get pods -A
    k p -A
    

提交回复
热议问题