Bird
Raised Fist0
GCPcloud~20 mins

Kubectl configuration for GKE in GCP - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
GKE Kubectl Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Configuration
intermediate
2:00remaining
Understanding the kubectl context after GKE cluster creation

After creating a new GKE cluster, you run kubectl config get-contexts. What does the output show?

AAn error saying no contexts are configured yet
BOnly the new GKE cluster context without any other contexts
CA list of all Kubernetes contexts including the new GKE cluster context with its cluster and user info
DA list of all pods running in the default namespace
Attempts:
2 left
💡 Hint

Think about what kubectl config get-contexts shows in general.

❓ service_behavior
intermediate
2:00remaining
Effect of running 'gcloud container clusters get-credentials' on kubectl

What happens when you run gcloud container clusters get-credentials my-cluster --zone us-central1-a --project my-project?

AIt updates your kubeconfig file to add credentials and context for the specified GKE cluster
BIt creates a new GKE cluster named 'my-cluster' in the specified zone
CIt deletes the kubeconfig file and resets kubectl configuration
DIt lists all running pods in the 'my-cluster' cluster
Attempts:
2 left
💡 Hint

Consider what the command name suggests about credentials and configuration.

❓ security
advanced
2:00remaining
Identifying security risks in kubeconfig file sharing

You share your kubeconfig file with a colleague. What is a potential security risk of this action?

AThe colleague can access your GKE cluster with your permissions, possibly causing unintended changes
BThe kubeconfig file will automatically expire and become unusable after 24 hours
CSharing kubeconfig files is safe because they contain only public information
DThe colleague can only view cluster metadata but cannot make changes
Attempts:
2 left
💡 Hint

Think about what credentials and permissions kubeconfig files hold.

❓ Architecture
advanced
2:00remaining
How kubectl communicates with a GKE cluster

Which component does kubectl communicate with directly to manage resources in a GKE cluster?

AThe Google Cloud Storage bucket linked to the cluster
BThe Google Cloud Console web interface
CThe GKE master node's operating system shell
DThe Kubernetes API server running inside the GKE cluster
Attempts:
2 left
💡 Hint

Consider what kubectl commands like kubectl get pods interact with.

✅ Best Practice
expert
2:00remaining
Best practice for managing multiple GKE cluster contexts in kubectl

You manage multiple GKE clusters across projects and regions. What is the best practice to avoid confusion when switching between clusters using kubectl?

AManually edit the kubeconfig file to remove unused clusters each time
BUse descriptive context names and switch contexts explicitly with <code>kubectl config use-context</code>
CDelete all other contexts except the one you are currently using
DAlways run <code>gcloud container clusters get-credentials</code> before every kubectl command
Attempts:
2 left
💡 Hint

Think about how kubectl manages multiple cluster connections.

Practice

(1/5)
1. What is the main purpose of running gcloud container clusters get-credentials when working with GKE?
easy
A. To create a new Kubernetes cluster in GKE
B. To delete an existing GKE cluster
C. To configure kubectl to connect to a specific GKE cluster
D. To update the Kubernetes version of a cluster

Solution

  1. Step 1: Understand the command's role

    The command gcloud container clusters get-credentials fetches cluster access credentials and updates the local kubectl config.
  2. Step 2: Connect kubectl to the cluster

    This allows kubectl to communicate with the specified GKE cluster for managing resources.
  3. Final Answer:

    To configure kubectl to connect to a specific GKE cluster -> Option C
  4. Quick Check:

    Get credentials = Setup kubectl connection [OK]
Hint: Remember: get-credentials sets kubectl access [OK]
Common Mistakes:
  • Thinking it creates or deletes clusters
  • Confusing it with cluster upgrade commands
  • Assuming it manages Kubernetes resources directly
2. Which of the following is the correct syntax to configure kubectl for a GKE cluster named my-cluster in zone us-central1-a?
easy
A. gcloud container clusters get-credentials my-cluster --zone us-central1-a
B. kubectl config set-cluster my-cluster --zone us-central1-a
C. gcloud container clusters create my-cluster --zone us-central1-a
D. kubectl get credentials my-cluster --zone us-central1-a

