Getting Access to the GKE Cluster

After deployment, to access the GKE cluster with kubectl commands, you need to add your IP address to the authorized networks.

First, get your current IP address with the following command:

shell
curl ifconfig.me

Now that you have your IP address, you need to add it to the GKE Authorized Networks. There are two ways to do this:

Option A: Using GCP Console (recommended for first-time setup):

  1. Go to GKE Clusters in GCP Console.

  2. Click on your cluster name

  3. Click Edit at the top.

    Under NetworkingControl plane authorized networks:

    1. Click Add authorized network

    2. Enter your IP with /32 for example: 203.0.113.123/32

    3. Add a description such as "My laptop"

    4. Click Save

Option B: Using code (for permanent access):

  1. Edit terraform.tfvars file

  2. Add your IP to the ip_ranges_allowed_to_kubeapi list:

    hcl
    ip_ranges_allowed_to_kubeapi = [
         "YOUR.IP.ADDRESS/32",    # Add your IP here
         # Add other team members' IPs as needed
       ]
  3. Apply the changes:

    shell
    terraform apply -target="module.gke"

The last step is to configure kubectl:

shell
# Authenticate with GCP
gcloud auth login
# Get cluster credentials (replace with your actual cluster name and project)
gcloud container clusters get-credentials <your-cluster-name> --zone <your-zone> --project <your-project-id>
# Test access
kubectl get namespaces

Note

If your IP address changes frequently (dynamic IP), you may need to update the authorized networks accordingly.