# GKE

> Run GKE locally with LocalCloud: connection settings, supported workflows, known limits, and code examples.
>
> Source: https://local.cloud/services/gke/

Google Kubernetes Engine manages Kubernetes clusters for container workloads. LocalCloud uses k3d to provide a local Kubernetes runtime alongside supported cluster metadata.

## Typical uses

Use when deployment depends on Kubernetes manifests and APIs, and you need cluster provisioning plus pod readiness checks. Local tests require Docker and k3d.

Examples

- Kubernetes deployment tests
- Cluster provisioning and readiness checks

GKE is opt-in to save memory. Add `gke` to the services you start, for example `localcloud start --local-only --services gke,gcs,pubsub`; `--services` sets the exact list.

Connection

Environment variable

`GKE_EMULATOR_HOST=localhost:5380`

Runtime details

- **Endpoints:** gRPC :5380 · k3d :5443
- **Minimum tier:** [Pro tier, free during preview](https://local.cloud/pricing/#pro-tier)
- **Persistence:** metadata
- **Implementation:** Local Facade

## Example usage

Service ID: `gke`. Enable this service in the exact list of services your project starts; see the opt-in instruction above. Use an already running LocalCloud runtime for the examples below.

Export the local project and mapped endpoints in your client process, then use the client settings below. [First-time setup](https://local.cloud/docs/)

```bash
# Export GOOGLE_CLOUD_PROJECT and GKE_EMULATOR_HOST
eval "$(localcloud env)"
```

REST gateway examples use the generated HTTP address in `SERVICE_USAGE_EMULATOR_HOST`; native SDKs can use a different protocol.

Java · REST:

### Java · REST

### List Kubernetes clusters

List Kubernetes clusters; GKE provides the cluster context where you deploy and inspect container workloads.

Call the Google Cloud REST API with the JDK HTTP client. Requires JDK 17+. Results reflect resources already created in your local project.

Discovery check · reads existing local state.

#### Save as Hello.java

```java
import java.net.URI;
import java.net.http.*;
import java.time.Duration;
import java.util.Objects;

public class Hello {
  public static void main(String[] args) throws Exception {
    var project = Objects.requireNonNull(System.getenv("GOOGLE_CLOUD_PROJECT"));
    var endpoint = Objects.requireNonNull(System.getenv("SERVICE_USAGE_EMULATOR_HOST"));
    var url = URI.create(endpoint.replaceAll("/+$", "") + "/v1/projects/" + project + "/locations/us-central1/clusters");
    var request = HttpRequest.newBuilder(url).timeout(Duration.ofSeconds(30)).GET().build();
    var client = HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(10)).build();
    var response = client.send(request, HttpResponse.BodyHandlers.ofString());
    if (response.statusCode() >= 400) {
      throw new IllegalStateException(response.statusCode() + ": " + response.body());
    }
    System.out.println(response.body());
  }
}
```

#### Run the example

```bash
java Hello.java
```

#### Verify the result

The request succeeds. An empty list or no printed rows is valid before matching resources exist. Continue with the documented workflows for a resource test.

gcloud CLI:

### gcloud CLI

### List Kubernetes clusters

List Kubernetes clusters; GKE provides the cluster context where you deploy and inspect container workloads.

Use the Google Cloud CLI against the local gateway in its default open IAM mode. Run these exports in a terminal dedicated to local development.

Discovery check · reads existing local state.

#### Configure gcloud CLI

```bash
: "${SERVICE_USAGE_EMULATOR_HOST:?Export the LocalCloud environment first}"
export CLOUDSDK_CORE_PROJECT="${GOOGLE_CLOUD_PROJECT:?Export the LocalCloud environment first}"
export CLOUDSDK_AUTH_DISABLE_CREDENTIALS=true
export CLOUDSDK_API_ENDPOINT_OVERRIDES_CONTAINER="${SERVICE_USAGE_EMULATOR_HOST%/}/"
```

#### Run in your terminal

```bash
gcloud container clusters list --region=us-central1
```

#### Verify the result

The request succeeds. An empty list or no printed rows is valid before matching resources exist. Continue with the documented workflows for a resource test.

Verify a resource workflow by creating isolated state, performing the operation, and reading the result back. Run cleanup even after a failure; delete only test-owned resources.

Connection failed? Check `localcloud status --verbose`, enabled services, and client exports. Stop accidental Google Cloud calls; correct local routing before retrying.

## Documented workflows

- ### Cluster metadata lifecycle

    Create a cluster and poll its pending operation until k3d provisioning finishes. Inspect the terminal result before treating the cluster as available.

- ### Real local Kubernetes clusters through k3d

    Use Docker and k3d to bring up the local Kubernetes cluster, then deploy a small workload. Check pod status and application output through Kubernetes.

- ### Pod ADC through annotated Kubernetes-to-Google service-account bindings

    Enable TLS and local identity, configure the project workload pool, annotate the Kubernetes service account, and grant workloadIdentityUser to its Google service-account mapping. Check ADC inside a pod before calling a local API.

## Service boundaries

- One k3d server node; requires Docker. No node-pool creation, autoscaling, resize, or upgrades
- Use the exported /container/v1 REST endpoint; shared /v1 cluster routes select AlloyDB
- Pod identity needs TLS, local identity, the KSA annotation, and workloadIdentityUser; direct principal federation is unavailable

## Code examples and integrations

- [Build an integration test loop](https://local.cloud/gcp-integration-testing/): Start the runtime, verify readiness, exercise your SDK, and clean up test state.

Agent testing

## Use GKE with an AI agent

Before the agent changes application logic, have it create local GKE state, read it back with the project SDK, and note which feature the check covered. That first local call catches accidental production routing and needs no GCP account, service-account key, or billing project.

### Configure this repo

```
Set up this repository to use LocalCloud for local GCP development. First read https://local.cloud/ai/agents.md, then inspect this repo, identify the GCP services and SDK language, configure emulator environment variables, and run the narrowest integration test against localhost. Do not use real GCP credentials or production endpoints.
```

Production endpoints, auth, IAM, quotas, regional behavior, and final release validation still need the target Google Cloud project.

[Agent resources](https://local.cloud/ai/) has more prompts and the AGENTS.md template.

## Related guides

- [Compatibility](https://local.cloud/compatibility/): compare all 27 service guides.
- [Configuration](https://local.cloud/docs/configuration/): service selection and runtime settings.
- [Official GKE documentation](https://docs.cloud.google.com/kubernetes-engine/docs/concepts/kubernetes-engine-overview): service concepts and cloud usage.
