Skip to main content
In this guide, you’ll learn how to create and manage a dedicated Kubernetes namespace on a Google Kubernetes Engine (GKE) cluster. Namespaces provide logical separation for applications, improving resource management, security, and clarity.

Why Use Kubernetes Namespaces?

A single GKE cluster can host multiple environments or teams. Namespaces help you:
  • Enforce resource quotas and limits per team or environment
  • Simplify Role-Based Access Control (RBAC)
  • Keep workloads organized and isolated
Namespaces are a native Kubernetes feature. Learn more in the Kubernetes Namespaces documentation.

Prerequisites

  • A Google Cloud project (e.g., kodekloud-gcp-training)
  • A GKE cluster named gcp-devops-project in zone us-central1-c
  • Access to Cloud Shell, or local installation of gcloud and kubectl

Step 1. Connect to Your GKE Cluster

  1. Open Cloud Shell in the GCP Console:
    Kubernetes Engine > Clusters > Connect > Run in Cloud Shell.
  2. Authorize Cloud Shell by pressing Enter when prompted.
  3. Fetch cluster credentials:
Your local kubeconfig is now configured to interact with the gcp-devops-project cluster.

Step 2. List Existing Namespaces

Run:
Example output:

Step 3. Create a New Namespace

Create the gcp-devops-prod namespace for production workloads:

Step 4. Verify Your New Namespace

List namespaces again:
You should see:

Step 5. (Optional) Set the New Namespace as Default

To avoid specifying -n gcp-devops-prod on every command, update your context:
Confirm your active namespace:
Switching the default namespace affects all subsequent kubectl commands in this session.

Step 6. View Namespaced Workloads in GCP Console

  1. In the GCP Console, go to Kubernetes Engine > Workloads.
  2. Click Show system workloads, then open the Filter pane.
  3. Select gcp-devops-prod under Namespace and apply.
You’ll see workloads scoped to your production namespace (none yet, until you deploy).

Command Reference Table


That’s it! You’ve successfully created, verified, and configured a namespace in your GKE cluster. You can now deploy applications into gcp-devops-prod.

Watch Video