Skip to content

Commit ece5da2

Browse files
committed
feat: Add nginx example to demonstrate helm-values-manager usage
- Add example using Bitnami nginx chart - Demonstrate value management for staging and production - Show validation capabilities - Include cleanup instructions and .gitignore - Focus on simplified configuration for clarity
1 parent 9553894 commit ece5da2

File tree

3 files changed

+223
-0
lines changed

3 files changed

+223
-0
lines changed

example/nginx/.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Generated value files
2+
*.nginx-app.values.yaml
3+
4+
# Generated manifest files
5+
*-manifests.yaml
6+
7+
# Helm Values Manager files
8+
helm-values.json
9+
.helm-values.lock
10+
11+
# Temporary files that might be created during development
12+
*.tmp
13+
*.bak

example/nginx/README.md

Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
# Helm Values Manager Example
2+
3+
This example demonstrates how to use the helm-values-manager plugin to manage different configurations for staging and production environments using the Bitnami Nginx chart.
4+
5+
## Reference Values
6+
7+
Here are the reference values that we'll be managing across environments:
8+
9+
### Base Values (common.yaml)
10+
11+
```yaml
12+
nginx:
13+
image:
14+
registry: docker.io
15+
repository: bitnami/nginx
16+
tag: latest
17+
pullPolicy: IfNotPresent
18+
```
19+
20+
### Staging Values (staging.yaml)
21+
22+
```yaml
23+
nginx:
24+
replicaCount: 1
25+
26+
service:
27+
type: ClusterIP
28+
port: 80
29+
30+
ingress:
31+
enabled: true
32+
hostname: staging.example.com
33+
34+
metrics:
35+
enabled: false
36+
```
37+
38+
### Production Values (production.yaml)
39+
40+
```yaml
41+
nginx:
42+
replicaCount: 3
43+
44+
service:
45+
type: LoadBalancer
46+
port: 80
47+
48+
ingress:
49+
enabled: true
50+
hostname: example.com
51+
tls: true
52+
53+
metrics:
54+
enabled: true
55+
```
56+
57+
## Setup and Usage
58+
59+
1. Add the Bitnami repository:
60+
61+
```bash
62+
helm repo add bitnami https://charts.bitnami.com/bitnami
63+
helm repo update
64+
```
65+
66+
2. Initialize helm-values-manager for the nginx release:
67+
68+
```bash
69+
helm values-manager init --release nginx-app
70+
```
71+
72+
3. Add value configurations with descriptions and validation:
73+
74+
```bash
75+
# Core configurations
76+
helm values-manager add-value-config --path nginx.replicaCount --description "Number of nginx replicas" --required
77+
helm values-manager add-value-config --path nginx.service.type --description "Kubernetes service type (ClusterIP/LoadBalancer)" --required
78+
helm values-manager add-value-config --path nginx.service.port --description "Service port number" --required
79+
80+
# Ingress configuration
81+
helm values-manager add-value-config --path nginx.ingress.enabled --description "Enable ingress" --required
82+
helm values-manager add-value-config --path nginx.ingress.hostname --description "Ingress hostname"
83+
helm values-manager add-value-config --path nginx.ingress.tls --description "Enable TLS for ingress"
84+
85+
# Metrics configuration
86+
helm values-manager add-value-config --path nginx.metrics.enabled --description "Enable prometheus metrics"
87+
```
88+
89+
4. Add deployments for different environments:
90+
91+
```bash
92+
helm values-manager add-deployment staging
93+
helm values-manager add-deployment production
94+
```
95+
96+
5. Set values for staging environment:
97+
98+
```bash
99+
# Basic configuration
100+
helm values-manager set-value --path nginx.replicaCount --value 1 --deployment staging
101+
helm values-manager set-value --path nginx.service.type --value ClusterIP --deployment staging
102+
helm values-manager set-value --path nginx.service.port --value 80 --deployment staging
103+
104+
# Ingress configuration
105+
helm values-manager set-value --path nginx.ingress.enabled --value true --deployment staging
106+
helm values-manager set-value --path nginx.ingress.hostname --value staging.example.com --deployment staging
107+
108+
# Metrics configuration
109+
helm values-manager set-value --path nginx.metrics.enabled --value false --deployment staging
110+
```
111+
112+
6. Generate staging values:
113+
114+
```bash
115+
# Generate staging values - this should succeed as all required values are set
116+
helm values-manager generate --deployment staging
117+
```
118+
119+
7. Set up production environment (demonstrating validation):
120+
121+
```bash
122+
# Set some of the production values, intentionally omitting service configuration
123+
helm values-manager set-value --path nginx.replicaCount --value 3 --deployment production
124+
helm values-manager set-value --path nginx.ingress.enabled --value true --deployment production
125+
helm values-manager set-value --path nginx.ingress.hostname --value example.com --deployment production
126+
helm values-manager set-value --path nginx.ingress.tls --value true --deployment production
127+
helm values-manager set-value --path nginx.metrics.enabled --value true --deployment production
128+
129+
# Try to generate values - this should fail with validation errors
130+
helm values-manager generate --deployment production
131+
```
132+
133+
The above command will fail with validation errors because we haven't set two required values:
134+
135+
1. `nginx.service.type`
136+
2. `nginx.service.port`
137+
138+
This demonstrates how helm-values-manager helps catch missing configurations early in the deployment process.
139+
140+
8. Fix validation errors and complete production setup:
141+
142+
```bash
143+
# Set the missing required values
144+
helm values-manager set-value --path nginx.service.type --value LoadBalancer --deployment production
145+
helm values-manager set-value --path nginx.service.port --value 80 --deployment production
146+
147+
# Now the generate command should succeed
148+
helm values-manager generate --deployment production
149+
```
150+
151+
9. Verify configurations using helm template:
152+
153+
```bash
154+
# Template the chart for staging environment
155+
helm template nginx-staging bitnami/nginx -f common.yaml -f staging.nginx-app.values.yaml
156+
157+
# Template the chart for production environment
158+
helm template nginx-prod bitnami/nginx -f common.yaml -f prod.nginx-app.values.yaml
159+
160+
# You can also save the templated output to files for inspection
161+
helm template nginx-staging bitnami/nginx -f common.yaml -f staging.nginx-app.values.yaml > staging-manifests.yaml
162+
helm template nginx-prod bitnami/nginx -f common.yaml -f prod.nginx-app.values.yaml > prod-manifests.yaml
163+
```
164+
165+
The helm template command will show you the actual Kubernetes manifests that would be created, allowing you to:
166+
167+
- Verify that all values are correctly applied
168+
- Inspect the differences between environments
169+
- Catch any issues before actual deployment
170+
171+
## Key Benefits Demonstrated
172+
173+
1. **Configuration Validation**: Early detection of missing or invalid configurations through required value definitions
174+
2. **Value Documentation**: Each configuration value is documented with clear descriptions
175+
3. **Environment Separation**: Clean separation between staging and production configurations
176+
4. **Structured Management**: Organized way to add and modify values
177+
5. **Value Tracking**: Easy to track what values are available and required
178+
179+
## Cleanup
180+
181+
To clean up the example:
182+
183+
1. Remove generated value files:
184+
185+
```bash
186+
rm -f *.nginx-app.values.yaml
187+
```
188+
189+
2. Remove generated manifest files:
190+
191+
```bash
192+
rm -f *-manifests.yaml
193+
```
194+
195+
3. Remove helm-values-manager files:
196+
197+
```bash
198+
rm -f helm-values.json .helm-values.lock
199+
```

example/nginx/common.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
nginx:
2+
image:
3+
registry: docker.io
4+
repository: bitnami/nginx
5+
tag: latest
6+
pullPolicy: IfNotPresent
7+
8+
serverBlock: ""
9+
10+
metrics:
11+
enabled: false

0 commit comments

Comments
 (0)