Ben*_*Ben 1 kubernetes kubernetes-helm configmap
我正在尝试在带有舵图的部署中使用配置映射。现在似乎可以根据此处的文档使用 Helm 访问文件: https: //github.com/helm/helm/blob/master/docs/chart_template_guide/accessing_files.md
这是我的部署:
kind: Deployment
apiVersion: extensions/v1beta1
metadata:
name: "{{ template "service.fullname" . }}"
labels:
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
spec:
replicas: {{ .Values.replicaCount }}
template:
metadata:
labels:
app: "{{ template "service.fullname" . }}"
spec:
containers:
- name: "{{ .Chart.Name }}"
image: "{{ .Values.registryHost }}/{{ .Values.userNamespace }}/{{ .Values.projectName }}/{{ .Values.serviceName }}:{{.Chart.Version}}"
volumeMounts:
- name: {{ .Values.configmapName}}configmap-volume
mountPath: /app/config
ports:
- containerPort: 80
name: http
livenessProbe:
httpGet:
path: /health
port: http
initialDelaySeconds: 10
timeoutSeconds: 5
readinessProbe:
httpGet:
path: /health
port: http
initialDelaySeconds: 10
timeoutSeconds: 5
volumes:
- name: {{ .Values.configmapName}}configmap-volume
configMap:
name: "{{ .Values.configmapName}}-configmap"
Run Code Online (Sandbox Code Playgroud)
我的 configmap 正在访问配置文件。这是配置图:
apiVersion: v1
kind: ConfigMap
metadata:
name: "{{ .Values.configmapName}}-configmap"
labels:
app: "{{ .Values.configmapName}}"
data:
{{ .Files.Get "files/{{ .Values.configmapName}}-config.json" | indent 2}}
Run Code Online (Sandbox Code Playgroud)
图表目录如下所示:
files/
--runtime-config.json
templates/
--configmap.yaml
--deployment.yaml
--ingress.yaml
--service.yaml
chart.value
vaues.yaml
Run Code Online (Sandbox Code Playgroud)
这就是我的runtime-confi.json 文件的样子:
{
"GameModeConfiguration": {
"command": "xx",
"modeId": 10,
"sessionId": 11
}
}
Run Code Online (Sandbox Code Playgroud)
问题是,当我安装图表时(即使使用空运行模式),我的配置映射的数据为空。它不会将配置文件中的数据添加到我的 configmap 声明中。这就是我进行空运行时的样子:
---
apiVersion: v1
kind: ConfigMap
metadata:
name: "runtime-configmap"
labels:
app: "runtime"
data:
---
kind: Deployment
apiVersion: extensions/v1beta1
metadata:
name: "whimsical-otter-runtime-service"
labels:
chart: "runtime-service-unknown/version"
spec:
replicas: 1
template:
metadata:
labels:
app: "whimsical-otter-runtime-service"
spec:
containers:
- name: "runtime-service"
image: "gcr.io/xxx-dev/xxx/runtime_service:unknown/version"
volumeMounts:
- name: runtimeconfigmap-volume
mountPath: /app/config
ports:
- containerPort: 80
name: http
resources:
limits:
cpu: 100m
memory: 100Mi
requests:
cpu: 100m
memory: 100Mi
livenessProbe:
httpGet:
path: /health
port: http
initialDelaySeconds: 10
timeoutSeconds: 5
readinessProbe:
httpGet:
path: /health
port: http
initialDelaySeconds: 10
timeoutSeconds: 5
volumes:
- name: runtimeconfigmap-volume
configMap:
name: "runtime-configmap"
---
Run Code Online (Sandbox Code Playgroud)
我做错了什么导致我没有获取数据?
字符串内变量的替换不起作用:
{{ .Files.Get "files/{{ .Values.configmapName}}-config.json" | indent 2}}
Run Code Online (Sandbox Code Playgroud)
printf但是您可以使用如下函数生成字符串:
{{ .Files.Get (printf "files/%s-config.json" .Values.configmapName) | indent 2 }}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4903 次 |
| 最近记录: |