使用Config视图获得以下输出。注意否";当前上下文";
root@Bootstrap [ /etc ]# kubectl config view
apiVersion: v1
clusters:
- cluster:
certificate-authority-data: DATA+OMITTED
server: https://192.168.10.50:6443
name: tanzu-m01
contexts:
- context:
cluster: tanzu-m01
user: tanzu-m01-admin
name: tanzu-m01-admin@tanzu-m01
current-context: ""
kind: Config
preferences: {}
users:
- name: tanzu-m01-admin
user:
client-certificate-data: REDACTED
client-key-data: REDACTED
- name: tkgm-mgmt01-admin
user:
client-certificate-data: REDACTED
client-key-data: REDACTED
使用kubectl设置上下文>gt;显示上下文修改的
root@Bootstrap [ /etc ]# kubectl config set-context tanzu-m01-admin@tanzu-m01
Context "tanzu-m01-admin@tanzu-m01" modified.
然而,在";kubectl config当前上下文";显示当前上下文未设置
root@Bootstrap [ /etc ]# kubectl config current-context
error: current-context is not set
我错过了什么?
正确的命令是:
kubectl config use-context ${CONTEXT}
您可以通过以下方式确认:
kubectl config --help
set-context Set a context entry in kubeconfig
use-context Set the current-context in a kubeconfig file
kubectl config set-context
设置指定上下文的属性:
kubectl config set-context ${CONTEXT}
--cluster=${CLUSTER}
--user=user_${USER}
--namespace=${NAMESPACE}
下面将为您提供当前上下文
kubectl config set current-context
如果没有看到当前上下文,则搜索当前上下文
kubectl config get-contexts
现在你将有列表,现在你设置上下文
kubectl config set current-context <context-name>