LoginSignup
5
4

More than 5 years have passed since last update.

GKEでclusterに繋ぐためのクライアント証明書と秘密鍵を取得する

Last updated at Posted at 2017-04-13

tl;dr

gcloud container clusters describe ${cluster_name} --project=${project} \
  --zone ${zone} \
  --format 'value(masterAuth.clientCertificate)'  |  base64 -d > client.pem

gcloud container clusters describe ${cluster_name} --project=${project} \
  --zone ${zone} \
  --format 'value(masterAuth.clientKey)'  |  base64 -d > key.rsa

gcloud container clusters describe ${cluster_name} --project=${project} \
  --zone ${zone} \
  --format 'value(masterAuth.clusterCaCertificate)'  |  base64 -d > ca.pem

# 繋がる
kubectl get pod --server https://xxx.xxx.xxx.xxx \
  --client-certificate=./client.pem  \
  --client-key=./key.rsa \
  --certificate-authority=ca.pem


殆どの場合gcloudで認証情報を取得すればいい、もしくはgcpメタデータ認証とか使えば問題ない

$ gcloud container clusters get-credentials $cluster_name

いいんだけど、ごくたまに証明書を指定して認証したい時がある(jenkinsとかで別Projectのclusterにつなぎたいとか)
で、証明書ってどうやって取るんだっけ?って毎回忘れる

gcloud container clusters describe で取れることまでは思い出せるんだけど
これがbase64されてることをマジで忘れる。
ドキュメントにもちゃんと書いてあるんだけどこのドキュメント到達するの結構大変

と、いうわけでbase64でdecodeする

gcloud container clusters describe ${cluster_name} \
  --project=${project} \
  --zone ${zone} \
  --format 'value(masterAuth.clientKey)'  |  base64 -d > key.rsa
5
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
4