如何在一个集群中执行 kubectl 命令。

3

我有两个集群

NAME                   LOCATION        MASTER_VERSION  MASTER_IP      MACHINE_TYPE   NODE_VERSION    NUM_NODES  STATUS
cassandra-cluster      europe-west4-a  1.14.10-gke.36  xx.90.xx.31    n1-standard-1  1.14.10-gke.36  3          RUNNING
codingjediweb-cluster  europe-west4-a  1.14.10-gke.36  uu.90.uu.182  n1-standard-1  1.14.10-gke.36  2          RUNNING
manuchadha25@cloudshell:~ (copper-frame-262317)$

我想在cassandra群集上运行以下命令。如何将cassandra群集设置为当前上下文?

我遇到了错误。

CASS_USER=$(kubectl --cluster gke_copper-frame-262317_europe-west4-a_cassandra-cluster get secret cluster1-superuser -o json | jq -r '.data.username' | base64 --decode)kubectl
Error from server (NotFound): secrets "cluster1-superuser" not found

我尝试了这个,但是失败了。

manuchadha25@cloudshell:~ (copper-frame-262317)$ kubectl config use-context cassandra-cluster 
error: no context exists with the name: "cassandra-cluster"
2个回答

2
您可以设置正确的上下文来处理多个集群,如此处所述:这里
kubectl config get-contexts                          # display list of contexts 
kubectl config current-context                       # display the current-context
kubectl config use-context my-cluster-name           # set the default context to my-cluster-name

在使用多个集群时,您总是需要知道正在哪个集群上执行命令,为了方便起见,您可以使用此 Bash 脚本$PS1 中显示当前上下文和名称空间。


0

我必须设置获取上下文,然后将上下文设置如下

manuchadha25@cloudshell:~ (copper-frame-262317)$ kubectl config get-contexts
CURRENT   NAME                                                           CLUSTER                                                        AUTHINFO                                                       NAMESPACE
          gke_copper-frame-262317_europe-west4-a_cassandra-cluster       gke_copper-frame-262317_europe-west4-a_cassandra-cluster       gke_copper-frame-262317_europe-west4-a_cassandra-cluster   
*         gke_copper-frame-262317_europe-west4-a_codingjediweb-cluster   gke_copper-frame-262317_europe-west4-a_codingjediweb-cluster   gke_copper-frame-262317_europe-west4-a_codingjediweb-cluster
manuchadha25@cloudshell:~ (copper-frame-262317)$ kubectl config use-context gke_copper-frame-262317_europe-west4-a_codingjediweb-cluster

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接