Prepare and test your skills

Prepare and test your skills

Service exposure and network connectivity in Google Kubernetes Engine (GKE) is how a containerized application is made reachable through a stable address. A Kubernetes Service (opens in a new tab) groups a set of Pod endpoints into one resource with a stable IP address and port. A client sends a request to the Service address, and the request is routed to one of the Pods in the Service, even as individual Pods start and stop.
Exposing an application in GKE connects three parts. The frontend is the network location that listens for traffic, including its network, IP address, ports, and protocols. Routing and load balancing define how traffic is processed and sent to backends, and backends are the Pod endpoints that GKE updates dynamically. In GKE, the Service controller watches the declarative Service manifest and creates the needed load balancer, IP address, and firewall rules automatically.
Three GKE traffic paths side by side: ClusterIP for internal clients, NodePort via node IP and port, and LoadBalancer via cloud load balancer external IP, each forwarding from Service port to Pod targetPort.
A Kubernetes Service provides a consistent entry point for clients to reach Pods that change over time. The Service uses a label selector to find its member Pods, so any Pod with matching labels such as app: products becomes a backend for the Service. The Service also separates two port settings where port is the port clients use to contact the Service and targetPort is the port on the Pod container where the application listens.
GKE supports five Service types for different connectivity needs:
The selector and port mapping let one stable Service front many changing Pods without clients tracking Pod addresses.
A ClusterIP Service is the default Service type for internal communication inside the cluster. The ClusterIP Service receives a stable cluster IP address that is reachable only by clients inside the cluster. Traffic flows from an internal client to the Service cluster IP and port, then from the Service to one of the selected Pods on its targetPort.
Choose a ClusterIP Service when only other Pods or services inside the same cluster need to reach the application. Because the cluster IP is never exposed to the internet, the application stays isolated from external traffic. A typical manifest sets type: ClusterIP, a port such as 80, a targetPort such as 8080, and a selector that matches the Deployment Pods.
A NodePort Service exposes an application by opening the same port on every cluster node. Traffic flows from a client to any node IP address combined with the NodePort, then from the node to one of the Service Pods. Clients must be able to reach the node network, so NodePort is useful for internal networks and testing but is not the normal way to serve public internet traffic.
Choose a NodePort Service when internal or directly connected clients need to reach the application without provisioning a cloud load balancer. For example, a Service named web can use type: NodePort with port: 8080 and targetPort: 8080 to forward node traffic to containers listening on port 8080. The same result can be created with kubectl expose deployment my-deployment-50000 --type NodePort --port 80 --target-port 50000.
A LoadBalancer Service exposes an application to external traffic through a cloud load balancer with an external IP address. Traffic flows from an outside client to the load balancer IP address and Service port, then from the load balancer to a member Pod on its targetPort. The value of port is arbitrary, so a Service can listen on port 60000 while forwarding to containers listening on port 50001.
Choose a LoadBalancer Service when clients on the internet or another external network need a single public entry point. In GKE, creating this Service causes the Service controller to provision the load balancer and external IP automatically, which may take a few minutes before the address accepts traffic. Access uses the form LOAD_BALANCER_ADDRESS:60000, where the address is the external IP shown in the Service details.
Choosing a Service type by connectivity need means matching who must reach the application to what GKE provisions. Client network is a core factor, along with protocol and whether the application must be reachable regionally or globally. For HTTP applications that need broader routing by host or path, GKE recommends HTTP(S) load balancing through Ingress (opens in a new tab) rather than a basic LoadBalancer Service.
| Service type | Who can reach it | How GKE exposes it |
|---|---|---|
| ClusterIP | Clients inside the cluster only | Stable cluster IP address with no external frontend |
| NodePort | Clients that can reach node IPs | Same port opened on every node, forwarding to Pods |
| LoadBalancer | External clients outside the cluster | Cloud load balancer with an external IP that forwards to Pods |
A LoadBalancer Service builds on NodePort behavior by adding an external frontend, while a ClusterIP Service provides no external frontend at all.
Exam tip: Use ClusterIP for cluster-internal clients only, NodePort for access through a node IP and port, and LoadBalancer for external access through a provisioned load balancer IP.
Kubernetes workload configuration and deployment is the process of defining the desired state of an application in a manifest file and applying that file to a GKE cluster. A Deployment (opens in a new tab) is the Kubernetes controller that keeps stateless applications running as a set of uniform Pods. The manifest declares how many Pods should run, which container image they should use, and which labels identify them, and GKE works to keep the running Pods matched to that desired state.
Stateless workloads and the Deployment controller describe applications that do not store data on the cluster and the controller that keeps them running. A stateless application does not store data or application state on the cluster or in persistent storage. Data and state stay with the client instead, so any Pod can serve any request and replicas can be added or removed without losing data.
The Deployment controller deploys these applications as uniform, non-unique Pods and manages their desired state, including replica count, container image version, and Pod labels. When the replica count or image is updated, the Deployment controller creates, updates, or removes Pods until the cluster matches the new desired state. This model maintains workload stability because the controller continuously reconciles actual Pods with the declared replica count.
| Workload type | Storage model | Pod identity and controller |
|---|---|---|
| Stateless application | No cluster or persistent storage, state stays with the client | Uniform, non-unique Pods managed by a Deployment |
| Stateful application | Uses persistent storage to save data | Pods with unique identities managed by a StatefulSet |
A frontend web application is a common stateless example because additional identical replicas increase availability during high demand and can be scaled down when demand is low.
A Deployment manifest is a YAML resource file that declares the desired state for application Pods in a GKE cluster. The example Deployment named my-app creates three replicated Pods labeled run: my-app that run the hello-app image from Artifact Registry at us-docker.pkg.dev/google-samples/containers/gke/hello-app:1.0. The Deployment manifest links its controller to its Pods through matching labels that must align exactly.
The key fields in the Deployment manifest work together:
replicas: 3.run: my-app.Changing replicas, the image tag or digest, or the labels in this template updates the desired state that the Deployment enforces.
Exam tip: The value in spec.selector.matchLabels must match the value in spec.template.metadata.labels, such as run: my-app, or the Deployment cannot associate its Pods with the replica count.
Applying workloads to a GKE cluster means submitting the Kubernetes resource file so the Deployment controller creates the declared Pods. The container image must already be stored in an image registry such as Artifact Registry, and a GKE cluster must already exist to receive the workload. The manifest can be applied directly with kubectl, the command-line interface for Kubernetes, or through Cloud Build (opens in a new tab) using builder images.
The Cloud Build gke-deploy builder at gcr.io/cloud-builders/gke-deploy is a wrapper around kubectl that applies Google recommended practices for deployment. The gke-deploy builder connects the build pipeline to the target cluster and the manifest file:
A gke-deploy run step requires the manifest path in --filename, the cluster region in --location, and the cluster name in --cluster. If no additional functionality is needed, Cloud Build also provides a kubectl builder that deploys the application to the GKE cluster with kubectl directly.
Container image management and registry integration is the practice of storing versioned container images centrally and letting GKE pull them securely at deploy time. Artifact Registry (opens in a new tab) provides that central storage for Docker and Open Container Initiative (OCI) images in a Docker repository. GKE clusters then use Identity and Access Management (IAM) permissions and authentication to pull only the images they are allowed to access.
Artifact Registry is a central Google Cloud service for storing container images and build dependencies in regional or multi-region Docker repositories. You must create a Docker repository before you push an image to the pkg.dev domain, which keeps repository administration separate from pushing and pulling images. You can create multiple repositories in one project and group images by team or development stage, such as team1 and team2.
Artifact Registry connects builds to deployments across Google Cloud runtimes, including GKE, Cloud Run, Compute Engine, and App Engine flexible environment. Images built by Cloud Build can be stored in Artifact Registry and then deployed to GKE without moving them between systems. Consistent IAM credentials control who can push, pull, and manage repositories, while features like Virtual Private Cloud (VPC) Service Controls perimeters and image prewarming support security and performance for GKE workloads.
Secure image pulls from Artifact Registry to GKE depend on two layers of control called Identity and Access Management (IAM) (opens in a new tab) permissions and access scopes. IAM permissions determine which users and service accounts can access a repository, while access scopes limit the default OAuth scopes available to code running on a virtual machine (VM) instance. Google Cloud runtimes are preconfigured for access to repositories in the same project, so same-project pulls often work without extra setup.
The default Compute Engine service account has permission to pull from Artifact Registry repositories in the same Google Cloud project unless automatic role grants to default service accounts were disabled. That Compute Engine service account is also the default GKE node service account and the default Cloud Run service account, so GKE nodes use it to pull images by default. The default Cloud Build service account has permission to both push to and pull from Artifact Registry repositories in the same project under the same condition. You must configure permissions yourself when a service account in one project accesses Artifact Registry in another project, when a custom service account interacts with Artifact Registry, or when a read-only service account also needs to upload artifacts.
Exam tip: GKE nodes in the same project can pull from Artifact Registry by default through the Compute Engine service account, unless automatic role grants to default service accounts were disabled.
Authentication for Artifact Registry proves the identity of the Docker client or GKE cluster that is pushing or pulling an image. For local development, the command gcloud auth configure-docker registers a credential helper for all Google-supported Docker registries so the Docker client can connect to Artifact Registry. After authentication, docker images lists available images with their full repository path, tag, image ID, and size.
For a private registry used from outside Google Cloud, such as GKE on AWS or GKE on Azure, the cluster authenticates with an IAM service account that has the Artifact Registry reader role. The full image name shows where the image lives, for example us-west1-docker.pkg.dev/PROJECT_NAME/hello-repo/hello-app with tag v1, where the location, project, repository, and image name are all part of the path. To grant private pull access with a dedicated identity, complete the steps in order:
gcloud iam service-accounts create ACCOUNT_NAME to create the IAM service account for registry access.roles/artifactregistry.reader role in the project that owns the Artifact Registry repository.registry-access-key.json, so the remote cluster can present that identity when it pulls the private image.Managing images, tags, and metadata in Artifact Registry means controlling image versions and tracking related information over time. A tag such as v1 labels a specific build of an image path like us-west1-docker.pkg.dev/PROJECT_NAME/hello-repo/hello-app, so a GKE workload can request exactly that version. Pushing uploads a new tagged image to an existing repository, pulling downloads a tagged image for local use or deployment, and image management operations run directly on the repository without managing Cloud Storage buckets.
Artifact Registry also stores container metadata as attachments, which are OCI artifacts linked to a specific container image. Artifact Analysis can generate or scan these attachments to support supply-chain security:
Pub/Sub notifications publish repository changes to the gcr topic, so automation can react when images are pushed, updated, or deleted.
port from the container targetPort.replicas, selector.matchLabels, Pod template labels, and container image.v1 identifies a specific build of an image path, and Artifact Registry links SBOMs, vulnerability results, and build provenance to images as attachments.In Google Kubernetes Engine (GKE), a ClusterIP Service is reachable only inside the cluster through a stable cluster IP with no external frontend, a NodePort Service is reachable through the same port opened on every node IP for clients that can reach the node network, and a LoadBalancer Service is reachable externally through a provisioned cloud load balancer with an external IP that forwards to Pods. A LoadBalancer Service builds on NodePort behavior by adding an external frontend, while a ClusterIP Service provides no external frontend at all. All three use a label selector to group Pod endpoints behind a stable address that separates the client-facing port from the container targetPort.
Use a LoadBalancer Service in Google Kubernetes Engine (GKE) when clients on the internet or another external network need a single public entry point, while a ClusterIP Service is for cluster-internal clients only. In Google Kubernetes Engine (GKE), creating a LoadBalancer Service causes the Service controller to provision the load balancer and external IP automatically, which may take a few minutes before the address accepts traffic. For HTTP applications that need broader routing by host or path, Google Kubernetes Engine (GKE) recommends HTTP(S) load balancing through Ingress rather than a basic LoadBalancer Service.
A Kubernetes Deployment in Google Kubernetes Engine (GKE) declares the desired state with replicas, selector matchLabels, Pod template labels, and container image, and the Deployment controller creates, updates, or removes uniform Pods until the cluster matches that state. The value in the selector matchLabels must match the value in the template metadata labels or the Deployment cannot associate its Pods with the replica count. This model supports stateless applications that store no data on the cluster, so any Pod can serve any request and replicas can be added or removed without losing data.
Google Kubernetes Engine (GKE) nodes use the default Compute Engine service account to pull from Artifact Registry repositories in the same project unless automatic role grants to default service accounts were disabled. Identity and Access Management (IAM) permissions determine which users and service accounts can access a repository, while access scopes limit the default OAuth scopes available to code running on a virtual machine (VM) instance. You must configure permissions yourself when a service account in one project accesses Artifact Registry in another project, when using a custom service account, or when a read-only service account also needs to upload artifacts.
Your company is building a containerized web application that will be hosted on Google Kubernetes Engine (GKE). You have created a Docker repository named app-repo located in the us-central1 region inside the Google Cloud project my-prod-project.
You need to properly tag the local image web-frontend with the version v1.0 so that it can be pushed to Artifact Registry and pulled by your GKE workloads.
Which image path follows the correct Artifact Registry tagging convention?
docker.pkg.dev/us-central1/my-prod-project/web-frontend:v1.0
us-central1-docker.pkg.dev/my-prod-project/app-repo/web-frontend:v1.0
gcr.io/us-central1/my-prod-project/app-repo/web-frontend:v1.0
us-central1.pkg.dev/my-prod-project/docker/app-repo/web-frontend:v1.0
Last updated