How can I view the config details of the current context in kubectl?
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
add a comment |
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
add a comment |
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
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
kubernetes kubectl
asked Nov 20 at 22:59
Chris Stryczynski
3,61052761
3,61052761
add a comment |
add a comment |
4 Answers
4
active
oldest
votes
kubectl config view --minify
displays only the current context
add a comment |
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.
add a comment |
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
add a comment |
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
kubectl config view --minify
displays only the current context
add a comment |
kubectl config view --minify
displays only the current context
add a comment |
kubectl config view --minify
displays only the current context
kubectl config view --minify
displays only the current context
answered Nov 20 at 23:41
Jordan Liggitt
6,8312522
6,8312522
add a comment |
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered Nov 20 at 23:47
andrewdotn
22.8k16597
22.8k16597
add a comment |
add a comment |
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
add a comment |
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
add a comment |
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
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
answered Nov 21 at 1:00
Rico
25.9k94864
25.9k94864
add a comment |
add a comment |
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
add a comment |
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
add a comment |
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
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
answered Nov 21 at 1:01
marvelTracker
1,8371938
1,8371938
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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