Questo documento descrive come eseguire l'autenticazione a Google Kubernetes Engine in modo programmatico. La modalità di autenticazione in Google Kubernetes Engine dipende dall'interfaccia utilizzata per accedere all'API e dall'ambiente in cui viene eseguito il codice.
L'API GKE ti consente di interagire con l'infrastruttura Google Cloud che esegue Kubernetes, come i cluster e i nodi GKE.
Per interagire con gli oggetti Kubernetes come pod e servizi, devi
autenticarti all'API Kubernetes, che è separata dall'API GKE e viene gestita dal server API Kubernetes in ogni cluster. Per istruzioni, consulta
Autenticarsi nel server dell'API Kubernetes.
Per accedere ad altre risorse Google Cloud come i bucket Cloud Storage
dai carichi di lavoro in esecuzione in GKE, utilizza
Workload Identity Federation for GKE.
Per saperne di più sull'autenticazione di Google Cloud , consulta la sezione
Metodi di autenticazione.
Accesso API
GKE supporta l'accesso programmatico. Puoi accedere all'API nei seguenti modi:
Le librerie client GKE forniscono
supporto linguistico di alto livello per l'autenticazione a GKE
in modo programmatico.
Per autenticare le chiamate alle API Google Cloud , le librerie client supportano le credenziali predefinite dell'applicazione (ADC); le librerie cercano le credenziali in un insieme di posizioni definite e le utilizzano per autenticare le richieste all'API. Con ADC, puoi rendere disponibili le credenziali alla tua applicazione in una serie di ambienti, ad esempio sviluppo locale o produzione, senza dover modificare il codice dell'applicazione.
Google Cloud CLI
Quando utilizzi gcloud CLI per accedere a GKE, accedi a gcloud CLI con un account utente, che fornisce le credenziali utilizzate dai comandi gcloud CLI.
Se i criteri di sicurezza della tua organizzazione impediscono agli account utente di disporre delle autorizzazioni richieste, puoi utilizzare l'impersonificazione del service account.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-09-04 UTC."],[],[],null,["# Authenticate to GKE\n\n[Autopilot](/kubernetes-engine/docs/concepts/autopilot-overview) [Standard](/kubernetes-engine/docs/concepts/choose-cluster-mode)\n\n*** ** * ** ***\n\n\nThis document describes how to authenticate to Google Kubernetes Engine programmatically. How\nyou authenticate to Google Kubernetes Engine depends on the interface you use to access the API\nand the environment where your code is running.\nThe GKE API lets you interact with the Google Cloud infrastructure that runs Kubernetes, like your GKE clusters and nodes.\n\n\u003cbr /\u003e\n\nTo interact with *Kubernetes objects* like Pods and Services, you must\nauthenticate to the Kubernetes API, which is separate to the\nGKE API and is served by the Kubernetes API server in each\ncluster. For instructions, see\n[Authenticate to the Kubernetes API server](/kubernetes-engine/docs/how-to/api-server-authentication).\n\nTo access other Google Cloud resources like Cloud Storage buckets\nfrom workloads running in GKE, use\n[Workload Identity Federation for GKE](/kubernetes-engine/docs/how-to/workload-identity).\n\n\nFor more information about Google Cloud authentication, see the\n[Authentication methods](/docs/authentication).\n\nAPI access\n----------\n\n\nGKE supports programmatic access. You can access the API in\nthe following ways:\n\n- [Client libraries](#client-libraries)\n- [Google Cloud CLI](#gcloud)\n- [REST](#rest)\n\n### Client libraries\n\n\nThe [GKE client libraries](/kubernetes-engine/docs/reference/libraries) provide\nhigh-level language support for authenticating to GKE\nprogrammatically.\n\n\nTo authenticate calls to Google Cloud APIs, client libraries support\n[Application Default Credentials (ADC)](/docs/authentication/application-default-credentials);\nthe libraries look for credentials in a set of defined locations and use those credentials\nto authenticate requests to the API. With ADC, you can make\ncredentials available to your application in a variety of environments, such as local\ndevelopment or production, without needing to modify your application code.\n\n### Google Cloud CLI\n\n\nWhen you use the [gcloud CLI](/sdk/gcloud/reference/container/clusters) to access\nGKE, you\n[log in to the gcloud CLI](/sdk/docs/authorizing) with a user\naccount, which provides the credentials used by the gcloud CLI commands.\n\n\nIf your organization's security policies prevent user accounts from having the required\npermissions, you can use [service account impersonation](#sa-impersonation).\n\nFor more information, see\n[Authenticate for using the gcloud CLI](/docs/authentication/gcloud).\nFor more information about using the gcloud CLI with GKE,\nsee [the gcloud CLI reference pages](/sdk/gcloud/reference/container/clusters).\n\n\n### REST\n\n\nYou can authenticate to\n[the GKE API](/kubernetes-engine/docs/reference/rest)\nby using your gcloud CLI credentials or by using\n[Application Default Credentials](/docs/authentication/application-default-credentials).\nFor more information about authentication for REST requests, see\n[Authenticate for using REST](/docs/authentication/rest).\nFor information about the types of credentials, see\n[gcloud CLI credentials and ADC credentials](/docs/authentication/gcloud#gcloud-credentials).\n\nWhat's next\n-----------\n\n- [Authenticate to the Kubernetes API server](/kubernetes-engine/docs/how-to/api-server-authentication).\n- [Use external identity providers to authenticate to GKE](/kubernetes-engine/docs/how-to/oidc).\n- [Authenticate to Google Cloud APIs from GKE using Workload Identity Federation for GKE](/kubernetes-engine/docs/how-to/workload-identity).\n- [Learn about access control in GKE and Kubernetes](/kubernetes-engine/docs/concepts/access-control).\n- [Learn about the GKE API and the Kubernetes API](/kubernetes-engine/docs/reference/api-organization).\n- Learn about [Google Cloud authentication methods](/docs/authentication#auth-decision-tree).\n- See a list of [authentication use cases](/docs/authentication/use-cases)."]]