Prepare and test your skills

Prepare and test your skills

Cluster authentication and kubeconfig configuration is the process that lets kubectl (opens in a new tab), the Kubernetes command-line tool, find and securely access a Google Kubernetes Engine (GKE) (opens in a new tab) cluster. The Google Cloud CLI retrieves the cluster endpoint and authentication data and writes it into the kubeconfig file. Kubectl then sends requests to the correct control plane with the correct Google identity.
A kubeconfig file is a YAML file that stores the connection and authentication information kubectl needs to reach clusters. The file is saved by default at $HOME/.kube/config and contains a list of contexts, where each context groups a Kubernetes cluster, a user, and a namespace. The current context is the default cluster for kubectl, so every kubectl command runs against that cluster unless a different target is specified. When kubectl runs, traffic flows from kubectl to the Kubernetes API server in the cluster control plane over TCP port 443. The kubeconfig supplies both sides of that connection by providing the endpoint address kubectl must reach and the credentials that prove who is making the request.
Checking existing kubeconfig access shows which clusters kubectl already knows about and which cluster is the default. The command kubectl config view returns the kubeconfig file and all contexts it contains, including every cluster with a generated entry. If the target GKE cluster is listed, kubectl can run commands against it in the current environment, and if it is not listed, a new kubeconfig entry must be generated. The command kubectl config current-context outputs the name of the current context that kubectl uses by default. The current context controls where requests go when no override is given, while the --cluster flag lets kubectl send one command to a specific cluster without changing the default.
Retrieving credentials with the Google Cloud CLI automatically populates the kubeconfig file with endpoint and authentication data. The get-credentials command contacts the GKE Multi-Cloud API, fetches the cluster endpoint, and adds a new context for that cluster to the local kubeconfig. After the command succeeds, kubectl uses the same Google identity that gcloud uses, such as the personal credentials from gcloud auth login. For GKE on AWS, the pattern is gcloud container aws clusters get-credentials CLUSTER_NAME --location GOOGLE_CLOUD_LOCATION. For GKE on Azure, the pattern is gcloud container azure clusters get-credentials CLUSTER_NAME --location GOOGLE_CLOUD_LOCATION. In both commands, CLUSTER_NAME is the cluster name and GOOGLE_CLOUD_LOCATION is the Google Cloud region or zone where the cluster is managed, and the credentials must include the userinfo.email OAuth scope so GKE can validate the user or service account email.
The connection path determines how traffic flows from kubectl to the cluster control plane. The recommended path is the Connect gateway, a Google-hosted reverse proxy where the gke-connect-agent Deployment in the cluster carries requests between Google and the control plane. The alternative path is a private endpoint, where kubectl sends requests directly to the private DNS name of the control plane inside the cloud virtual network. The two options differ in traffic flow and network requirements:
Workstation kubectl reaches the control-plane kube-apiserver on TCP 443 via two paths: recommended Connect gateway through Google and gke-connect-agent, or direct private ELB endpoint inside the VPC.
| Connection option | How kubectl traffic flows | Network requirement |
|---|---|---|
| Connect gateway | Traffic flows from kubectl to connectgateway.googleapis.com to the private endpoint through the agent | Cluster needs outbound connectivity to Google; no direct VPC route to the control plane is required |
| Private endpoint | Traffic flows from kubectl directly to the private control-plane endpoint, such as an ELB DNS name on AWS | Workstation needs routing to the control-plane endpoint in the AWS Virtual Private Cloud or Azure Virtual Network, and firewall rules may need to be widened |
With the Connect gateway, the kubeconfig endpoint looks like https://connectgateway.googleapis.com/v1/projects/PROJECT_NUMBER/memberships/CLUSTER_NAME. With a private endpoint, the kubeconfig points at the canonical private DNS name that is only resolvable inside the cluster network. Choose the Connect gateway when direct routing to the private control plane is not available, and choose the private endpoint only when VPC connectivity and routing already exist.
Exam tip: get-credentials uses the Connect gateway by default; use the private-endpoint variant only when you have direct VPC routing to the control-plane endpoint.
Authentication for kubectl defaults to Google identity, which requires no extra cluster configuration. By default, the GKE Multi-Cloud API grants the user who created the cluster Kubernetes role-based access control (RBAC) permission as clusterrole/cluster-admin, and that creator can add other users as admin users with full administrative access. The API also configures an impersonation policy that authorizes the Connect agent to send requests to the Kubernetes API server on behalf of an admin user. Once users are authenticated, they must also be authorized by both Google Cloud IAM and Kubernetes RBAC before they can act on the cluster. For kubectl access through the Connect gateway, an admin user who is not a project owner needs IAM roles in the project:
roles/gkehub.gatewayAdmin lets a user access the Connect gateway API for full management, with roles/gkehub.gatewayEditor for read and write access and roles/gkehub.gatewayReader for read-only accessroles/gkehub.viewer lets a user retrieve cluster kubeconfigs and view clusters outside Google Cloud in the consoleroles/container.viewer lets a user view the GKE Clusters page and other container resources in the Google Cloud consoleThe cluster admin remains responsible for Kubernetes RBAC authorization inside the cluster, so authenticated Google identities still need the appropriate cluster roles to perform actions on GKE resources.
Context management and connectivity verification is how you point kubectl (opens in a new tab), the Kubernetes command-line tool, at the right cluster and prove that it can reach and use that cluster. Kubectl reads connection details from a file called kubeconfig, and each saved connection is called a context. A successful resource request confirms both network connectivity to the control plane and authorization to act on the cluster.
Kubeconfig is a YAML file that stores cluster authentication information for kubectl, saved by default at $HOME/.kube/config. A context in kubeconfig is a group of access parameters that links together three things: a Kubernetes cluster, a user identity, and a namespace. The current context is the default cluster for kubectl, so every kubectl command runs against that cluster unless you override it. Traffic from kubectl flows to the cluster control plane, where the kube-apiserver listens on TCP port 443. Without a valid context, kubectl does not know which endpoint to reach or which identity to present.
Checking the current configuration shows which clusters kubectl knows about and which one is the default. The command kubectl config view lists all contexts and clusters with generated kubeconfig entries, and if a GKE cluster (opens in a new tab) appears in that output, kubectl can run commands against it in the current environment. The command kubectl config current-context outputs the name of the current context that kubectl will use. If the needed cluster is not listed, you must generate a kubeconfig entry with a gcloud container ... clusters get-credentials command before kubectl can connect. This check prevents sending commands to the wrong cluster or failing because no endpoint is configured.
Working with multiple clusters means either changing the default context or targeting one cluster for a single command. Running gcloud container azure clusters get-credentials CLUSTER_NAME --location GOOGLE_CLOUD_LOCATION or the equivalent AWS command adds that cluster to kubeconfig and switches the current context to it. For example, if the current context is cluster-2, running get-credentials for cluster-1 makes cluster-1 the new default for all later kubectl commands. To leave the default unchanged, run an individual command with the --cluster flag, such as kubectl get pod --cluster cluster-2, which sends only that request to cluster-2 using the name as it appears in kubeconfig. This separation lets you manage many clusters from one workstation without constantly rewriting the default.
Exam tip: Use get-credentials when you want to change the default context, and use --cluster CLUSTER_NAME when you want to query a different cluster without changing the default.
Verifying connectivity and authorization means running a read request against the cluster and confirming that it returns resources instead of a connection or permission error. A simple check such as kubectl get pod asks the kube-apiserver to list Pod objects, so a returned list proves that traffic reached the control plane and that the identity was authorized by Kubernetes RBAC. When access uses the Connect gateway, kubectl sends traffic to Google, the gke-connect-agent Deployment forwards it to the private control-plane endpoint, and the agent is authorized to impersonate an admin user to the API server. The connection path determines what network and permission setup is required:
| Connection option | Traffic path | Requirement |
|---|---|---|
| Connect gateway | Kubectl sends requests to Google, then the gke-connect-agent forwards them to the cluster control plane | User needs gateway and viewer IAM roles when not a project owner |
| Private endpoint | Kubectl sends requests directly to the private kube-apiserver endpoint in the virtual network | Workstation needs routing to the control-plane VPC and possibly widened firewall rules |
For Connect gateway access, an admin user who is not a project owner needs roles/gkehub.viewer to retrieve cluster kubeconfigs plus one gateway role for the level of access needed. Authentication reuses the Google Cloud identity from gcloud auth login, including the userinfo.email scope that GKE uses to identify the user, and then cluster RBAC must also authorize that user for the requested action.
roles/gkehub.gatewayAdmin gives full management access through the gatewayroles/gkehub.gatewayEditor gives read and write access to connected clustersroles/gkehub.gatewayReader gives read-only access to connected clustersInstallation and component integration is the process of setting up the Google Cloud CLI (opens in a new tab) on a local machine, adding the kubectl tool, and preparing both to communicate with Google Kubernetes Engine (GKE) services. The Google Cloud CLI, also called the gcloud CLI, provides the base gcloud commands for managing Google Cloud projects and clusters. The kubectl component adds Kubernetes cluster control, and initialization links the local environment to the correct account, project, and GKE services.
The Google Cloud CLI is the command-line toolkit that lets a local shell send requests to Google Cloud APIs and manage resources such as GKE clusters. On Linux, the archive installation follows an ordered workflow that places the tools on the system and adds them to the shell path. Before starting, confirm Python 3.10 to 3.15 is available and run uname -a to determine whether the x86_64, Arm, or x86 package is needed. The installation then proceeds in order:
curl -O https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-cli-linux-x86_64.tar.gz, replacing the file name with the package that matches the platform.tar -xf google-cloud-cli-linux-x86_64.tar.gz to create the google-cloud-sdk directory, deleting any existing directory first when replacing an installation../google-cloud-sdk/install.sh from the extracted folder and answer Y to add the gcloud CLI to PATH, enable command completion, and opt in to anonymous usage statistics.PATH was updated so the gcloud command is found in the new session.gcloud init to authorize the user account and configure the default project and location for later GKE commands.The installer can also run non-interactively with flags shown by ./google-cloud-sdk/install.sh --help. On Debian and Ubuntu, an apt package is available, but that package contains only the core tools and requires a separate step for kubectl.
The kubectl component is the Kubernetes command-line interface that sends cluster operations from the local machine to the GKE control plane. The kubectl tool depends on the Google Cloud CLI installation because it is delivered and updated as an additional gcloud component rather than as part of every base package. After the base CLI is installed, the component manager adds kubectl to the same local environment so gcloud handles project authentication while kubectl handles cluster workloads. The Debian and Ubuntu apt package illustrates this separation because it contains only a limited set of tools, including gcloud, gcloud alpha, and gcloud beta for core and preview commands, plus gsutil for Cloud Storage and bq for BigQuery. The Debian and Ubuntu package does not include kubectl or the App Engine extensions required for some gcloud deploy commands. A system installed from that package must install kubectl separately before it can communicate with GKE clusters.
Exam tip: The Debian and Ubuntu apt package does not include kubectl — install kubectl separately as an additional component after installing the Google Cloud CLI.
Initialization is the step where the local environment is authorized and configured so commands run against the intended Google Cloud project and location. The gcloud init command starts this process by signing in the user account, selecting or creating a project, and setting defaults such as compute region or zone. A properly initialized environment lets later gcloud and kubectl commands flow from the local shell to the correct GKE services without repeating project and location flags. Keeping the installation updated ensures the local tools can communicate with current GKE services, and the command gcloud components update retrieves the latest supported version of the gcloud CLI and its installed components, including kubectl. Before installing on Debian or Ubuntu, the operating system must meet three baseline requirements: a supported release that has not reached end-of-life, a recent package index from sudo apt-get update, and the helper packages ca-certificates, gnupg, and curl.
$HOME/.kube/config and each context links a cluster, user, and namespace, with the current context acting as the kubectl default.gcloud container aws clusters get-credentials and gcloud container azure clusters get-credentials with --location fetch the cluster endpoint and add a new kubeconfig context.connectgateway.googleapis.com and gke-connect-agent or directly to a private control-plane endpoint.kubectl config view lists all known contexts, kubectl config current-context shows the default, and --cluster targets one command without changing the default.apt package for the Google Cloud CLI does not include kubectl, so kubectl must be installed separately as an additional component.A kubeconfig file is a YAML file saved by default at $HOME/.kube/config that stores the connection and authentication information kubectl needs to reach clusters. Each context in the file groups a Kubernetes cluster, a user, and a namespace, and the current context is the default cluster for kubectl commands. The file supplies the endpoint address kubectl must reach and the credentials that prove who is making the request for traffic to the Kubernetes API server over TCP port 443.
Retrieving credentials with the Google Cloud CLI automatically populates the kubeconfig file with endpoint and authentication data by contacting the GKE Multi-Cloud API and adding a new context for that cluster. For GKE on AWS the pattern is gcloud container aws clusters get-credentials CLUSTER_NAME --location GOOGLE_CLOUD_LOCATION and for GKE on Azure the pattern uses gcloud container azure clusters get-credentials with the same arguments, where CLUSTER_NAME is the cluster name and GOOGLE_CLOUD_LOCATION is the Google Cloud region or zone where the cluster is managed. After the command succeeds, kubectl uses the same Google identity that gcloud uses, and the credentials must include the userinfo.email OAuth scope so GKE can validate the user or service account email.
The Connect gateway is the recommended path when direct routing to the private control plane is not available, while the private endpoint should be used only when VPC connectivity and routing already exist. With the Connect gateway, traffic flows from kubectl to connectgateway.googleapis.com to the private endpoint through the gke-connect-agent Deployment in the cluster, and the cluster only needs outbound connectivity to Google with no direct VPC route required. With a private endpoint, traffic flows directly from kubectl to the private control-plane endpoint such as an ELB DNS name on AWS, which requires the workstation to have routing to the control-plane endpoint in the virtual network and possibly widened firewall rules.
You are setting up a new local workstation to manage Google Kubernetes Engine (GKE) clusters for your organization.
You have installed the Google Cloud CLI package and need to:
kubectl command-line tool using the built-in component managerWhich sequence of commands should you execute?
Last updated