我有一个 configMap,我正在尝试对其进行模板化。我的values.yaml 文件中有这个json 值,在我的configmap 模板中我试图通过此命令获取它。
有没有办法解析 json 值,它会返回一个干净的 json 值,我可以将其应用到我的 kubernetes 集群中。非常感谢
configmap.yaml
data: {{ .Values.config | toJson | quote }}
values.yaml
instance-0.json: |-
{
"name": nameofserver,
"connectionType": "STANDALONE",
"host": "IP",
"port": 6379,
"username": "",
"password": "",
"tls": {
"useTls": false,
"verifyServerCert": true,
"clientAuth": false
}
Result:
data: "{\"instance-0.json\":\"{\\n \\\"name\\\": \\\"nameofserver\\\",\\n \\\"connectionType\\\": \\\"STANDALONE\\\",\\n \\\"host\\\": \\\"IP\\\",\\n \\\"port\\\": 6379,\\n \\\"username\\\": \\\"\\\",\\n \\\"password\\\": \\\"\\\",\\n \\\"tls\\\": {\\n \\\"useTls\\\": false,\\n \\\"verifyServerCert\\\": true,\\n \\\"clientAuth\\\": false\\n }\"}"
我尝试了上述方法并期望它返回一个干净的 Json 文件
values.yaml
config:
instance-0.json: |-
{
"name": nameofserver,
"connectionType": "STANDALONE",
"host": "IP",
"port": 6379,
"username": "",
"password": "",
"tls": {
"useTls": false,
"verifyServerCert": true,
"clientAuth": false
}
cm.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: test
data:
{{- toYaml .Values.config | nindent 2 }}
输出
apiVersion: v1
kind: ConfigMap
metadata:
name: test
data:
instance-0.json: |-
{
"name": nameofserver,
"connectionType": "STANDALONE",
"host": "IP",
"port": 6379,
"username": "",
"password": "",
"tls": {
"useTls": false,
"verifyServerCert": true,
"clientAuth": false
}