おもむろに kubectl config get-contexts
を打つと
CURRENT NAME CLUSTER AUTHINFO NAMESPACE
gke_hogehoge-project2019_asia-east1-a_cluster-sugi-app gke_hogehoge-project2019_asia-east1-a_cluster-sugi-app gke_hogehoge-project2019_asia-east1-a_cluster-sugi-app sugi
gke_hogehoge-project2019_asia-east1-a_cluster-sugi2-app gke_hogehoge-project2019_asia-east1-a_cluster-sugi2-app gke_hogehoge-project2019_asia-east1-a_cluster-sugi2-app sugi2
gke_hogehoge-project2019_asia-east1-a_cluster-sugi3-app gke_hogehoge-project2019_asia-east1-a_cluster-sugi3-app gke_hogehoge-project2019_asia-east1-a_cluster-sugi3-app sugi3
* gke_hogehoge-project2019_asia-east1-a_cluster-sugi4-app gke_hogehoge-project2019_asia-east1-a_cluster-sugi4-app gke_hogehoge-project2019_asia-east1-a_cluster-sugi4-app
gke_fugafuga-project2018_asia-east1-a_hands-on gke_fugafuga-project2018_asia-east1-a_hands-on gke_fugafuga-project2018_asia-east1-a_hands-on
こんなことになって、長すぎて見づらいことがあります。これらのクラスタの名前とかは
~/.kube/config
に定義されていますのでこれを開きます。
こんなの(秘密にした方がよさげなところはマスクしてます)。WindowsでやってるのでWindowsのパスとかも入ってます。
apiVersion: v1
clusters:
- cluster:
certificate-authority-data: ひみつ
server: https://xx.xxx.xxx.xxx
name: gke_hogehoge-project2019_asia-east1-a_cluster-sugi-app
- cluster:
certificate-authority-data: ひみつ
server: https://xx.xxx.xxx.xx
name: gke_hogehoge-project2019_asia-east1-a_cluster-sugi2-app
- cluster:
certificate-authority-data: ひみつ
server: https://xx.xxx.xxx.xxx
name: gke_hogehoge-project2019_asia-east1-a_cluster-sugi3-app
- cluster:
certificate-authority-data: ひみつ
server: https://xx.xx.xxx.xx
name: gke_hogehoge-project2019_asia-east1-a_cluster-sugi4-app
- cluster:
certificate-authority-data: ひみつ
server: https://xx.xxx.xxx.xxx
name: gke_fugafuga-project2018_asia-east1-a_hands-on
contexts:
- context:
cluster: gke_hogehoge-project2019_asia-east1-a_cluster-sugi-app
namespace: sugi
user: gke_hogehoge-project2019_asia-east1-a_cluster-sugi-app
name: gke_hogehoge-project2019_asia-east1-a_cluster-sugi-app
- context:
cluster: gke_hogehoge-project2019_asia-east1-a_cluster-sugi2-app
namespace: sugi2
user: gke_hogehoge-project2019_asia-east1-a_cluster-sugi2-app
name: gke_hogehoge-project2019_asia-east1-a_cluster-sugi2-app
- context:
cluster: gke_hogehoge-project2019_asia-east1-a_cluster-sugi3-app
namespace: sugi3
user: gke_hogehoge-project2019_asia-east1-a_cluster-sugi3-app
name: gke_hogehoge-project2019_asia-east1-a_cluster-sugi3-app
- context:
cluster: gke_hogehoge-project2019_asia-east1-a_cluster-sugi4-app
user: gke_hogehoge-project2019_asia-east1-a_cluster-sugi4-app
name: gke_hogehoge-project2019_asia-east1-a_cluster-sugi4-app
- context:
cluster: gke_fugafuga-project2018_asia-east1-a_hands-on
user: gke_fugafuga-project2018_asia-east1-a_hands-on
name: gke_fugafuga-project2018_asia-east1-a_hands-on
current-context: gke_hogehoge-project2019_asia-east1-a_cluster-sugi4-app
kind: Config
preferences: {}
users:
- name: gke_hogehoge-project2019_asia-east1-a_cluster-sugi-app
user:
auth-provider:
config:
access-token: ひみつ
cmd-args: config config-helper --format=json
cmd-path: C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\bin\gcloud.cmd
expiry: 2019-03-18 07:31:28
expiry-key: '{.credential.token_expiry}'
token-key: '{.credential.access_token}'
name: gcp
- name: gke_hogehoge-project2019_asia-east1-a_cluster-sugi2-app
user:
auth-provider:
config:
access-token: ひみつ
cmd-args: config config-helper --format=json
cmd-path: C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\bin\gcloud.cmd
expiry: 2019-03-18 09:48:26
expiry-key: '{.credential.token_expiry}'
token-key: '{.credential.access_token}'
name: gcp
- name: gke_hogehoge-project2019_asia-east1-a_cluster-sugi3-app
user:
auth-provider:
config:
access-token: ひみつ
cmd-args: config config-helper --format=json
cmd-path: C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\bin\gcloud.cmd
expiry: 2019-04-03 01:30:32
expiry-key: '{.credential.token_expiry}'
token-key: '{.credential.access_token}'
name: gcp
- name: gke_hogehoge-project2019_asia-east1-a_cluster-sugi4-app
user:
auth-provider:
config:
access-token: ひみつ
cmd-args: config config-helper --format=json
cmd-path: C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\bin\gcloud.cmd
expiry: 2019-04-03T02:32:11Z
expiry-key: '{.credential.token_expiry}'
token-key: '{.credential.access_token}'
name: gcp
- name: gke_fugafuga-project2018_asia-east1-a_hands-on
user:
auth-provider:
config:
access-token: ひみつ
cmd-args: config config-helper --format=json
cmd-path: C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\bin\gcloud.cmd
expiry: 2019-03-15 10:02:27
expiry-key: '{.credential.token_expiry}'
token-key: '{.credential.access_token}'
name: gcp
これをみると、クラスタにローカル名を付けて、それをコンテキストで参照してコンテキストにもローカル名を付けて、などで結びついてることが分かります。
たとえばこれを gke_hogehoge-project2019_asia-east1-a_ を削除するように一括置換すると
kubectl config get-contexts
を打つと
CURRENT NAME CLUSTER AUTHINFO NAMESPACE
cluster-sugi-app cluster-sugi-app cluster-sugi-app sugi
cluster-sugi2-app cluster-sugi2-app cluster-sugi2-app sugi2
cluster-sugi3-app cluster-sugi3-app cluster-sugi3-app sugi3
* cluster-sugi4-app cluster-sugi4-app cluster-sugi4-app
gke_fugafuga-project2018_asia-east1-a_hands-on gke_fugafuga-project2018_asia-east1-a_hands-on gke_fugafuga-project2018_asia-east1-a_hands-on
こんな感じになって見やすくなります。
一括置換のときはまちがってconfigの別の必要な項目を誤置換しないように長めの文言でやるように気をつけましょう。