This document describes how to authenticate to Google Kubernetes Engine programmatically. How
you authenticate to Google Kubernetes Engine depends on the interface you use to access the API
and the environment where your code is running.
The GKE API lets you interact with the Google Cloud infrastructure that runs Kubernetes, like your GKE clusters and nodes.

<br />

To interact with *Kubernetes objects* like Pods and Services, you must
authenticate to the Kubernetes API, which is separate to the
GKE API and is served by the Kubernetes API server in each
cluster. For instructions, see
[Authenticate to the Kubernetes API server](https://docs.cloud.google.com/kubernetes-engine/docs/how-to/api-server-authentication.md.txt).

To access other Google Cloud resources like Cloud Storage buckets
from workloads running in GKE, use
[Workload Identity Federation for GKE](https://docs.cloud.google.com/kubernetes-engine/docs/how-to/workload-identity.md.txt).


For more information about Google Cloud authentication, see the
[Authentication methods](https://docs.cloud.google.com/docs/authentication.md.txt).

## API access


GKE supports programmatic access. You can access the API in
the following ways:

- [Client libraries](https://docs.cloud.google.com/kubernetes-engine/docs/authentication.md.txt#client-libraries)
- [Google Cloud CLI](https://docs.cloud.google.com/kubernetes-engine/docs/authentication.md.txt#gcloud)
- [REST](https://docs.cloud.google.com/kubernetes-engine/docs/authentication.md.txt#rest)

### Client libraries


The [GKE client libraries](https://docs.cloud.google.com/kubernetes-engine/docs/reference/libraries.md.txt) provide
high-level language support for authenticating to GKE
programmatically.


To authenticate calls to Google Cloud APIs, client libraries support
[Application Default Credentials (ADC)](https://docs.cloud.google.com/docs/authentication/application-default-credentials.md.txt);
the libraries look for credentials in a set of defined locations and use those credentials
to authenticate requests to the API. With ADC, you can make
credentials available to your application in a variety of environments, such as local
development or production, without needing to modify your application code.

### Google Cloud CLI


When you use the [gcloud CLI](https://docs.cloud.google.com/sdk/gcloud/reference/container/clusters) to access
GKE, you authenticate to Google Cloud as a principal, which
provides the credentials used by the gcloud CLI commands.


If your organization's security policies prevent user accounts from having the required
permissions, you can use [service account impersonation](https://docs.cloud.google.com/kubernetes-engine/docs/authentication.md.txt#sa-impersonation).

For more information, see
[Authenticate for the gcloud CLI](https://docs.cloud.google.com/sdk/docs/authenticate.md.txt).
For more information about using the gcloud CLI with GKE,
see [the gcloud CLI reference pages](https://docs.cloud.google.com/sdk/gcloud/reference/container/clusters).


### REST


You can authenticate to
[the GKE API](https://docs.cloud.google.com/kubernetes-engine/docs/reference/rest.md.txt)
by using your [gcloud CLI credentials](https://docs.cloud.google.com/sdk/docs/authenticate.md.txt) or by
using
[Application Default Credentials](https://docs.cloud.google.com/docs/authentication/application-default-credentials.md.txt). For more information about authentication for REST
requests, see [Authenticate for using REST](https://docs.cloud.google.com/docs/authentication/rest.md.txt).

## What's next

- [Authenticate to the Kubernetes API server](https://docs.cloud.google.com/kubernetes-engine/docs/how-to/api-server-authentication.md.txt).
- [Use external identity providers to authenticate to GKE](https://docs.cloud.google.com/kubernetes-engine/docs/how-to/oidc.md.txt).
- [Authenticate to Google Cloud APIs from GKE using Workload Identity Federation for GKE](https://docs.cloud.google.com/kubernetes-engine/docs/how-to/workload-identity.md.txt).
- [Learn about access control in GKE and Kubernetes](https://docs.cloud.google.com/kubernetes-engine/docs/concepts/access-control.md.txt).
- [Learn about the GKE API and the Kubernetes API](https://docs.cloud.google.com/kubernetes-engine/docs/reference/api-organization.md.txt).
- Learn about [Google Cloud authentication methods](https://docs.cloud.google.com/docs/authentication.md.txt#auth-decision-tree).
- See a list of [authentication use cases](https://docs.cloud.google.com/docs/authentication/use-cases.md.txt).