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 will set up Harness GitOps to connect securely to a Google Kubernetes Engine (GKE) cluster without storing kubeconfigs or static credentials.
What you will learn from this topic
What GKE Workload Identity is and how it provides keyless authentication for GKE clusters.
The setup process for connecting a GKE cluster to Harness GitOps.
How to create and bind GCP IAM service accounts, modify the GitOps agent YAML, and deploy the agent with Workload Identity annotations.
How to create the cluster secret and verify the connection in the Harness UI.
Before you begin
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
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
Go to the GKE Workload Identity documentation to learn more about how Workload Identity works in GKE, and go to Argo CD's GKE Workload Identity setup guide to see Argo CD's native configuration guidance.
Overview of the setup process
The GKE Workload Identity setup involves these key steps:
Enable Workload Identity on the GKE cluster: Configure your cluster to support Workload Identity.
Create a GCP IAM service account: Create a service account for GitOps agent authentication.
Grant IAM permissions: Assign the necessary permissions to the service account.
Establish an IAM binding: Link the Kubernetes service account to the GCP IAM service account.
Download and modify the GitOps agent YAML: Download the agent YAML and configure service account annotations.
Annotate an existing service account: If you are reusing an existing Kubernetes service account, annotate it directly.
Deploy the GitOps agent: Install the modified agent in your cluster.
Create the cluster secret: Configure the cluster connection with Workload Identity authentication.
Verify setup: Ensure the cluster appears healthy in the Harness UI.
Enable Workload Identity on the 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 the next step.
Enable Workload Identity on an existing cluster
If Workload Identity is not enabled, enable it on your cluster:
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 a new cluster with Workload Identity (optional)
If you are creating a new cluster, enable Workload Identity during creation:
Create a 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
Grant IAM permissions to the service account
Grant the necessary IAM permissions to your service account to access the GKE cluster.
Grant the 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:
Establish the 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 the IAM binding
You should see a binding similar to:
Download and modify the 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 the GitOps agent YAML from Harness
First, 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 (for example,
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 is a file named something like
gitops-agent.yaml.Save the file locally. You need to edit it before applying it to your cluster.
Annotate the service account in the agent YAML
Now that you have the agent YAML file, annotate the service account to enable Workload Identity.
Open the downloaded YAML file in your preferred text editor. Find the application controller service account section. Look for this section in the file:
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 are 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 have 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
Annotate an existing service account
If you are using an existing Kubernetes service account that is already being used by other workloads, you need to annotate it with the Workload Identity binding.
Create the namespace (if it does not exist)
Annotate the Kubernetes service account
This is the command you have already run. The annotation establishes the link between the Kubernetes service account and the GCP IAM service account.
Verify the service account annotation
You should see the annotation:
Deploy the GitOps agent
Apply the modified GitOps agent YAML to your cluster.
Ensure the kubectl context is correct
Before applying, ensure you are 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 the agent in the Harness UI
Navigate to GitOps -> Settings -> GitOps Agents in your Harness account.
Verify that your agent shows a Healthy status.
Create the 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 the secret from a 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:
Verify setup in the 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 have 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.
Next steps
GitOps Agent metrics with Prometheus: Monitor the health and performance of the agent connected to this cluster.
Use secrets for cluster credentials: Review alternative, secret-based authentication methods for other clusters.
Manage GitOps Applications: Deploy applications to your newly connected cluster.
Last updated
Was this helpful?