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:
curl ifconfig.meNow 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):
Go to GKE Clusters in GCP Console.
Click on your cluster name
Click Edit at the top.
Under → :
Click
Enter your IP with
/32for example:203.0.113.123/32Add a description such as "My laptop"
Click
Option B: Using code (for permanent access):
Edit
terraform.tfvarsfileAdd your IP to the
ip_ranges_allowed_to_kubeapilist:hclip_ranges_allowed_to_kubeapi = [ "YOUR.IP.ADDRESS/32", # Add your IP here # Add other team members' IPs as needed ]Apply the changes:
shellterraform apply -target="module.gke"
The last step is to configure kubectl:
# 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 namespacesNote
If your IP address changes frequently (dynamic IP), you may need to update the authorized networks accordingly.