簡體   English   中英

如何在集群中執行 kubectl 命令

[英]How to execute kubectl command in a cluster

我有兩個集群

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-cluster 上運行以下命令。 如何使 cassandra-cluster 成為我當前的上下文?

我收到錯誤

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"

您可以使用多個集群設置正確的上下文,如此所述:

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中顯示當前上下文和命名空間。

我必須設置獲取上下文,然后設置上下文如下

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM