Google Kubernetes Engine Samples
repository·main·Indexed 23 days ago
https://github.com/googlecloudplatform/kubernetes-engine-samplesA collection of sample applications and implementation patterns for Google Kubernetes Engine (GKE). Includes demonstrations for agentic AI workloads using the Agentic Development Kit (ADK) with Vertex AI or vLLM, and a secure Anthropic Agent Sandbox utilizing gVisor isolation, the GKE Agent Sandbox add-on, and the Anthropic CLI.
What's inside kubernetes-engine-samples
- This example demonstrates how to build, instrument, and deploy a containerized Go web server to a Kubernetes cluster using OpenTelemetry for distributed tracing. The application architecture consists of a frontend and a backend service, where the frontend makes requests to the backend, which in turn makes outbound requests to an external destination (e.g., google.com).
Overview of the Terraform Kubernetes Engine Module
mainThis module is a fork of the upstream Google GKE Module. The primary difference is that this version includes Private Clusters directly within the main module, whereas the upstream version requires using submodules for private cluster configurations.Overview of the Workload Recommender Module
mainThe Workload Recommender Module provides tools to recommend Horizontal Pod Autoscaler (HPA) or static Vertical Pod Autoscaler (VPA) configurations for Kubernetes workloads in Google Kubernetes Engine (GKE). It aims to balance cost efficiency and reliability by evaluating workloads using historical metric data.
Key Capabilities:
- Fetches and aggregates CPU and memory metrics from Cloud Monitoring.
- Calculates workload startup time (including pod initialization and cluster autoscaler delays).
- Simulates resource scaling using Dynamic Minimum Replicas (DMR) and Dynamic CPU Requests (DCR) algorithms.
- Generates specific resource recommendations for both HPA and VPA.
Note: This solution is currently tested only for Kubernetes Deployments.
Overview of the Prometheus dummy exporter
mainThe
prometheus-dummy-exporteris a simple container designed to expose a single Prometheus metric with a constant value. It is intended for testing and demonstrating how metrics are collected and used in GKE.Key features:
- Configurable Metrics: You can specify the metric name, the metric value, and the port via command-line flags.
- Cloud Monitoring Integration: The metrics are exported to Google Cloud Monitoring using Google Cloud Managed Service for Prometheus via a
PodMonitoringresource.
Overview of whereami
mainwhereamiis a Python-based Kubernetes application designed to describe the location and attributes of the Pod serving a request. It returns metadata such as the cluster name, region, pod name, namespace, and service account. This is primarily used for demonstrations to visualize how traffic flows through a cluster.It supports two modes:
- Flask (HTTP): The default mode.
- gRPC: An alternative mode for gRPC-based communication.
Observability
- Tracing: In Flask mode, it is instrumented with OpenTelemetry and exports traces to Cloud Trace when running on GCP. You can configure the sampling likelihood via the
TRACE_SAMPLING_RATIOenvironment variable in the ConfigMap. - Metrics: Prometheus metrics are exposed at
x.x.x.x/metrics. In gRPC mode, this endpoint is exposed on port8000via HTTP.
Note: If using Workload Identity, ensure the associated Google Service Account (GSA) has permissions to write to Cloud Trace (e.g.,
roles/cloudtrace.agent).Overview of the Stackdriver dummy exporter
mainThe
sd-dummy-exporteris a simple container designed to export a metric with a constant value to Stackdriver (Google Cloud Observability) in a continuous loop. This is useful for testing observability pipelines or custom metrics autoscaling.Key configuration capabilities:
- Metric Name: Set via flags.
- Metric Value: Set via flags.
- Pod Name: Set via flags.
- Namespace: Set via flags.
Use the Terraform Kubernetes Engine Module
mainThis module is a fork of the Google upstreambeta-private-clustermodule from theterraform-google-modules/terraform-google-kubernetes-enginerepository (specifically versionv24.0.0). It is intended for provisioning Kubernetes Engine clusters using Terraform.Serve Stable Diffusion XL using TPUs on GKE with MaxDiffusion
mainThis sample demonstrates how to serve Stable Diffusion XL (SDXL) using Cloud TPUs on Google Kubernetes Engine (GKE) with MaxDiffusion.
For a complete step-by-step tutorial on setting up this environment, refer to the official Google Cloud documentation.
Prepare data and batch-predict on TPU with Ray Data
mainThis sample demonstrates two primary workflows using Ray Data for TPU-based machine learning tasks:
Data Preparation (
prepare_preference_data.py): A CPU-distributed job that streams a raw preference dataset (e.g., from HuggingFace), reshapes it into the specific columns required by Tunix'sDPOTrainer(prompts,chosen_responses,rejected_responses), and writes the cleaned JSONL output to Google Cloud Storage (GCS).Batch Prediction (
batch_predict_tpu.py): An offline inference job that streams prompts through a model on a TPU slice. It usesiter_jax_batchesto yield batches as device-sharded JAX arrays directly to TPU hosts, allowing the CPU-based tokenization pipeline to overlap with the TPU forward pass. Predictions are written back to GCS.
This sample is designed to run against the cluster configured in the
../cluster/directory.Deploy a simple web application in a single region using Helm
mainThis sample provides a Helm chart for deploying a simple web application within a single Google Cloud region. It is designed to demonstrate basic single-region deployment patterns on Google Kubernetes Engine (GKE).Serve Llama open models on GKE
mainThis repository provides examples for serving Llama open models on Google Kubernetes Engine (GKE) using various serving engines. It demonstrates how to deploy and manage large language model (LLM) workloads on GKE infrastructure.Integrate Model Armor guardrails with GKE
mainThis sample demonstrates how to secure a Large Language Model (LLM) running on Google Kubernetes Engine (GKE) by using Model Armor to inspect traffic and defend against harmful inputs and outputs.
Key components of the implementation include:
- Infrastructure: Provisioning a GKE cluster equipped with NVIDIA L4 GPUs and Hyperdisk ML storage.
- Model Serving: Using vLLM to serve the Gemma 1.1 7b-it model.
- Networking: Deploying a GKE Gateway for regional external load balancing.
- Security: Implementing a security checkpoint via GKE Service Extensions to apply Model Armor policies that filter both prompts (inputs) and responses (outputs).