How can I view the config details of the current context in kubectl?












1














I'd like to see the 'config' details as shown by the command of:



kubectl config view


However this shows the entire config details of all contexts, how can I filter it (or perhaps there is another command), to view the config details of the CURRENT context?










share|improve this question



























    1














    I'd like to see the 'config' details as shown by the command of:



    kubectl config view


    However this shows the entire config details of all contexts, how can I filter it (or perhaps there is another command), to view the config details of the CURRENT context?










    share|improve this question

























      1












      1








      1







      I'd like to see the 'config' details as shown by the command of:



      kubectl config view


      However this shows the entire config details of all contexts, how can I filter it (or perhaps there is another command), to view the config details of the CURRENT context?










      share|improve this question













      I'd like to see the 'config' details as shown by the command of:



      kubectl config view


      However this shows the entire config details of all contexts, how can I filter it (or perhaps there is another command), to view the config details of the CURRENT context?







      kubernetes kubectl






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 20 at 22:59









      Chris Stryczynski

      3,61052761




      3,61052761
























          4 Answers
          4






          active

          oldest

          votes


















          2














          kubectl config view --minify displays only the current context






          share|improve this answer





























            1














            The cloud-native way to do this is to use the JSON output of the command, then filter it with jq:



            kubectl config view -o json | jq '. as $o
            | ."current-context" as $current_context_name
            | $o.contexts | select(.name == $current_context_name) as $context
            | $o.clusters | select(.name == $context.context.cluster) as $cluster
            | $o.users | select(.name == $context.context.user) as $user
            | {"current-context-name": $current_context_name, context: $context, cluster: $cluster, user: $user}'

            {
            "current-context-name": "docker-for-desktop",
            "context": {
            "name": "docker-for-desktop",
            "context": {
            "cluster": "docker-for-desktop-cluster",
            "user": "docker-for-desktop"
            }
            },
            "cluster": {
            "name": "docker-for-desktop-cluster",
            "cluster": {
            "server": "https://localhost:6443",
            "insecure-skip-tls-verify": true
            }
            },
            "user": {
            "name": "docker-for-desktop",
            "user": {
            "client-certificate-data": "REDACTED",
            "client-key-data": "REDACTED"
            }
            }
            }


            This answer helped me figure out some of the jq bits.






            share|improve this answer





























              1














              The bash/kubectl with a little bit of jq, for any context equivalent:



              exec >/tmp/output &&
              CONTEXT_NAME=kubernetes-admin@kubernetes
              CONTEXT_CLUSTER=$(kubectl config view -o=jsonpath="{.contexts[?(@.name=="${CONTEXT_NAME}")].context.cluster}")
              CONTEXT_USER=$(kubectl config view -o=jsonpath="{.contexts[?(@.name=="${CONTEXT_NAME}")].context.user}") &&
              echo "[" &&
              kubectl config view -o=json | jq -j --arg CONTEXT_NAME "$CONTEXT_NAME" '.contexts | select(.name==$CONTEXT_NAME)' &&
              echo "," &&
              kubectl config view -o=json | jq -j --arg CONTEXT_CLUSTER "$CONTEXT_CLUSTER" '.clusters | select(.name==$CONTEXT_CLUSTER)' &&
              echo "," &&
              kubectl config view -o=json | jq -j --arg CONTEXT_USER "$CONTEXT_USER" '.users | select(.name==$CONTEXT_USER)' &&
              echo -e "n]n" &&
              exec >/dev/tty &&
              cat /tmp/output | jq &&
              rm -rf /tmp/output





              share|improve this answer





























                1














                You can use the command kubectl config view --minify to get current context only.



                It is handy to use --help to get the options what you could have for kubectl operations.



                kubectl config view --help





                share|improve this answer





















                  Your Answer






                  StackExchange.ifUsing("editor", function () {
                  StackExchange.using("externalEditor", function () {
                  StackExchange.using("snippets", function () {
                  StackExchange.snippets.init();
                  });
                  });
                  }, "code-snippets");

                  StackExchange.ready(function() {
                  var channelOptions = {
                  tags: "".split(" "),
                  id: "1"
                  };
                  initTagRenderer("".split(" "), "".split(" "), channelOptions);

                  StackExchange.using("externalEditor", function() {
                  // Have to fire editor after snippets, if snippets enabled
                  if (StackExchange.settings.snippets.snippetsEnabled) {
                  StackExchange.using("snippets", function() {
                  createEditor();
                  });
                  }
                  else {
                  createEditor();
                  }
                  });

                  function createEditor() {
                  StackExchange.prepareEditor({
                  heartbeatType: 'answer',
                  autoActivateHeartbeat: false,
                  convertImagesToLinks: true,
                  noModals: true,
                  showLowRepImageUploadWarning: true,
                  reputationToPostImages: 10,
                  bindNavPrevention: true,
                  postfix: "",
                  imageUploader: {
                  brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                  contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                  allowUrls: true
                  },
                  onDemand: true,
                  discardSelector: ".discard-answer"
                  ,immediatelyShowMarkdownHelp:true
                  });


                  }
                  });














                  draft saved

                  draft discarded


















                  StackExchange.ready(
                  function () {
                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53402872%2fhow-can-i-view-the-config-details-of-the-current-context-in-kubectl%23new-answer', 'question_page');
                  }
                  );

                  Post as a guest















                  Required, but never shown

























                  4 Answers
                  4






                  active

                  oldest

                  votes








                  4 Answers
                  4






                  active

                  oldest

                  votes









                  active

                  oldest

                  votes






                  active

                  oldest

                  votes









                  2














                  kubectl config view --minify displays only the current context






                  share|improve this answer


























                    2














                    kubectl config view --minify displays only the current context






                    share|improve this answer
























                      2












                      2








                      2






                      kubectl config view --minify displays only the current context






                      share|improve this answer












                      kubectl config view --minify displays only the current context







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Nov 20 at 23:41









                      Jordan Liggitt

                      6,8312522




                      6,8312522

























                          1














                          The cloud-native way to do this is to use the JSON output of the command, then filter it with jq:



                          kubectl config view -o json | jq '. as $o
                          | ."current-context" as $current_context_name
                          | $o.contexts | select(.name == $current_context_name) as $context
                          | $o.clusters | select(.name == $context.context.cluster) as $cluster
                          | $o.users | select(.name == $context.context.user) as $user
                          | {"current-context-name": $current_context_name, context: $context, cluster: $cluster, user: $user}'

                          {
                          "current-context-name": "docker-for-desktop",
                          "context": {
                          "name": "docker-for-desktop",
                          "context": {
                          "cluster": "docker-for-desktop-cluster",
                          "user": "docker-for-desktop"
                          }
                          },
                          "cluster": {
                          "name": "docker-for-desktop-cluster",
                          "cluster": {
                          "server": "https://localhost:6443",
                          "insecure-skip-tls-verify": true
                          }
                          },
                          "user": {
                          "name": "docker-for-desktop",
                          "user": {
                          "client-certificate-data": "REDACTED",
                          "client-key-data": "REDACTED"
                          }
                          }
                          }


                          This answer helped me figure out some of the jq bits.






                          share|improve this answer


























                            1














                            The cloud-native way to do this is to use the JSON output of the command, then filter it with jq:



                            kubectl config view -o json | jq '. as $o
                            | ."current-context" as $current_context_name
                            | $o.contexts | select(.name == $current_context_name) as $context
                            | $o.clusters | select(.name == $context.context.cluster) as $cluster
                            | $o.users | select(.name == $context.context.user) as $user
                            | {"current-context-name": $current_context_name, context: $context, cluster: $cluster, user: $user}'

                            {
                            "current-context-name": "docker-for-desktop",
                            "context": {
                            "name": "docker-for-desktop",
                            "context": {
                            "cluster": "docker-for-desktop-cluster",
                            "user": "docker-for-desktop"
                            }
                            },
                            "cluster": {
                            "name": "docker-for-desktop-cluster",
                            "cluster": {
                            "server": "https://localhost:6443",
                            "insecure-skip-tls-verify": true
                            }
                            },
                            "user": {
                            "name": "docker-for-desktop",
                            "user": {
                            "client-certificate-data": "REDACTED",
                            "client-key-data": "REDACTED"
                            }
                            }
                            }


                            This answer helped me figure out some of the jq bits.






                            share|improve this answer
























                              1












                              1








                              1






                              The cloud-native way to do this is to use the JSON output of the command, then filter it with jq:



                              kubectl config view -o json | jq '. as $o
                              | ."current-context" as $current_context_name
                              | $o.contexts | select(.name == $current_context_name) as $context
                              | $o.clusters | select(.name == $context.context.cluster) as $cluster
                              | $o.users | select(.name == $context.context.user) as $user
                              | {"current-context-name": $current_context_name, context: $context, cluster: $cluster, user: $user}'

                              {
                              "current-context-name": "docker-for-desktop",
                              "context": {
                              "name": "docker-for-desktop",
                              "context": {
                              "cluster": "docker-for-desktop-cluster",
                              "user": "docker-for-desktop"
                              }
                              },
                              "cluster": {
                              "name": "docker-for-desktop-cluster",
                              "cluster": {
                              "server": "https://localhost:6443",
                              "insecure-skip-tls-verify": true
                              }
                              },
                              "user": {
                              "name": "docker-for-desktop",
                              "user": {
                              "client-certificate-data": "REDACTED",
                              "client-key-data": "REDACTED"
                              }
                              }
                              }


                              This answer helped me figure out some of the jq bits.






                              share|improve this answer












                              The cloud-native way to do this is to use the JSON output of the command, then filter it with jq:



                              kubectl config view -o json | jq '. as $o
                              | ."current-context" as $current_context_name
                              | $o.contexts | select(.name == $current_context_name) as $context
                              | $o.clusters | select(.name == $context.context.cluster) as $cluster
                              | $o.users | select(.name == $context.context.user) as $user
                              | {"current-context-name": $current_context_name, context: $context, cluster: $cluster, user: $user}'

                              {
                              "current-context-name": "docker-for-desktop",
                              "context": {
                              "name": "docker-for-desktop",
                              "context": {
                              "cluster": "docker-for-desktop-cluster",
                              "user": "docker-for-desktop"
                              }
                              },
                              "cluster": {
                              "name": "docker-for-desktop-cluster",
                              "cluster": {
                              "server": "https://localhost:6443",
                              "insecure-skip-tls-verify": true
                              }
                              },
                              "user": {
                              "name": "docker-for-desktop",
                              "user": {
                              "client-certificate-data": "REDACTED",
                              "client-key-data": "REDACTED"
                              }
                              }
                              }


                              This answer helped me figure out some of the jq bits.







                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Nov 20 at 23:47









                              andrewdotn

                              22.8k16597




                              22.8k16597























                                  1














                                  The bash/kubectl with a little bit of jq, for any context equivalent:



                                  exec >/tmp/output &&
                                  CONTEXT_NAME=kubernetes-admin@kubernetes
                                  CONTEXT_CLUSTER=$(kubectl config view -o=jsonpath="{.contexts[?(@.name=="${CONTEXT_NAME}")].context.cluster}")
                                  CONTEXT_USER=$(kubectl config view -o=jsonpath="{.contexts[?(@.name=="${CONTEXT_NAME}")].context.user}") &&
                                  echo "[" &&
                                  kubectl config view -o=json | jq -j --arg CONTEXT_NAME "$CONTEXT_NAME" '.contexts | select(.name==$CONTEXT_NAME)' &&
                                  echo "," &&
                                  kubectl config view -o=json | jq -j --arg CONTEXT_CLUSTER "$CONTEXT_CLUSTER" '.clusters | select(.name==$CONTEXT_CLUSTER)' &&
                                  echo "," &&
                                  kubectl config view -o=json | jq -j --arg CONTEXT_USER "$CONTEXT_USER" '.users | select(.name==$CONTEXT_USER)' &&
                                  echo -e "n]n" &&
                                  exec >/dev/tty &&
                                  cat /tmp/output | jq &&
                                  rm -rf /tmp/output





                                  share|improve this answer


























                                    1














                                    The bash/kubectl with a little bit of jq, for any context equivalent:



                                    exec >/tmp/output &&
                                    CONTEXT_NAME=kubernetes-admin@kubernetes
                                    CONTEXT_CLUSTER=$(kubectl config view -o=jsonpath="{.contexts[?(@.name=="${CONTEXT_NAME}")].context.cluster}")
                                    CONTEXT_USER=$(kubectl config view -o=jsonpath="{.contexts[?(@.name=="${CONTEXT_NAME}")].context.user}") &&
                                    echo "[" &&
                                    kubectl config view -o=json | jq -j --arg CONTEXT_NAME "$CONTEXT_NAME" '.contexts | select(.name==$CONTEXT_NAME)' &&
                                    echo "," &&
                                    kubectl config view -o=json | jq -j --arg CONTEXT_CLUSTER "$CONTEXT_CLUSTER" '.clusters | select(.name==$CONTEXT_CLUSTER)' &&
                                    echo "," &&
                                    kubectl config view -o=json | jq -j --arg CONTEXT_USER "$CONTEXT_USER" '.users | select(.name==$CONTEXT_USER)' &&
                                    echo -e "n]n" &&
                                    exec >/dev/tty &&
                                    cat /tmp/output | jq &&
                                    rm -rf /tmp/output





                                    share|improve this answer
























                                      1












                                      1








                                      1






                                      The bash/kubectl with a little bit of jq, for any context equivalent:



                                      exec >/tmp/output &&
                                      CONTEXT_NAME=kubernetes-admin@kubernetes
                                      CONTEXT_CLUSTER=$(kubectl config view -o=jsonpath="{.contexts[?(@.name=="${CONTEXT_NAME}")].context.cluster}")
                                      CONTEXT_USER=$(kubectl config view -o=jsonpath="{.contexts[?(@.name=="${CONTEXT_NAME}")].context.user}") &&
                                      echo "[" &&
                                      kubectl config view -o=json | jq -j --arg CONTEXT_NAME "$CONTEXT_NAME" '.contexts | select(.name==$CONTEXT_NAME)' &&
                                      echo "," &&
                                      kubectl config view -o=json | jq -j --arg CONTEXT_CLUSTER "$CONTEXT_CLUSTER" '.clusters | select(.name==$CONTEXT_CLUSTER)' &&
                                      echo "," &&
                                      kubectl config view -o=json | jq -j --arg CONTEXT_USER "$CONTEXT_USER" '.users | select(.name==$CONTEXT_USER)' &&
                                      echo -e "n]n" &&
                                      exec >/dev/tty &&
                                      cat /tmp/output | jq &&
                                      rm -rf /tmp/output





                                      share|improve this answer












                                      The bash/kubectl with a little bit of jq, for any context equivalent:



                                      exec >/tmp/output &&
                                      CONTEXT_NAME=kubernetes-admin@kubernetes
                                      CONTEXT_CLUSTER=$(kubectl config view -o=jsonpath="{.contexts[?(@.name=="${CONTEXT_NAME}")].context.cluster}")
                                      CONTEXT_USER=$(kubectl config view -o=jsonpath="{.contexts[?(@.name=="${CONTEXT_NAME}")].context.user}") &&
                                      echo "[" &&
                                      kubectl config view -o=json | jq -j --arg CONTEXT_NAME "$CONTEXT_NAME" '.contexts | select(.name==$CONTEXT_NAME)' &&
                                      echo "," &&
                                      kubectl config view -o=json | jq -j --arg CONTEXT_CLUSTER "$CONTEXT_CLUSTER" '.clusters | select(.name==$CONTEXT_CLUSTER)' &&
                                      echo "," &&
                                      kubectl config view -o=json | jq -j --arg CONTEXT_USER "$CONTEXT_USER" '.users | select(.name==$CONTEXT_USER)' &&
                                      echo -e "n]n" &&
                                      exec >/dev/tty &&
                                      cat /tmp/output | jq &&
                                      rm -rf /tmp/output






                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Nov 21 at 1:00









                                      Rico

                                      25.9k94864




                                      25.9k94864























                                          1














                                          You can use the command kubectl config view --minify to get current context only.



                                          It is handy to use --help to get the options what you could have for kubectl operations.



                                          kubectl config view --help





                                          share|improve this answer


























                                            1














                                            You can use the command kubectl config view --minify to get current context only.



                                            It is handy to use --help to get the options what you could have for kubectl operations.



                                            kubectl config view --help





                                            share|improve this answer
























                                              1












                                              1








                                              1






                                              You can use the command kubectl config view --minify to get current context only.



                                              It is handy to use --help to get the options what you could have for kubectl operations.



                                              kubectl config view --help





                                              share|improve this answer












                                              You can use the command kubectl config view --minify to get current context only.



                                              It is handy to use --help to get the options what you could have for kubectl operations.



                                              kubectl config view --help






                                              share|improve this answer












                                              share|improve this answer



                                              share|improve this answer










                                              answered Nov 21 at 1:01









                                              marvelTracker

                                              1,8371938




                                              1,8371938






























                                                  draft saved

                                                  draft discarded




















































                                                  Thanks for contributing an answer to Stack Overflow!


                                                  • Please be sure to answer the question. Provide details and share your research!

                                                  But avoid



                                                  • Asking for help, clarification, or responding to other answers.

                                                  • Making statements based on opinion; back them up with references or personal experience.


                                                  To learn more, see our tips on writing great answers.





                                                  Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                                                  Please pay close attention to the following guidance:


                                                  • Please be sure to answer the question. Provide details and share your research!

                                                  But avoid



                                                  • Asking for help, clarification, or responding to other answers.

                                                  • Making statements based on opinion; back them up with references or personal experience.


                                                  To learn more, see our tips on writing great answers.




                                                  draft saved


                                                  draft discarded














                                                  StackExchange.ready(
                                                  function () {
                                                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53402872%2fhow-can-i-view-the-config-details-of-the-current-context-in-kubectl%23new-answer', 'question_page');
                                                  }
                                                  );

                                                  Post as a guest















                                                  Required, but never shown





















































                                                  Required, but never shown














                                                  Required, but never shown












                                                  Required, but never shown







                                                  Required, but never shown

































                                                  Required, but never shown














                                                  Required, but never shown












                                                  Required, but never shown







                                                  Required, but never shown







                                                  Popular posts from this blog

                                                  404 Error Contact Form 7 ajax form submitting

                                                  How to know if a Active Directory user can login interactively

                                                  TypeError: fit_transform() missing 1 required positional argument: 'X'