Setting the file. One moment. Configmap Template · K8S Manifest Generator · wshobson/agents · Skills Docs19
Workflow Orchestration Patterns
57
Nx Workspace Patterns
Trace To Training Data
Web Component Design
115
apiVersion
— line 115
This file
- Number
- 92.4
- Position
- 4 of 6
- Type
- YAML
- Size
- 6 KB
- Lines
- 296
assets/configmap-template.yaml
YAML·296 lines·6 KB
<instance-name>
13data:
14 # Simple key-value pairs
15 APP_ENV: "production"
16 LOG_LEVEL: "info"
17 DATABASE_HOST: "db.example.com"
18 DATABASE_PORT: "5432"
19 CACHE_TTL: "3600"
20 MAX_CONNECTIONS: "100"
21
22---
23# Template 2: Configuration File
24apiVersion: v1
25kind: ConfigMap
26metadata:
27 name: <app-name>-config-file
28 namespace: <namespace>
29 labels:
30 app.kubernetes.io/name: <app-name>
31data:
32 # Application configuration file
33 application.yaml: |
34 server:
35 port: 8080
36 host: 0.0.0.0
37
38 logging:
39 level: INFO
40 format: json
41
42 database:
43 host: db.example.com
44 port: 5432
45 pool_size: 20
46 timeout: 30
47
48 cache:
49 enabled: true
50 ttl: 3600
51 max_entries: 10000
52
53 features:
54 new_ui: true
55 beta_features: false
56
57---
58# Template 3: Multiple Configuration Files
59apiVersion: v1
60kind: ConfigMap
61metadata:
62 name: <app-name>-multi-config
63 namespace: <namespace>
64 labels:
65 app.kubernetes.io/name: <app-name>
66data:
67 # Nginx configuration
68 nginx.conf: |
69 user nginx;
70 worker_processes auto;
71 error_log /var/log/nginx/error.log warn;
72 pid /var/run/nginx.pid;
73
74 events {
75 worker_connections 1024;
76 }
77
78 http {
79 include /etc/nginx/mime.types;
80 default_type application/octet-stream;
81
82 log_format main '$remote_addr - $remote_user [$time_local] "$request" '
83 '$status $body_bytes_sent "$http_referer" '
84 '"$http_user_agent" "$http_x_forwarded_for"';
85
86 access_log /var/log/nginx/access.log main;
87 sendfile on;
88 keepalive_timeout 65;
89
90 include /etc/nginx/conf.d/*.conf;
91 }
92
93 # Default site configuration
94 default.conf: |
95 server {
96 listen 80;
97 server_name _;
98
99 location / {
100 proxy_pass http://backend:8080;
101 proxy_set_header Host $host;
102 proxy_set_header X-Real-IP $remote_addr;
103 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
104 proxy_set_header X-Forwarded-Proto $scheme;
105 }
106
107 location /health {
108 access_log off;
109 return 200 "healthy\n";
110 }
111 }
112
113---
114# Template 4: JSON Configuration
115apiVersion: v1
116kind: ConfigMap
117metadata:
118 name: <app-name>-json-config
119 namespace: <namespace>
120 labels:
121 app.kubernetes.io/name: <app-name>
122data:
123 config.json: |
124 {
125 "server": {
126 "port": 8080,
127 "host": "0.0.0.0",
128 "timeout": 30
129 },
130 "database": {
131 "host": "postgres.example.com",
132 "port": 5432,
133 "database": "myapp",
134 "pool": {
135 "min": 2,
136 "max": 20
137 }
138 },
139 "redis": {
140 "host": "redis.example.com",
141 "port": 6379,
142 "db": 0
143 },
144 "features": {
145 "auth": true,
146 "metrics": true,
147 "tracing": true
148 }
149 }
150
151---
152# Template 5: Environment-Specific Configuration
153apiVersion: v1
154kind: ConfigMap
155metadata:
156 name: <app-name>-prod-config
157 namespace: production
158 labels:
159 app.kubernetes.io/name: <app-name>
160 environment: production
161data:
162 APP_ENV: "production"
163 LOG_LEVEL: "warn"
164 DEBUG: "false"
165 RATE_LIMIT: "1000"
166 CACHE_TTL: "3600"
167 DATABASE_POOL_SIZE: "50"
168 FEATURE_FLAG_NEW_UI: "true"
169 FEATURE_FLAG_BETA: "false"
170
171---
172# Template 6: Script Configuration
173apiVersion: v1
174kind: ConfigMap
175metadata:
176 name: <app-name>-scripts
177 namespace: <namespace>
178 labels:
179 app.kubernetes.io/name: <app-name>
180data:
181 # Initialization script
182 init.sh: |
183 #!/bin/bash
184 set -e
185
186 echo "Running initialization..."
187
188 # Wait for database
189 until nc -z $DATABASE_HOST $DATABASE_PORT; do
190 echo "Waiting for database..."
191 sleep 2
192 done
193
194 echo "Database is ready!"
195
196 # Run migrations
197 if [ "$RUN_MIGRATIONS" = "true" ]; then
198 echo "Running database migrations..."
199 ./migrate up
200 fi
201
202 echo "Initialization complete!"
203
204 # Health check script
205 healthcheck.sh: |
206 #!/bin/bash
207
208 # Check application health endpoint
209 response=$(curl -sf http://localhost:8080/health)
210
211 if [ $? -eq 0 ]; then
212 echo "Health check passed"
213 exit 0
214 else
215 echo "Health check failed"
216 exit 1
217 fi
218
219---
220# Template 7: Prometheus Configuration
221apiVersion: v1
222kind: ConfigMap
223metadata:
224 name: prometheus-config
225 namespace: monitoring
226 labels:
227 app.kubernetes.io/name: prometheus
228data:
229 prometheus.yml: |
230 global:
231 scrape_interval: 15s
232 evaluation_interval: 15s
233 external_labels:
234 cluster: 'production'
235 region: 'us-west-2'
236
237 alerting:
238 alertmanagers:
239 - static_configs:
240 - targets:
241 - alertmanager:9093
242
243 rule_files:
244 - /etc/prometheus/rules/*.yml
245
246 scrape_configs:
247 - job_name: 'kubernetes-pods'
248 kubernetes_sd_configs:
249 - role: pod
250 relabel_configs:
251 - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape]
252 action: keep
253 regex: true
254 - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_path]
255 action: replace
256 target_label: __metrics_path__
257 regex: (.+)
258 - source_labels: [__address__, __meta_kubernetes_pod_annotation_prometheus_io_port]
259 action: replace
260 target_label: __address__
261 regex: ([^:]+)(?::\d+)?;(\d+)
262 replacement: $1:$2
263
264---
265# Usage Examples:
266#
267# 1. Mount as environment variables:
268# envFrom:
269# - configMapRef:
270# name: <app-name>-config
271#
272# 2. Mount as files:
273# volumeMounts:
274# - name: config
275# mountPath: /etc/app
276# volumes:
277# - name: config
278# configMap:
279# name: <app-name>-config-file
280#
281# 3. Mount specific keys as files:
282# volumes:
283# - name: nginx-config
284# configMap:
285# name: <app-name>-multi-config
286# items:
287# - key: nginx.conf
288# path: nginx.conf
289#
290# 4. Use individual environment variables:
291# env:
292# - name: LOG_LEVEL
293# valueFrom:
294# configMapKeyRef:
295# name: <app-name>-config
296# key: LOG_LEVEL