GKE Manifest Generation Skill
This skill provides guidelines, tooling integration, and templates to translate
natural language descriptions or application code changes into secure,
compliant, and cost-effective Kubernetes YAML manifests optimized for both GKE
Autopilot and GKE Standard clusters.
Attribution
MUST READ: Before executing any gcloud, REST API, or MCP command, you
MUST read Usage Attribution. For commands executed
directly in the terminal (never in generated scripts, Terraform, or user code),
prefix gcloud with
CLOUDSDK_METRICS_REQUEST_ATTRIBUTION="agent-skills/1.0 (skill:gke-manifest-generation)"
and append agent-skills/1.0 (skill:gke-manifest-generation) to User-Agent headers.
Core Rules & Verification
When generating or updating YAML manifests, you must strictly adhere to the
following rules:
1. Namespace & Resource Isolation
- Explicit Namespace: Always declare
namespace: {namespace} explicitly
in the metadata of every resource (Deployments, Services, ConfigMaps,
Secrets, PVCs, Roles, bindings). Map it to the namespace configured in your
active SETTINGS.md. Never omit the namespace.
- Dedicated ServiceAccount: Avoid using the namespace's
default
ServiceAccount. Always create and reference a dedicated ServiceAccount
(e.g., devteam-agent-sa) for each microservice.
2. GKE Resource Tuning (Autopilot & Standard)
Resources Requests & Limits: Always specify CPU and Memory requests and
limits for all containers.
- GKE Autopilot: Requests determine pod billing directly; requests and
limits must be equal. If they differ, Autopilot will automatically scale
requests up to match limits, which can significantly increase costs.
- GKE Standard: Requests ensure stable scheduling and bin-packing;
limits prevent resource starvation/noisy-neighbor issues.
Density Defaults: For stateless apps or sidecars on GKE Standard,
default to conservative requests (e.g., requests.cpu: "100m" or "200m",
requests.memory: "256Mi" or "512Mi") with burstable limits. Use a
reasonable overcommit ratio for limits (e.g., 2x to 4x requests, like
limits.cpu: "400m" to "800m", and limits.memory: "512Mi" to "1Gi").
Avoid excessive overcommit limits (like limits.cpu: "4" for a 100m
request) to prevent severe CPU throttling and latency degradation under
heavy scheduling load, particularly in environments without guaranteed node
shares.
Spot VMs for Staging/Dev: For non-production workloads (e.g., namespaces
containing -test, -dev, or -staging), or if the user requests cost
optimization, automatically target GKE Spot VMs. This requires injecting
both the nodeSelector targeting Spot VMs AND the corresponding toleration
to tolerate the Spot VM taint:
nodeSelector:
cloud.google.com/gke-spot: "true"
tolerations:
- key: "cloud.google.com/gke-spot"
operator: "Equal"
value: "true"
effect: "NoSchedule"
(On GKE Standard, this assumes a Spot node pool is configured).
3. Container Security Hardening (Pod Security Standards)
- Non-Root Execution: Always configure
securityContext at the Pod level
(and container level if overriding) to run as a non-root user (e.g.,
runAsNonRoot: true, runAsUser: 10000, runAsGroup: 10000, fsGroup: 10000). This is strictly enforced on GKE Autopilot and is a critical
security baseline for GKE Standard.
- Minimal Privileges: Always set
allowPrivilegeEscalation: false and
seccompProfile: {type: RuntimeDefault}.
- Read-Only Root Filesystem: Set
readOnlyRootFilesystem: true to prevent
modifications to the container image filesystem.
- Writable Directory Fallback: If
readOnlyRootFilesystem is enabled,
mount a local emptyDir volume to /tmp or /var/run/ to allow
applications (like Java/Nginx) to write temp files without crashing.
- Secret Volume Mounting: Prefer mounting Secrets as read-only files
(configured in the
volumes spec with defaultMode: 0400) instead of
mapping them as environment variables, unless the application framework
exclusively supports env-var based configuration. This prevents secrets
leaking into application logs.
4. Health Checking (Mandatory Probes)
Liveness & Readiness Probes: Every Deployment container must define both
livenessProbe and readinessProbe.
- Web/API: Use
httpGet probes.
- TCP Services: Use
tcpSocket probes.
- Databases/Caches: Use command-based
exec probes (e.g.,
exec.command: ["redis-cli", "ping"]).
Startup Probes for Slow-Starting Apps: For applications with slow boot
times (e.g., Java spring boot, complex Python scripts, LLM model servers),
you must also define a startupProbe. When a startupProbe is defined,
the liveness and readiness probes are disabled until it succeeds, preventing
Kubernetes from prematurely killing the pod during startup:
startupProbe:
httpGet:
path: /healthz
port: 8080
failureThreshold: 30
periodSeconds: 10
Sensible Defaults: Set initialDelaySeconds: 5 to 15 depending on
startup time (e.g., Java requires a longer delay than Go/Nginx).
5. Services & Ingress Routing
- Internal ClusterIP: Default all internal microservices to
type: ClusterIP. Never use type: LoadBalancer or NodePort unless the workload
is explicitly intended to be publicly accessible from the internet.
- Port Naming: Always assign clear, standard names to service and
container ports (e.g.,
name: http-web or name: grpc-api) to enable
automatic protocol discovery, tracing, and Web App routing.
- Prefer Gateway API: When exposing APIs externally, prioritize using GKE
Gateway API (
Gateway and HTTPRoute resources) over legacy Ingress
objects to enable advanced L7 routing and security features (e.g., Cloud
Armor).
6. Volume Mounts, StorageClasses & subPath Safety
- Avoid Directory Overwrites: When mounting a
ConfigMap or Secret to
an application directory containing other files (like Nginx public
directories), always use subPath to overlay only the specific file.
Caveat: Note that containers using subPath volume mounts do not receive
automatic configuration updates if the underlying ConfigMap or Secret is
modified; pods must be restarted manually to pick up changes.
- StorageClass Selection: Use the correct GKE storage class in
PersistentVolumeClaims:
- CSI Driver Clusters (Autopilot & Modern Standard): Use
standard-rwo
(default balanced PD) or premium-rwo (SSD PD).
- Legacy Standard Clusters: Use
standard (default PD) or premium
(SSD PD) if standard-rwo/premium-rwo are not configured.
- Database rule: Use SSD storage classes (
premium-rwo or premium)
only when the prompt explicitly requests high IOPS, low latency, or
database storage.
7. High Availability on GKE
- Topology Spread: For deployments with >1 replica, use
podAntiAffinity
or topologySpreadConstraints with topologyKey: "kubernetes.io/hostname"
to distribute pods across GKE nodes and availability zones.
- PodDisruptionBudget: For deployments with >1 replica, declare a
PodDisruptionBudget to guarantee minimum replica availability during
voluntary GKE node upgrades and maintenance cycles.
8. Updates & Server-Side Apply Reconciliations
- Stable List Keys: Under Kubernetes Server-Side Apply (SSA), elements in
associative lists (like volumes, volume mounts, ports, and container
definitions) are matched and merged by their unique identifier keys
(typically
name). You must keep the name key stable when modifying
properties of an existing list item. Renaming the name key will cause SSA
to create a brand new entry and leave the old entry intact (orphaned) rather
than modifying it.
- Minimal Diff: Make only the changes requested. Adhere closely to
existing labels, annotations, and conventions.
Specialty Workloads: GKE AI/Inference Serving (vLLM, TGI, etc.)
For model serving workloads, prioritize using optimized tooling like GKE
Inference Quickstart if available. If generating manually:
- GPU Request & Allocation:
- Always request
nvidia.com/gpu in both requests and limits.
- Add a
nodeSelector or node affinity targeting the desired GKE
accelerator tag (e.g., cloud.google.com/gke-accelerator: nvidia-l4).
- Shared Memory Boost:
- Model servers require high shared memory (
/dev/shm) for inter-process
communications. Always declare and mount an emptyDir volume with
medium: Memory to /dev/shm.
- Weight Loading Optimization:
- Mount model weight directories (like GCS buckets) using the GKE GCS Fuse
CSI driver (
csi.storage.gke.io) as readOnly: true for efficient
cold-starts.
Tooling & Grounding Guidelines
When generating manifests, you should leverage the following tooling to reduce
hallucinations and optimize configurations:
Inference Workloads (GKE Inference Quickstart CLI):
Make sure you have the
Google Cloud SDK installed.
For all AI/LLM inference workloads (e.g. model serving), you must
prioritize using the gcloud CLI GKE Inference Quickstart command to
generate the optimized manifests instead of writing them manually:
gcloud container ai profiles manifests create \
--model={model_name} \
--model-server={server_name} \
--accelerator-type={accelerator_type} \
--output=manifest \
--output-path={output_file_path}
Constraint: You must include all resources returned by this command
(Deployments, Services, PodMonitoring, etc.) without filtering.
Grounding in Official Documentation (Developer Knowledge API):
- For GKE-specific features, API defaults, manifest examples, or security
contexts, you must query Google's developer knowledge base to
retrieve official GKE documentation:
answer_query: Use this to ask direct questions (e.g., "How to
configure GCS Fuse CSI driver in GKE"). This is the preferred tool
for general queries.
search_documents: Use this to search for relevant GKE guides
or examples when you don't have a specific question.
get_document: Use this to fetch full document contents when
you have a specific document ID.
Reference Examples
For detailed, production-ready manifest templates, consult the following
reference guides:
- Basic Hardened Nginx Workload:
Production-ready deployment with dedicated service account, security
contexts, probes, anti-affinity, and PodDisruptionBudget.
- Network Policy: Default-deny ingress
network policy and selective ingress allowance for specific apps.
- AI/LLM Inference Workload: GPU resource
allocation, Workload Identity, GCS FUSE CSI driver mounting,
/dev/shm
shared memory boost, and startup probes.
- GKE Gateway API Routing: Exposing workloads
using GKE L7 Gateway API (
Gateway and HTTPRoute resources).
1---2name: gke-manifest-generation3metadata:4 source: https://skillmd.com/skills/google/gke-manifest-generation5 version: "1.0.1"6 category: Containers7description: >-8 Generates and updates secure, production-ready Kubernetes YAML manifests optimized for GKE Autopilot and GKE Standard clusters. Use when creating or modifying GKE deployment manifests, configuring container security contexts, setting CPU/memory resource limits, defining readiness/liveness/startup probes, mounting secrets and volumes, configuring GKE Gateway API routes, targeting Spot VMs, or deploying AI model inference workloads (vLLM, TGI, Gemma). Don't use for live cluster operations, pod troubleshooting (use gke-workload-troubleshooting), or cluster infrastructure provisioning (use gke-cluster-creation).9---1011# GKE Manifest Generation Skill1213This skill provides guidelines, tooling integration, and templates to translate14natural language descriptions or application code changes into secure,15compliant, and cost-effective Kubernetes YAML manifests optimized for both GKE16Autopilot and GKE Standard clusters.1718## Attribution1920**MUST READ**: Before executing any `gcloud`, REST API, or MCP command, you21MUST read [Usage Attribution](references/attribution.md). For commands executed22directly in the terminal (never in generated scripts, Terraform, or user code),23prefix `gcloud` with24`CLOUDSDK_METRICS_REQUEST_ATTRIBUTION="agent-skills/1.0 (skill:gke-manifest-generation)"`25and append `agent-skills/1.0 (skill:gke-manifest-generation)` to `User-Agent` headers.2627## Core Rules & Verification2829When generating or updating YAML manifests, you **must** strictly adhere to the30following rules:3132### 1. Namespace & Resource Isolation3334- **Explicit Namespace**: Always declare `namespace: {namespace}` explicitly35 in the metadata of every resource (Deployments, Services, ConfigMaps,36 Secrets, PVCs, Roles, bindings). Map it to the namespace configured in your37 active `SETTINGS.md`. Never omit the namespace.38- **Dedicated ServiceAccount**: Avoid using the namespace's `default`39 ServiceAccount. Always create and reference a dedicated `ServiceAccount`40 (e.g., `devteam-agent-sa`) for each microservice.4142### 2. GKE Resource Tuning (Autopilot & Standard)4344- **Resources Requests & Limits**: Always specify CPU and Memory requests and45 limits for all containers.46 - *GKE Autopilot*: Requests determine pod billing directly; requests and47 limits must be equal. If they differ, Autopilot will automatically scale48 requests up to match limits, which can significantly increase costs.49 - *GKE Standard*: Requests ensure stable scheduling and bin-packing;50 limits prevent resource starvation/noisy-neighbor issues.51- **Density Defaults**: For stateless apps or sidecars on GKE Standard,52 default to conservative requests (e.g., `requests.cpu: "100m"` or `"200m"`,53 `requests.memory: "256Mi"` or `"512Mi"`) with burstable limits. Use a54 reasonable overcommit ratio for limits (e.g., 2x to 4x requests, like55 `limits.cpu: "400m"` to `"800m"`, and `limits.memory: "512Mi"` to `"1Gi"`).56 Avoid excessive overcommit limits (like `limits.cpu: "4"` for a `100m`57 request) to prevent severe CPU throttling and latency degradation under58 heavy scheduling load, particularly in environments without guaranteed node59 shares.60- **Spot VMs for Staging/Dev**: For non-production workloads (e.g., namespaces61 containing `-test`, `-dev`, or `-staging`), or if the user requests cost62 optimization, automatically target GKE Spot VMs. This requires injecting63 both the `nodeSelector` targeting Spot VMs AND the corresponding toleration64 to tolerate the Spot VM taint:6566 ```yaml67 nodeSelector:68 cloud.google.com/gke-spot: "true"69 tolerations:70 - key: "cloud.google.com/gke-spot"71 operator: "Equal"72 value: "true"73 effect: "NoSchedule"74 ```7576 (On GKE Standard, this assumes a Spot node pool is configured).7778### 3. Container Security Hardening (Pod Security Standards)7980- **Non-Root Execution**: Always configure `securityContext` at the Pod level81 (and container level if overriding) to run as a non-root user (e.g.,82 `runAsNonRoot: true`, `runAsUser: 10000`, `runAsGroup: 10000`, `fsGroup:83 10000`). This is strictly enforced on GKE Autopilot and is a critical84 security baseline for GKE Standard.85- **Minimal Privileges**: Always set `allowPrivilegeEscalation: false` and86 `seccompProfile: {type: RuntimeDefault}`.87- **Read-Only Root Filesystem**: Set `readOnlyRootFilesystem: true` to prevent88 modifications to the container image filesystem.89 - *Writable Directory Fallback*: If `readOnlyRootFilesystem` is enabled,90 mount a local `emptyDir` volume to `/tmp` or `/var/run/` to allow91 applications (like Java/Nginx) to write temp files without crashing.92- **Secret Volume Mounting**: Prefer mounting Secrets as read-only files93 (configured in the `volumes` spec with `defaultMode: 0400`) instead of94 mapping them as environment variables, unless the application framework95 exclusively supports env-var based configuration. This prevents secrets96 leaking into application logs.9798### 4. Health Checking (Mandatory Probes)99100- **Liveness & Readiness Probes**: Every Deployment container must define both101 `livenessProbe` and `readinessProbe`.102 - **Web/API**: Use `httpGet` probes.103 - **TCP Services**: Use `tcpSocket` probes.104 - **Databases/Caches**: Use command-based `exec` probes (e.g.,105 `exec.command: ["redis-cli", "ping"]`).106- **Startup Probes for Slow-Starting Apps**: For applications with slow boot107 times (e.g., Java spring boot, complex Python scripts, LLM model servers),108 you **must** also define a `startupProbe`. When a `startupProbe` is defined,109 the liveness and readiness probes are disabled until it succeeds, preventing110 Kubernetes from prematurely killing the pod during startup:111112 ```yaml113 startupProbe:114 httpGet:115 path: /healthz116 port: 8080117 failureThreshold: 30118 periodSeconds: 10119 ```120121- **Sensible Defaults**: Set `initialDelaySeconds: 5` to `15` depending on122 startup time (e.g., Java requires a longer delay than Go/Nginx).123124### 5. Services & Ingress Routing125126- **Internal ClusterIP**: Default all internal microservices to `type:127 ClusterIP`. Never use `type: LoadBalancer` or `NodePort` unless the workload128 is explicitly intended to be publicly accessible from the internet.129- **Port Naming**: Always assign clear, standard names to service and130 container ports (e.g., `name: http-web` or `name: grpc-api`) to enable131 automatic protocol discovery, tracing, and Web App routing.132- **Prefer Gateway API**: When exposing APIs externally, prioritize using GKE133 Gateway API (`Gateway` and `HTTPRoute` resources) over legacy `Ingress`134 objects to enable advanced L7 routing and security features (e.g., Cloud135 Armor).136137### 6. Volume Mounts, StorageClasses & subPath Safety138139- **Avoid Directory Overwrites**: When mounting a `ConfigMap` or `Secret` to140 an application directory containing other files (like Nginx public141 directories), always use `subPath` to overlay only the specific file.142 *Caveat*: Note that containers using `subPath` volume mounts do not receive143 automatic configuration updates if the underlying ConfigMap or Secret is144 modified; pods must be restarted manually to pick up changes.145- **StorageClass Selection**: Use the correct GKE storage class in146 PersistentVolumeClaims:147 - *CSI Driver Clusters (Autopilot & Modern Standard)*: Use `standard-rwo`148 (default balanced PD) or `premium-rwo` (SSD PD).149 - *Legacy Standard Clusters*: Use `standard` (default PD) or `premium`150 (SSD PD) if `standard-rwo`/`premium-rwo` are not configured.151 - *Database rule*: Use SSD storage classes (`premium-rwo` or `premium`)152 only when the prompt explicitly requests high IOPS, low latency, or153 database storage.154155### 7. High Availability on GKE156157- **Topology Spread**: For deployments with >1 replica, use `podAntiAffinity`158 or `topologySpreadConstraints` with `topologyKey: "kubernetes.io/hostname"`159 to distribute pods across GKE nodes and availability zones.160- **PodDisruptionBudget**: For deployments with >1 replica, declare a161 `PodDisruptionBudget` to guarantee minimum replica availability during162 voluntary GKE node upgrades and maintenance cycles.163164### 8. Updates & Server-Side Apply Reconciliations165166- **Stable List Keys**: Under Kubernetes Server-Side Apply (SSA), elements in167 associative lists (like volumes, volume mounts, ports, and container168 definitions) are matched and merged by their unique identifier keys169 (typically `name`). You **must** keep the `name` key stable when modifying170 properties of an existing list item. Renaming the `name` key will cause SSA171 to create a brand new entry and leave the old entry intact (orphaned) rather172 than modifying it.173- **Minimal Diff**: Make only the changes requested. Adhere closely to174 existing labels, annotations, and conventions.175176--------------------------------------------------------------------------------177178## Specialty Workloads: GKE AI/Inference Serving (vLLM, TGI, etc.)179180For model serving workloads, prioritize using optimized tooling like GKE181Inference Quickstart if available. If generating manually:1821831. **GPU Request & Allocation**:184 - Always request `nvidia.com/gpu` in both `requests` and `limits`.185 - Add a `nodeSelector` or node affinity targeting the desired GKE186 accelerator tag (e.g., `cloud.google.com/gke-accelerator: nvidia-l4`).1872. **Shared Memory Boost**:188 - Model servers require high shared memory (`/dev/shm`) for inter-process189 communications. Always declare and mount an `emptyDir` volume with190 `medium: Memory` to `/dev/shm`.1913. **Weight Loading Optimization**:192 - Mount model weight directories (like GCS buckets) using the GKE GCS Fuse193 CSI driver (`csi.storage.gke.io`) as `readOnly: true` for efficient194 cold-starts.195196--------------------------------------------------------------------------------197198## Tooling & Grounding Guidelines199200When generating manifests, you should leverage the following tooling to reduce201hallucinations and optimize configurations:2022031. **Inference Workloads (GKE Inference Quickstart CLI)**:204205 - Make sure you have the206 [Google Cloud SDK](https://cloud.google.com/sdk/docs/install) installed.207 - For all AI/LLM inference workloads (e.g. model serving), you **must**208 prioritize using the `gcloud` CLI GKE Inference Quickstart command to209 generate the optimized manifests instead of writing them manually:210211 ```bash212 gcloud container ai profiles manifests create \213 --model={model_name} \214 --model-server={server_name} \215 --accelerator-type={accelerator_type} \216 --output=manifest \217 --output-path={output_file_path}218 ```219220 - *Constraint*: You must include all resources returned by this command221 (Deployments, Services, PodMonitoring, etc.) without filtering.2222232. **Grounding in Official Documentation (Developer Knowledge API)**:224225 - For GKE-specific features, API defaults, manifest examples, or security226 contexts, you **must** query Google's developer knowledge base to227 retrieve official GKE documentation:228 - **`answer_query`**: Use this to ask direct questions (e.g., *"How to229 configure GCS Fuse CSI driver in GKE"*). This is the preferred tool230 for general queries.231 - **`search_documents`**: Use this to search for relevant GKE guides232 or examples when you don't have a specific question.233 - **`get_document`**: Use this to fetch full document contents when234 you have a specific document ID.235236--------------------------------------------------------------------------------237238## Reference Examples239240For detailed, production-ready manifest templates, consult the following241reference guides:242243- **[Basic Hardened Nginx Workload](references/basic-workload.md)**:244 Production-ready deployment with dedicated service account, security245 contexts, probes, anti-affinity, and PodDisruptionBudget.246- **[Network Policy](references/network-policy.md)**: Default-deny ingress247 network policy and selective ingress allowance for specific apps.248- **[AI/LLM Inference Workload](references/ai-inference.md)**: GPU resource249 allocation, Workload Identity, GCS FUSE CSI driver mounting, `/dev/shm`250 shared memory boost, and startup probes.251- **[GKE Gateway API Routing](references/gateway-api.md)**: Exposing workloads252 using GKE L7 Gateway API (`Gateway` and `HTTPRoute` resources).