title: How can I toggle between kubernetes context of various deployed apps?
body: <p>When I deploy each app using kubernetes/cluster/kube-up.sh over aws I set context using :</p>
  
  <pre><code>CONTEXT=$(kubectl config view | grep current-context | awk '{print $2}')
  
  kubectl config set-context $CONTEXT --namespace=${PROJECT_ID}
  </code></pre>
  
  <p>I do this for multiple apps and each deploys fine.  However I then need to be able to toggle between kubernetes context to interact with an arbitrary deployed app (view logs/ do a kubectl exec )   </p>
  
  <p>Here is how to show all my contexts </p>
  
  <pre><code>kubectl config view --output=json
  
  {
      "kind": "Config",
      "apiVersion": "v1",
      "preferences": {},
      "clusters": [
          {
              "name": "aws_kubernetes",
              "cluster": {
                  "server": "https://52.87.88.888",
                  "certificate-authority-data": "REDACTED"
              }
          },
          {
              "name": "gke_primacyofdirectexperience_us-east1-b_loudhttpscluster",
              "cluster": {
                  "server": "https://104.196.888.888",
                  "certificate-authority-data": "REDACTED"
              }
          }
      ],
      "users": [
          {
              "name": "aws_kubernetes",
              "user": {
                  "client-certificate-data": "REDACTED",
                  "client-key-data": "REDACTED",
                  "token": "taklamakan"
              }
          },
          {
              "name": "aws_kubernetes-basic-auth",
              "user": {
                  "username": "admin",
                  "password": "retrogradewaif"
              }
          },
          {
              "name": "gke_primacyofdirectexperience_us-east1-b_loudhttpscluster",
              "user": {
                  "client-certificate-data": "REDACTED",
                  "client-key-data": "REDACTED",
                  "username": "admin",
                  "password": "emptyadjacentpossible"
              }
          }
      ],
      "contexts": [
          {
              "name": "aws_kubernetes",
              "context": {
                  "cluster": "aws_kubernetes",
                  "user": "aws_kubernetes",
                  "namespace": "ruptureofthemundaneplane"
              }
          },
          {
              "name": "gke_primacyofdirectexperience_us-east1-b_loudhttpscluster",
              "context": {
                  "cluster": "gke_primacyofdirectexperience_us-east1-b_loudhttpscluster",
                  "user": "gke_primacyofdirectexperience_us-east1-b_loudhttpscluster",
                  "namespace": "primacyofdirectexperience"
              }
          }
      ],
      "current-context": "aws_kubernetes"
  }
  </code></pre>
  
  <p>you can see in above I have deployed two apps ... when I try the obvious to choose my kubernetes context </p>
  
  <pre><code>kubectl config set-context  gke_primacyofdirectexperience_us-east1-b_loudhttpscluster  --namespace=${PROJECT_ID}
  
  ... outputs
  context "gke_primacyofdirectexperience_us-east1-b_loudhttpscluster" set.
  
  
  kubectl config set-cluster "gke_primacyofdirectexperience_us-east1-b_loudhttpscluster"
  
  ... outputs
  cluster "gke_primacyofdirectexperience_us-east1-b_loudhttpscluster" set.
  </code></pre>
  
  <p>it then just hangs when I issue commands like</p>
  
  <pre><code>kubectl describe pods --namespace=primacyofdirectexperience 
  </code></pre>
  
  <p>perhaps I am missing the command to also set user since in above json each deployed app gets its own user name ???</p>
  
  <p><strong><em>UPDATE</em></strong></p>
  
  <pre><code>kubectl config use-context gke_primacyofdirectexperience_us-east1-b_loudhttpscluster
  
  ... outputs
  switched to context "gke_primacyofdirectexperience_us-east1-b_loudhttpscluster".
  </code></pre>
  
  <p>however now when I issue any kubectl command ... for example</p>
  
  <pre><code>kubectl get pods 
  
  .... outputs
  Unable to connect to the server: x509: certificate signed by unknown authority
  </code></pre>
  
  <p>which is an error I have never seen before ... no doubt due to the toggle issue</p>
  
  <p>Even with above error message /kubernetes/cluster/kube-down.sh was able to teardown the cluster so there is hope toggling will work !</p>