Solution

  1. Step 1: Identify the correct command for fetching credentials

    The correct command to configure kubectl is gcloud container clusters get-credentials followed by the cluster name and zone.
  2. Step 2: Verify syntax correctness

    gcloud container clusters get-credentials my-cluster --zone us-central1-a matches the correct syntax exactly, while others either use wrong commands or incorrect flags.
  3. Final Answer:

    gcloud container clusters get-credentials my-cluster --zone us-central1-a -> Option A
  4. Quick Check:

    Correct syntax uses gcloud get-credentials [OK]
Hint: Use gcloud get-credentials with cluster name and zone [OK]
Common Mistakes:
  • Using kubectl commands instead of gcloud for credentials
  • Mixing create and get-credentials commands
  • Omitting the --zone flag or using wrong flags
3. After running gcloud container clusters get-credentials my-cluster --zone us-central1-a, what will be the output of kubectl config current-context?
medium
A. gcloud-context
B. my-cluster-context
C. default
D. gke_project_us-central1-a_my-cluster

Solution

  1. Step 1: Understand how get-credentials sets context

    The command sets the current context to the GKE cluster with a name format: gke_PROJECT_ZONE_CLUSTER.
  2. Step 2: Match the expected context format

    Given the cluster name and zone, the context will be like gke_project_us-central1-a_my-cluster, where 'project' is your GCP project ID placeholder.
  3. Final Answer:

    gke_project_us-central1-a_my-cluster -> Option D
  4. Quick Check:

    Current context = gke_project_zone_cluster [OK]
Hint: Current context matches gke_project_zone_cluster format [OK]
Common Mistakes:
  • Expecting a simple cluster name as context
  • Assuming 'default' context after get-credentials
  • Confusing context with namespace or config name
4. You ran gcloud container clusters get-credentials my-cluster --zone us-central1-a but get the error: ERROR: (gcloud.container.clusters.get-credentials) ResponseError: code=404, message=Not found. What is the most likely cause?
medium
A. Your Kubernetes config file is corrupted
B. The cluster name or zone is incorrect or the cluster does not exist
C. You need to update your gcloud SDK version
D. kubectl is not installed on your machine

Solution

  1. Step 1: Analyze the 404 Not Found error

    This error means the requested cluster resource was not found in the specified zone or project.
  2. Step 2: Check cluster name and zone correctness

    Most likely, the cluster name or zone is wrong, or the cluster was deleted or never created.
  3. Final Answer:

    The cluster name or zone is incorrect or the cluster does not exist -> Option B
  4. Quick Check:

    404 error = cluster not found [OK]
Hint: 404 means cluster not found; check name and zone [OK]
Common Mistakes:
  • Assuming kubectl installation causes this error
  • Ignoring the zone or project mismatch
  • Thinking SDK update fixes resource not found
5. You want to switch kubectl to manage a different GKE cluster named prod-cluster in zone europe-west1-b. Which sequence of commands correctly updates your kubectl configuration?
hard
A. Run gcloud container clusters get-credentials prod-cluster --zone europe-west1-b then use kubectl config use-context with the new context
B. Run kubectl config set-cluster prod-cluster --zone europe-west1-b only
C. Run gcloud container clusters create prod-cluster --zone europe-west1-b then kubectl config use-context
D. Run kubectl config use-context prod-cluster directly without other commands

Solution

  1. Step 1: Fetch credentials for the new cluster

    Use gcloud container clusters get-credentials with the cluster name and zone to update kubectl config with new cluster info.
  2. Step 2: Switch kubectl context to the new cluster

    After fetching credentials, use kubectl config use-context with the new context name to switch active cluster.
  3. Final Answer:

    Run gcloud get-credentials then kubectl use-context -> Option A
  4. Quick Check:

    Get credentials + use-context = switch cluster [OK]
Hint: Always get credentials before switching context [OK]
Common Mistakes:
  • Trying to set cluster with kubectl only
  • Creating cluster instead of switching
  • Using use-context without fetching credentials
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard