Create a GitOps Cluster with GKE Workload Identity
Connect Harness GitOps (Argo CD) to Google Kubernetes Engine (GKE) using Workload Identity for secure, keyless authentication.
In this guide, you'll set up Harness GitOps to connect securely to a Google Kubernetes Engine (GKE) cluster without storing kubeconfigs or static credentials.
What is GKE Workload Identity?
GKE Workload Identity allows Kubernetes ServiceAccounts to securely access Google Cloud resources without storing credentials or secrets in the cluster. Instead, GKE binds Kubernetes ServiceAccounts to Google Cloud IAM Service Accounts, enabling workloads to authenticate using short-lived tokens.
With Workload Identity:
No kubeconfigs or static service account keys are stored
Authentication is short-lived and automatically rotated
Access is scoped to a specific Kubernetes ServiceAccount
Follows Google Cloud's security best practices
Learn more:
Prerequisites
Before setting up GKE Workload Identity with GitOps, ensure you have:
Google Cloud Platform (GCP) project with appropriate permissions to:
Create and manage IAM service accounts
Assign IAM roles and policies
Manage GKE clusters
Configure Workload Identity bindings
GKE cluster with Workload Identity enabled
gcloud CLI installed and configured
kubectl installed and configured
Harness GitOps module enabled in your account
Overview of the Setup Process
The GKE Workload Identity setup involves these key steps:
Enable Workload Identity on GKE Cluster - Configure your cluster to support Workload Identity
Create GCP IAM Service Account - Create a service account for GitOps agent authentication
Grant IAM Permissions - Assign necessary permissions to the service account
Establish IAM Binding - Link the Kubernetes service account to the GCP IAM service account
Download and Modify GitOps Agent YAML - Download the agent YAML and configure service account annotations
Deploy GitOps Agent - Install the modified agent in your cluster
Create Cluster Secret - Configure the cluster connection with Workload Identity authentication
Verify Setup - Ensure the cluster appears healthy in Harness UI
Step 1: Enable Workload Identity on GKE Cluster
Workload Identity must be enabled at both the cluster level and node pool level.
Check if Workload Identity is Already Enabled
First, check if your cluster already has Workload Identity enabled:
If the output shows <PROJECT_ID>.svc.id.goog, Workload Identity is already enabled. Skip to Step 2.
Enable Workload Identity on Existing Cluster
If Workload Identity is not enabled, enable it on your cluster:
Enabling Workload Identity on an existing cluster does not automatically enable it on existing node pools. You must update node pools separately.
Enable Workload Identity on Node Pools
Update your node pools to enable Workload Identity:
Replace <NODE_POOL_NAME> with your actual node pool name. Repeat for all node pools.
Create New Cluster with Workload Identity (Optional)
If you're creating a new cluster, enable Workload Identity during creation:
Step 2: Create GCP IAM Service Account
Create a Google Cloud IAM service account that will be used by your GitOps agent to authenticate to the GKE cluster.
Set Environment Variables
Create the IAM Service Account
Verify Service Account Creation
Step 3: Grant IAM Permissions to Service Account
Grant the necessary IAM permissions to your service account to access the GKE cluster.
Grant Container Cluster Viewer Role (Required)
The service account needs permissions to interact with GKE clusters. At minimum, grant the Container Cluster Viewer role:
This role provides:
Get and list GKE clusters
Get cluster credentials
View cluster resources
Grant Additional Roles (Optional)
Depending on your requirements, you may need additional roles:
Step 4: Establish IAM Binding
Create an IAM policy binding that allows the Kubernetes service account to impersonate the GCP IAM service account.
Set Kubernetes Service Account Variables
Create the IAM Policy Binding
This command creates a binding that allows the Kubernetes service account <K8S_SA_NAME> in namespace <K8S_NAMESPACE> to act as the GCP service account.
Verify IAM Binding
You should see a binding similar to:
Step 5: Download and Modify GitOps Agent YAML
Before you can configure workload identity authentication, you need to download the GitOps agent YAML from Harness and make specific modifications to enable Workload Identity.
Download GitOps Agent YAML from Harness
First, let's get the agent YAML file from your Harness account:
Log in to your Harness account and navigate to the GitOps module
Go to GitOps → Settings → GitOps Agents
Click + New GitOps Agent
Fill in the agent details:
Name: Enter a descriptive name for your agent (e.g.,
gke-wif-agent)Agent Type: Select Argo CD
Namespace: Enter your namespace (this must match the namespace in your IAM binding)
Click Continue or Next
Download the agent YAML file - this will be a file named something like
gitops-agent.yamlSave the file locally - you'll need to edit it before applying to your cluster
Annotate the Service Account in Agent YAML
Now that you have the agent YAML file, you need to annotate the service account to enable Workload Identity.
Step 1: Open the downloaded YAML file in your preferred text editor.
Step 2: Find the Application Controller Service Account section. Look for this section in the file:
Step 3: Add the GCP Workload Identity annotation to the metadata.annotations section:
Replace your-gcp-sa@your-gcp-project-id.iam.gserviceaccount.com with your actual GCP service account email.
Annotate Additional Service Accounts (If Using Option B)
If you're creating new service accounts via the agent YAML, you may also need to annotate the argocd-server service account for displaying logs in the Harness UI:
Find the Argo CD Server Service Account section:
Verify Your Modifications
Before proceeding, double-check that you've made these changes:
Added
iam.gke.io/gcp-service-accountannotation with your GCP service account emailUpdated the namespace to match your target namespace
If using an existing service account, updated the
serviceAccountNamereferences in deployments/statefulsetsSaved the modified YAML file
Step 6: Annotate Existing Service Account (If Using Existing SA)
If you're using an existing Kubernetes service account that's already being used by other workloads, you need to annotate it with the Workload Identity binding.
Create Namespace (if it doesn't exist)
Annotate the Kubernetes Service Account
This is the command you've already run. The annotation establishes the link between the Kubernetes service account and the GCP IAM service account.
Verify Service Account Annotation
You should see the annotation:
Step 7: Deploy GitOps Agent
Apply the modified GitOps agent YAML to your cluster.
Ensure kubectl Context is Correct
Before applying, ensure you're connected to the correct cluster:
Apply the GitOps Agent YAML
Verify Agent Deployment
Check that all GitOps agent pods are running:
Wait for all pods to be in Running state. The main pods to watch for are:
argocd-application-controller-*argocd-repo-server-*argocd-server-*gitops-agent-*(if using Harness-specific components)
Check Pod Logs for Workload Identity
Verify that Workload Identity is working by checking the application controller logs:
You should NOT see any authentication errors related to GCP credentials.
Verify Agent in Harness UI
Navigate to GitOps → Settings → GitOps Agents in your Harness account
Verify that your agent shows a Healthy status
Step 8: Create Cluster Secret
Create a Kubernetes secret that defines how to connect to your GKE cluster using Workload Identity authentication.
Gather Cluster Information
Get your cluster's API server endpoint and CA certificate:
Create the Cluster Secret
Create the secret that tells Harness GitOps how to authenticate to the cluster:
Alternative: Create Secret from YAML File
If you prefer to create a separate YAML file:
Replace the placeholders:
<CLUSTER_ENDPOINT>: Your cluster's API server endpoint<BASE64_ENCODED_CA_CERT>: The base64-encoded CA certificate
Then apply:
Verify the Secret
Check that the secret was created correctly:
Step 9: Verify Setup in Harness UI
Check Cluster Status
Navigate to GitOps → Settings → Clusters in your Harness account
You should see your cluster listed with an Active status
The cluster should show as Connected

Test the Connection
Create a simple test application to verify the connection:
Go to GitOps → Applications
Click + New Application
Configure a simple application pointing to your cluster
Verify that the application can successfully sync to the cluster

Summary
In this guide, you've learned how to:
Enable Workload Identity on your GKE cluster and node pools
Create and configure GCP IAM service accounts with the required Container Cluster Viewer permissions
Establish Workload Identity bindings between Kubernetes and GCP service accounts
Modify and deploy Harness GitOps agents with Workload Identity annotations
Create cluster secrets for secure authentication using
argocd-k8s-authVerify the setup and deploy applications to your cluster
Your GKE cluster is now securely connected to Harness GitOps using Workload Identity, eliminating the need for static credentials and following Google Cloud security best practices.
Last updated
Was this helpful?