mediumMultiple ChoiceObjective-mapped
Google ACE Practice Question: A developer needs to forward traffic from their…
A developer needs to forward traffic from their local port 5432 to a PostgreSQL service running in GKE on port 5432, to test database queries locally without exposing the database externally. Which kubectl command achieves this?
⚠ Common exam trap
Google Cloud often tests the distinction between exposing a service externally (LoadBalancer) and creating a local tunnel (port-forward), and candidates may mistakenly choose a LoadBalancer option thinking it is required for connectivity, ignoring the 'without exposing externally' constraint.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
kubectl port-forward svc/postgres-service 5432:5432
`kubectl port-forward` creates a local tunnel from port 5432 on the developer's machine to the specified service's port 5432 inside the GKE cluster. This allows the developer to connect to the PostgreSQL service as if it were running locally, without exposing it to the internet via a LoadBalancer or Ingress.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
kubectl expose pod postgres-pod --type=LoadBalancer --port=5432
Why it's wrong here
This creates a Service of type LoadBalancer, which provisions a cloud load balancer with a public external IP, making the database reachable from the internet. That violates the requirement for private, local-only access for the developer, and also changes the network topology in the cluster. It does not establish a direct tunnel from the developer's machine; it instead creates a lasting Service resource. The intended behavior is a temporary, private forwarding path, which only port-forward provides.
- ✓
kubectl port-forward svc/postgres-service 5432:5432
Why this is correct
This is the correct command because `kubectl port-forward` creates a direct, temporary tunnel from the developer's localhost port 5432 to the postgres Service's port 5432 inside the cluster. It does not expose the Service externally, does not create any Service or Ingress resource, and the bind is to localhost by default, so only the developer's machine can reach it. This matches the requirement for a secure, private way to connect to the database without altering the cluster's networking. The command is also the standard way to debug or access a private Kubernetes resource from a workstation.
- ✗
kubectl tunnel --local=5432 --remote=postgres-service:5432
Why it's wrong here
The kubectl CLI has no `tunnel` subcommand; this is a fabricated command. The correct native command for forwarding local ports to a cluster resource is `kubectl port-forward`, which takes the form `kubectl port-forward RESOURCE LOCAL_PORT:REMOTE_PORT`. Even if a hypothetical tunnel command existed, the syntax with `--local` and `--remote` flags does not match kubectl's actual port-forward flag conventions. Therefore this option is invalid and would fail immediately.
- ✗
gcloud container ssh postgres-pod --port-forward=5432:5432
Why it's wrong here
`gcloud container ssh` is not a valid gcloud command for accessing a GKE pod; the correct gcloud command for SSH to a node is `gcloud compute ssh`, and even that does not support a `--port-forward` flag. Port forwarding into a pod is handled by kubectl, not by gcloud, because it requires the Kubernetes API to establish the tunnel. This command would either fail as unrecognized or, if SSHing to a node, would not forward the container port. The proper tool is `kubectl port-forward svc/postgres-service 5432:5432`.
Go deeper
Related to this question
Learn chapter
GCP Database Services
Key term
Service
A service is a software component or system that performs a specific function and is available to be used by other programs or users over a network.
Key term
GKE
GKE is Google's managed Kubernetes service that automates deploying, scaling, and managing containerized applications in the cloud.
About these practice questions
One of 769 original ACE practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This ACE practice question is part of Courseiva's free Google Cloud certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the ACE exam.