How to switch kubectl clusters between gcloud and minikube

后端 未结 14 1152
再見小時候
再見小時候 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 20:05

    TL;DR: I created a GUI to switch Kubernetes contexts via AppleScript. I activate it via shift-cmd-x.

    I too had the same issue. It was a pain switching contexts by the command line. I used FastScripts to set a key combo (shift-cmd-x) to run the following AppleScript (placed in this directory: $(HOME)/Library/Scripts/Applications/Terminal).

    use AppleScript version "2.4" -- Yosemite (10.10) or later
    use scripting additions
    
    do shell script "/usr/local/bin/kubectl config current-context"
    set curcontext to result
    
    do shell script "/usr/local/bin/kubectl config get-contexts -o name"
    set contexts to paragraphs of result
    
    choose from list contexts with prompt "Select Context:" with title "K8s Context Selector" default items {curcontext}
    set scriptArguments to item 1 of result
    
    do shell script "/usr/local/bin/kubectl config use-context " & scriptArguments
    
    display dialog "Switched to " & scriptArguments buttons {"ok"} default button 1
    

提交回复
热议问题