Skip to main content

Overview

This guide covers setting up Vertex AI with Workload Identity Federation on GKE for secure, keyless authentication. This approach eliminates the need for service account keys and provides automatic credential rotation.
Workload Identity is the recommended way to access Google Cloud services from GKE. It provides better security than service account keys and simplifies credential management.

Architecture

Workload Identity Integration Flow

This diagram shows the complete authentication flow from a GKE pod to GCP services using Workload Identity Federation, eliminating the need for credential files:
Key Benefits of Workload Identity:
  • No credential files: Kubernetes tokens are automatically exchanged for GCP credentials
  • Automatic rotation: GCP handles credential rotation without manual intervention
  • Fine-grained access: Each Kubernetes service account maps to a specific GCP service account with minimal permissions
  • Audit trail: All GCP API calls are attributed to the specific service account identity

Prerequisites

Before starting, ensure you have:
  • GKE cluster with Workload Identity enabled
  • Staging infrastructure deployed (run setup-staging-infrastructure.sh first)
  • gcloud CLI installed and authenticated
  • kubectl installed and configured
  • Billing enabled on your GCP project

Quick Setup

The easiest way to set up Vertex AI with Workload Identity:
This script will:
  1. ✅ Enable Vertex AI API
  2. ✅ Create vertex-ai-staging service account
  3. ✅ Grant necessary IAM permissions
  4. ✅ Bind Kubernetes SA to GCP SA
  5. ✅ Annotate Kubernetes service account
  6. ✅ Verify configuration
If you prefer manual setup or need to understand each step:

Step 1: Enable Vertex AI API

Step 2: Create Service Account

Step 3: Grant Permissions

Step 4: Setup Workload Identity Binding

Step 5: Annotate Kubernetes Service Account

Configuration

Environment Variables

The deployment is configured with the following environment variables in deployments/overlays/preview-gke/deployment-patch.yaml:

Service Account Annotation

The Kubernetes service account is annotated to use Workload Identity:

Deployment

Deploy to Staging

After running the setup script, deploy the updated configuration:

Verification

1. Verify Workload Identity Binding

2. Verify Kubernetes Annotation

3. Test Authentication from Pod

4. Test Vertex AI Access

5. Test with LiteLLM

Troubleshooting

Error: google.auth.exceptions.DefaultCredentialsError: Could not automatically determine credentialsSolutions:
  1. Verify Workload Identity is enabled on cluster:
  2. Check service account annotation:
  3. Verify IAM binding:
  4. Restart pods to pick up new annotation:
Error: 403 Permission denied on resource projectSolutions:
  1. Verify service account has required roles:
  2. Grant missing permissions:
Error: 404 The model requested does not existSolutions:
  1. Verify model name format for Vertex AI:
  2. Check available models:
  3. Use supported model names:
    • gemini-2.5-flash
    • gemini-2.5-pro
Error: Pod uses default compute service account instead of vertex-ai-stagingSolutions:
  1. Ensure pod spec uses correct service account:
  2. Check if annotation was applied before pod creation:
  3. Verify namespace has Workload Identity enabled:

Security Considerations

Benefits of Workload Identity

No Key Management

No service account keys to create, rotate, or secure. Authentication is handled automatically by GKE.

Automatic Rotation

Credentials are automatically rotated by Google Cloud. No manual intervention required.

Least Privilege

Each pod gets only the permissions it needs via IAM bindings. No shared credentials.

Audit Trail

All API calls are logged with the service account identity. Easy to audit and monitor.

IAM Permissions

The vertex-ai-staging service account has been granted these roles:

Best Practices

  • Do:
  • Use Workload Identity for all GCP service access
  • Grant minimum required permissions
  • Monitor API usage and costs
  • Set up quota alerts
  • Don’t:
  • Create service account keys
  • Grant overly broad permissions
  • Share service accounts across environments
  • Ignore quota warnings

Cost Management

Vertex AI Pricing

Vertex AI charges per 1,000 characters (roughly equivalent to tokens):
gemini-2.5-flash and gemini-2.5-pro are production-grade models recommended for enterprise deployments. They offer stable performance, SLA guarantees, and are suitable for production workloads. Other Gemini 2.5 variants (if any) may be experimental or preview releases.

Setting Quotas

Monitoring Costs

Migration from Google AI Studio

If you’re currently using Google AI Studio API keys, here’s how to migrate:
1

Update Environment Variables

Change from API key to Vertex AI configuration:Before (Google AI Studio):
After (Vertex AI):
2

Run Setup Script

3

Deploy Updated Configuration

4

Verify Migration

Next Steps

Google Gemini Guide

Learn about Gemini model features and capabilities

GKE Preview Deployment

Complete GKE preview deployment guide

Observability

Monitor Vertex AI usage and performance

Production Checklist

Prepare for production deployment

Vertex AI with Workload Identity Configured! Your staging environment now uses keyless authentication for secure, scalable AI access.