%%
date:: [[2023-10-13]]
parent::
%%
# [[How to set up kubectl with GKE]]
[docs](https://cloud.google.com/kubernetes-engine/docs/how-to/cluster-access-for-kubectl)
Here's how to set up [[kubectl]] to work wtih [[Google Kubernetes Engine|GKE]] for [[Google Cloud Platform|GCP]].
### Enable the [[Google Kubernetes Engine|GKE]] API
[Click on this link](https://console.cloud.google.com/flows/enableapi?apiid=container.googleapis.com) and authenticate, and then follow the prompts to enable the GKE API.
### Install GCloud CLI
I recommend you install the GCloud CLI. It's optional, but it will help you manage GCloud permissions. [Download the relevant binary here](https://cloud.google.com/sdk/docs/install).
Extract the gzip file, `cd` to the directory you downloaded it too, and then run the installation:
```shell
./google-cloud-sdk/install.sh
```
Follow the instructions, and then initialize the GCloud API:
```shell
./google-cloud-sdk/bin/gcloud init
```
Restart your terminal window, and then confirm you can access gcloud commands by doing a `gcloud --version`.
### Install kubectl
If you don't already have [[kubectl]], install it via the GCloud CLI:
```shell
gcloud components install kubectl
```
Then verify that it's installed:
```shell
kubectl version
```
### Create cluster
### Install the GCloud kubectl auth plugin
Run the following command on the GCloud CLI:
```shell
gcloud components install gke-gcloud-auth-plugin
```
This command installs the `gke-gcloud-auth-plugin`.
[Click here for more details on this plugin and the authentication changes](https://cloud.google.com/blog/products/containers-kubernetes/kubectl-auth-changes-in-gke).
### Connect to the GCP cluster
From the [Google Cloud Console](https://console.cloud.google.com/), go to the cluster you want to connect to. Scroll to the right and click the three dots to open the menu, and then click *Connect*.
Copy the command under "Command-line access":
![[gcp-connect-to-the-cluster.png]]
It should look something like this:
```shell
gcloud container clusters get-credentials otel-demo --zone europe-central2-a --project dev-advocacy-380120
```
When you run the command on your terminal, you should get a message that says the kubeconfig entry has been generated:
```shell
Fetching cluster endpoint and auth data.
kubeconfig entry generated for otel-demo.
```
This step essentially adds the information to access the GCP cluster in kubeconfig as per [[kubectl#Add credentials to config]].