Connect local instance of kubectl to GKE cluster without using gcloud tool?

后端 未结 3 706
猫巷女王i
猫巷女王i 2021-02-05 21:24

Does anyone know how to connect a local instance of kubectl to a Google Kubernetes Engine (GKE) cluster, without using the gcloud tool locally?

3条回答
  •  闹比i
    闹比i (楼主)
    2021-02-05 21:49

    The easiest way to achieve this is by copying the ~/.kube/config file (from a gcloud authenticated instance) to this directory $HOME/.kube in your local instance (laptop).

    But first, and using the authenticated instance, you would have to enable legacy cluster per this document by running these commands:

    gcloud config set container/use_client_certificate True
    export CLOUDSDK_CONTAINER_USE_CLIENT_CERTIFICATE=True
    

    Then execute the get-credentials command, and copy the file.

    gcloud container clusters get-credentials NAME [--zone=ZONE, -z ZONE] [GCLOUD_WIDE_FLAG …]
    

    Note that you may have to run the get-credentials command, and copy the config file every time authentication tokens (saved in the config file) expire.

提交回复
热议问题