1
- # 使用 kustomize 定义 helm chart
1
+ # 使用 kustomize 对 helm chart s进行修改
2
2
3
3
[ last mile ] : https://testingclouds.wordpress.com/2018/07/20/844/
4
4
[ stable chart ] : https://github.com/helm/charts/tree/master/stable
5
5
[ Helm charts ] : https://github.com/helm/charts
6
6
[ _minecraft_ ] : https://github.com/helm/charts/tree/master/stable/minecraft
7
7
[ 插件 ] : ../../docs/plugins
8
8
9
- kustomize 并不会读取 [ Helm charts] ,但可以使用[ 插件 ] 来访问 [ Helm charts] 。
9
+ kustomize 并不会读取 [ Helm charts] ,但可以使用 generator ß来访问 [ Helm charts] 。
10
10
11
11
使用 [ last mile] 模式来结合 kustomize 和 helm ,使用一个 inflated chart 作为基础,然后使用 kustomize 在部署到集群的途中进行修改。
12
12
13
- 以下示例中使用的插件编码仅适用于 [ stable chart] 仓库中的 chart。该示例虽然使用 [ _ minecraft_ ] ,但可以应用于任何 chart。
13
+ 以下示例中使用的 generator 仅适用于 [ stable chart] 仓库中的 chart。该示例虽然使用 [ _ minecraft_ ] ,但可以应用于任何 chart。
14
14
15
15
假设 ` helm ` 已在你的 ` $PATH ` 中,建立一个工作空间:
16
16
17
- <!-- @makeWorkplace @helmtest -->
17
+ <!-- @makeWorkplace @test -->
18
18
``` bash
19
19
DEMO_HOME=$( mktemp -d)
20
20
mkdir -p $DEMO_HOME /base
@@ -28,7 +28,7 @@ mkdir -p $DEMO_HOME/prod
28
28
29
29
这可能涉及许多 kustomizations(参见其他示例),但在本示例中,将 ` dev- ` 名称前缀添加到所有资源:
30
30
31
- <!-- @writeKustDev @helmtest -->
31
+ <!-- @writeKustDev @test -->
32
32
``` bash
33
33
cat << 'EOF ' >$DEMO_HOME/dev/kustomization.yaml
34
34
namePrefix: dev-
39
39
40
40
同上,使用 ` namePrefix: prod- ` 定义生产 variant :
41
41
42
- <!-- @writeKustProd @helmtest -->
42
+ <!-- @writeKustProd @test -->
43
43
``` bash
44
44
cat << 'EOF ' >$DEMO_HOME/prod/kustomization.yaml
45
45
namePrefix: prod-
52
52
53
53
定义这个 base:
54
54
55
- <!-- @writeKustDev @helmtest -->
55
+ <!-- @writeKustDev @test -->
56
56
``` bash
57
57
cat << 'EOF ' >$DEMO_HOME/base/kustomization.yaml
58
58
generators:
@@ -66,7 +66,7 @@ base 指向一个名为 `chartInflator.yaml` 的生成配置文件。
66
66
67
67
创建配置文件 ` chartInflator.yaml ` ,指定 chart 名称为 _ minecraft_ :
68
68
69
- <!-- @writeGeneratorConfig @helmtest -->
69
+ <!-- @writeGeneratorConfig @test -->
70
70
``` bash
71
71
cat << 'EOF ' >$DEMO_HOME/base/chartInflator.yaml
72
72
apiVersion: someteam.example.com/v1
81
81
82
82
将插件下载到 ` DEMO_HOME ` 并赋予其执行权限:
83
83
84
- <!-- @installPlugin @helmtest -->
84
+ <!-- @installPlugin @test -->
85
85
``` bash
86
86
plugin=plugin/someteam.example.com/v1/chartinflator/ChartInflator
87
87
curl -s --create-dirs -o \
@@ -99,7 +99,7 @@ chmod a+x $DEMO_HOME/kustomize/$plugin
99
99
tree $DEMO_HOME
100
100
```
101
101
102
- 将会得到类似的东西 :
102
+ 将会得倒类似的目录及文件 :
103
103
104
104
> ``` bash
105
105
> /tmp/whatever
@@ -120,7 +120,7 @@ tree $DEMO_HOME
120
120
121
121
运行 kustomize 定义一个 helper function 来传入正确的环境和常见标志:
122
122
123
- < ! -- @defineKustomizeIt @helmtest -->
123
+ < ! -- @defineKustomizeIt @test -->
124
124
` ` `
125
125
function kustomizeIt {
126
126
XDG_CONFIG_HOME=$DEMO_HOME \
@@ -131,7 +131,7 @@ function kustomizeIt {
131
131
132
132
最终构建 ` prod ` variant。这里要注意的是,所有资源名称现在都具有 ` prod- ` 前缀:
133
133
134
- <!-- @doProd @helmtest -->
134
+ <!-- @doProd @test -->
135
135
``` bash
136
136
clear
137
137
kustomizeIt prod
@@ -144,22 +144,23 @@ kustomizeIt prod
144
144
diff <( kustomizeIt dev) <( kustomizeIt prod) | more
145
145
```
146
146
147
- 在 base上 运行 kustomize 查看未修改但已 inflated 的 chart。这里的每次调用都是重新下载并 re-inflating chart。
147
+ 在 base上 运行 kustomize 查看未修改但已展开的 chart。
148
+ 这里的每次调用都是重新下载并重新展开 chart。
148
149
149
- <!-- @showBase @helmtest -->
150
+ <!-- @showBase @test -->
150
151
``` bash
151
152
kustomizeIt base
152
153
```
153
154
154
155
## 使用本地 chart
155
156
156
- 上面的示例由于未在配置中指定本地 chart 的主目录,则使用 kustomize 构建将 chart 的新副本 fetche 到临时目录 。
157
+ 上面的示例由于未在配置中指定本地 chart 的主目录,所以kustomize会取得远程chart的副本并存在临时目录中 。
157
158
158
- 要禁止 fetche ,请明确指定 chart home ,并确保图表已存在。
159
+ 要禁止 fetch ,请明确指定 ` charHome ` ,并确保chart 已经被保存在该目录下
159
160
160
161
要进行演示,并且不会干扰您现有的 helm 环境,请执行以下操作:
161
162
162
- <!-- @helmInit @helmtest -->
163
+ <!-- @helmInit @test -->
163
164
``` bash
164
165
helmHome=$DEMO_HOME /dothelm
165
166
chartHome=$DEMO_HOME /base/charts
@@ -175,14 +176,14 @@ doHelm init --client-only >& /dev/null
175
176
176
177
现在下载 chart ; 可以再次使用的 [ _ minecraft_ ] (也可以使用其他的 chart ):
177
178
178
- <!-- @fetchChart @helmtest -->
179
+ <!-- @fetchChart @test -->
179
180
``` bash
180
181
doHelm fetch --untar \
181
182
--untardir $chartHome \
182
183
stable/minecraft
183
184
```
184
185
185
- 使用 tree 查看更多信息;helm 配置数据和完成的 chart 副本:
186
+ 使用 tree 查看更多信息;helm 配置数据和完整的 chart 副本:
186
187
187
188
<!-- @tree -->
188
189
``` bash
@@ -191,24 +192,24 @@ tree $DEMO_HOME
191
192
192
193
将 ` chartHome ` 字段添加到生成器的配置文件中,以便可以查找本地 chart:
193
194
194
- <!-- @modifyGenConfig @helmtest -->
195
+ <!-- @modifyGenConfig @test -->
195
196
``` bash
196
197
echo " chartHome: $chartHome " >> $DEMO_HOME /base/chartInflator.yaml
197
198
```
198
199
199
200
更改 values 文件,用来展示本地 chart 的更改:
200
201
201
- <!-- @valueChange @helmtest -->
202
+ <!-- @valueChange @test -->
202
203
```
203
204
sed -i 's/CHANGEME!/SOMETHINGELSE/' $chartHome/minecraft/values.yaml
204
205
sed -i 's/LoadBalancer/NodePort/' $chartHome/minecraft/values.yaml
205
206
```
206
207
207
208
最后进行构建:
208
209
209
- <!-- @finalProd @helmtest -->
210
+ <!-- @finalProd @test -->
210
211
``` bash
211
212
kustomizeIt prod
212
213
```
213
214
214
- 观察从变化 ` LoadBalancer ` 到 ` NodePort ` ,并更改编码的密码 。
215
+ 观察结果中 ` LoadBalancer ` 变为 ` NodePort ` ,并且加密的密码也有所不同 。
0 commit comments