1
---
2
name: gke-manifest-generation
3
metadata:
4
version: "1.0.2"
5
category: Containers
6
description: >-
7
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).
8
---
9
10
# GKE Manifest Generation Skill
11
12
This skill provides guidelines, tooling integration, and templates to translate
13
natural language descriptions or application code changes into secure,
14
compliant, and cost-effective Kubernetes YAML manifests optimized for both GKE
15
Autopilot and GKE Standard clusters.
16
17
## Attribution
18
19
**MUST READ**: Before executing any `gcloud`, REST API, or MCP command, you
20
MUST read [Usage Attribution](references/attribution.md). For commands executed
21
directly in the terminal (never in generated scripts, Terraform, or user code),
22
prefix `gcloud` with
23
`CLOUDSDK_METRICS_REQUEST_ATTRIBUTION="agent-skills/1.0 (skill:gke-manifest-generation)"`
24
and append `agent-skills/1.0 (skill:gke-manifest-generation)` to `User-Agent`
25
headers.
26
27
## Core Rules & Verification
28
29
When generating or updating YAML manifests, you **must** strictly adhere to the
30
following rules:
31
32
### 1. Namespace & Resource Isolation
33
34
- **Explicit Namespace**: Always declare `namespace: {namespace}` explicitly
35
in the metadata of every resource (Deployments, Services, ConfigMaps,
36
Secrets, PVCs, Roles, bindings). Map it to the namespace configured in your
37
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.
41
42
### 2. GKE Resource Tuning (Autopilot & Standard)
43
44
- **Resources Requests & Limits**: Always specify CPU and Memory requests and
45
limits for all containers.
46
- *GKE Autopilot*: Requests determine pod billing directly; requests and
47
limits must be equal. If they differ, Autopilot will automatically scale
48
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 a
54
reasonable overcommit ratio for limits (e.g., 2x to 4x requests, like
55
`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 under
58
heavy scheduling load, particularly in environments without guaranteed node
59
shares.
60
- **Spot VMs for Staging/Dev**: For non-production workloads (e.g., namespaces
61
containing `-test`, `-dev`, or `-staging`), or if the user requests cost
62
optimization, automatically target GKE Spot VMs. This requires injecting
63
both the `nodeSelector` targeting Spot VMs AND the corresponding toleration
64
to tolerate the Spot VM taint:
65
66
```yaml
67
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
```
75
76
(On GKE Standard, this assumes a Spot node pool is configured).
77
78
### 3. Container Security Hardening (Pod Security Standards)
79
80
- **Non-Root Execution**: Always configure `securityContext` at the Pod level
81
(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 critical
84
security baseline for GKE Standard.
85
- **Minimal Privileges**: Always set `allowPrivilegeEscalation: false` and
86
`seccompProfile: {type: RuntimeDefault}`.
87
- **Read-Only Root Filesystem**: Set `readOnlyRootFilesystem: true` to prevent
88
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 allow
91
applications (like Java/Nginx) to write temp files without crashing.
92
- **Secret Volume Mounting**: Prefer mounting Secrets as read-only files
93
(configured in the `volumes` spec with `defaultMode: 0400`) instead of
94
mapping them as environment variables, unless the application framework
95
exclusively supports env-var based configuration. This prevents secrets
96
leaking into application logs.
97
98
### 4. Health Checking (Mandatory Probes)
99
100
- **Liveness & Readiness Probes**: Every Deployment container must define both
101
`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 boot
107
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, preventing
110
Kubernetes from prematurely killing the pod during startup:
111
112
```yaml
113
startupProbe:
114
httpGet:
115
path: /healthz
116
port: 8080
117
failureThreshold: 30
118
periodSeconds: 10
119
```
120
121
- **Sensible Defaults**: Set `initialDelaySeconds: 5` to `15` depending on
122
startup time (e.g., Java requires a longer delay than Go/Nginx).
123
124
### 5. Services & Ingress Routing
125
126
- **Internal ClusterIP**: Default all internal microservices to `type:
127
ClusterIP`. Never use `type: LoadBalancer` or `NodePort` unless the workload
128
is explicitly intended to be publicly accessible from the internet.
129
- **Port Naming**: Always assign clear, standard names to service and
130
container ports (e.g., `name: http-web` or `name: grpc-api`) to enable
131
automatic protocol discovery, tracing, and Web App routing.
132
- **Prefer Gateway API**: When exposing APIs externally, prioritize using GKE
133
Gateway API (`Gateway` and `HTTPRoute` resources) over legacy `Ingress`
134
objects to enable advanced L7 routing and security features (e.g., Cloud
135
Armor).
136
137
### 6. Volume Mounts, StorageClasses & subPath Safety
138
139
- **Avoid Directory Overwrites**: When mounting a `ConfigMap` or `Secret` to
140
an application directory containing other files (like Nginx public
141
directories), always use `subPath` to overlay only the specific file.
142
*Caveat*: Note that containers using `subPath` volume mounts do not receive
143
automatic configuration updates if the underlying ConfigMap or Secret is
144
modified; pods must be restarted manually to pick up changes.
145
- **StorageClass Selection**: Use the correct GKE storage class in
146
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, or
153
database storage.
154
155
### 7. High Availability on GKE
156
157
- **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 a
161
`PodDisruptionBudget` to guarantee minimum replica availability during
162
voluntary GKE node upgrades and maintenance cycles.
163
164
### 8. Updates & Server-Side Apply Reconciliations
165
166
- **Stable List Keys**: Under Kubernetes Server-Side Apply (SSA), elements in
167
associative lists (like volumes, volume mounts, ports, and container
168
definitions) are matched and merged by their unique identifier keys
169
(typically `name`). You **must** keep the `name` key stable when modifying
170
properties of an existing list item. Renaming the `name` key will cause SSA
171
to create a brand new entry and leave the old entry intact (orphaned) rather
172
than modifying it.
173
- **Minimal Diff**: Make only the changes requested. Adhere closely to
174
existing labels, annotations, and conventions.
175
176
--------------------------------------------------------------------------------
177
178
## Specialty Workloads: GKE AI/Inference Serving (vLLM, TGI, etc.)
179
180
For model serving workloads, prioritize using optimized tooling like GKE
181
Inference Quickstart if available. If generating manually:
182
183
1. **GPU Request & Allocation**:
184
- Always request `nvidia.com/gpu` in both `requests` and `limits`.
185
- Add a `nodeSelector` or node affinity targeting the desired GKE
186
accelerator tag (e.g., `cloud.google.com/gke-accelerator: nvidia-l4`).
187
2. **Shared Memory Boost**:
188
- Model servers require high shared memory (`/dev/shm`) for inter-process
189
communications. Always declare and mount an `emptyDir` volume with
190
`medium: Memory` to `/dev/shm`.
191
3. **Weight Loading Optimization**:
192
- Mount model weight directories (like GCS buckets) using the GKE GCS Fuse
193
CSI driver (`gcsfuse.csi.storage.gke.io`) as `readOnly: true` for
194
efficient cold-starts.
195
196
--------------------------------------------------------------------------------
197
198
## Tooling & Grounding Guidelines
199
200
When generating manifests, you should leverage the following tooling to reduce
201
hallucinations and optimize configurations:
202
203
1. **Inference Workloads (GKE Inference Quickstart CLI)**:
204
205
- Make sure you have the
206
[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 to
209
generate the optimized manifests instead of writing them manually:
210
211
```bash
212
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
```
219
220
- *Constraint*: You must include all resources returned by this command
221
(Deployments, Services, PodMonitoring, etc.) without filtering.
222
223
2. **Grounding in Official Documentation (Developer Knowledge API)**:
224
225
- For GKE-specific features, API defaults, manifest examples, or security
226
contexts, you **must** query Google's developer knowledge base to
227
retrieve official GKE documentation:
228
- **`answer_query`**: Use this to ask direct questions (e.g., *"How to
229
configure GCS Fuse CSI driver in GKE"*). This is the preferred tool
230
for general queries.
231
- **`search_documents`**: Use this to search for relevant GKE guides
232
or examples when you don't have a specific question.
233
- **`get_document`**: Use this to fetch full document contents when
234
you have a specific document ID.
235
236
--------------------------------------------------------------------------------
237
238
## Reference Examples
239
240
For detailed, production-ready manifest templates, consult the following
241
reference guides:
242
243
- **[Basic Hardened Nginx Workload](references/basic-workload.md)**:
244
Production-ready deployment with dedicated service account, security
245
contexts, probes, anti-affinity, and PodDisruptionBudget.
246
- **[Network Policy](references/network-policy.md)**: Default-deny ingress
247
network policy and selective ingress allowance for specific apps.
248
- **[AI/LLM Inference Workload](references/ai-inference.md)**: GPU resource
249
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 workloads
252
using GKE L7 Gateway API (`Gateway` and `HTTPRoute` resources).
253