英文:
Helm Chart - How to set configMap from values.yaml?
问题
我有一个名为`application.yaml`的文件来自我的Spring配置。我想在ConfigMap中重用这个文件。我在Helm的`values.yaml`中定义了这些属性,然后在`configmap.yaml`中读取它们。
以下是所有的文件:
**application.yaml**
invoice:
catalog-service-uri: http://catalog-service
spring:
flyway:
url: jdbc:postgresql://invoice-postgres/invoice_order
r2dbc:
url: r2dbc:postgresql://invoice-postgres/invoice_order
rabbitmq:
host: invoice-rabbitmq
security:
oauth2:
resourceserver:
jwt:
issuer-uri: http://ecomm-keycloak/realms/EcommRealm
**values.yaml**
configMapData:
application.yaml: |-
invoice:
catalog-service-uri: http://catalog-service
spring:
flyway:
url: jdbc:postgresql://invoice-postgres/invoice_order
r2dbc:
url: r2dbc:postgresql://invoice-postgres/invoice_order
rabbitmq:
host: invoice-rabbitmq
security:
oauth2:
resourceserver:
jwt:
issuer-uri: http://ecomm-keycloak/realms/EcommRealm
**configmap.yaml**
apiVersion: v1
kind: ConfigMap
metadata:
name: order-config
labels:
app: order-service
data:
{{- range $key, $value := .Values.configMapData }}
{{ $key }}: |-
{{ $value | indent 4 }}
{{- end }}
使用这个配置,我得到了错误:
**msg: 'error unmarshalling resource: error converting YAML to JSON: yaml: line 7:
did not find expected node content'**
这个配置有什么问题?
有没有更好的方法来做同样的事情?
任何帮助将不胜感激。
谢谢
英文:
I have a file application.yaml
from my spring configuration. I want to reuse this file in ConfigMap. I defined these properties in Helm's values.yaml
and then reading them in configmap.yaml
.
Here are all the files:
application.yaml
invoice:
catalog-service-uri: http://catalog-service
spring:
flyway:
url: jdbc:postgresql://invoice-postgres/invoice_order
r2dbc:
url: r2dbc:postgresql://invoice-postgres/invoice_order
rabbitmq:
host: invoice-rabbitmq
security:
oauth2:
resourceserver:
jwt:
issuer-uri: http://ecomm-keycloak/realms/EcommRealm
values.yaml
configMapData:
application.yaml: |-
invoice:
catalog-service-uri: http://catalog-service
spring:
flyway:
url: jdbc:postgresql://invoice-postgres/invoice_order
r2dbc:
url: r2dbc:postgresql://invoice-postgres/invoice_order
rabbitmq:
host: invoice-rabbitmq
security:
oauth2:
resourceserver:
jwt:
issuer-uri: http://ecomm-keycloak/realms/EcommRealm
configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: order-config
labels:
app: order-service
data:
{{- range $key, $value := .Values.configMapData }}
{{ $key }}: |-
{{ $value | indent 4 }}
{{- end }}
With this configuration, I am getting error:
msg: 'error unmarshalling resource: error converting YAML to JSON: yaml: line 7:
did not find expected node content'
What's wrong with this configuration?
Is there any better way of doing the same?
Any help would be highly appreciated.
Thanks
答案1
得分: 1
apiVersion: v1
kind: ConfigMap
metadata:
name: order-config
labels:
app: order-service
data:
{{- .Values.configMapData | toYaml | nindent 2 }}
英文:
Try this:
apiVersion: v1
kind: ConfigMap
metadata:
name: order-config
labels:
app: order-service
data:
{{- .Values.configMapData | toYaml | nindent 2 }}
答案2
得分: 0
Andromeda的回答效果不错。如果您想直接使用application.yaml
文件,可以选择以下方法。
将文件放在您的helm-chart/
目录中(而不是templates
内)。
configmap.yaml:
kind: ConfigMap
apiVersion: v1
metadata:
name: order-config
labels:
app: order-service
data:
application.yaml: |-
{{ .Files.Get "application.yaml" | indent 4 }}
这将产生相同的结果。希望对您有所帮助!
英文:
The answer by Andromeda works fine. An alternate, if you want to use the application.yaml
file directly.
Place the file in your helm-chart/
directory (not inside templates
).
configmap.yaml:
kind: ConfigMap
apiVersion: v1
metadata:
name: order-config
labels:
app: order-service
data:
application.yaml: |-
{{ .Files.Get "application.yaml" | indent 4 }}
This shall produce the same result. Hope this helps!
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论