kubernetes 将Zip / Binary文件添加到configmap

fhity93d  于 2023-05-06  发布在  Kubernetes
关注(0)|答案(1)|浏览(177)

我试图添加一个zip文件到我们的configmap由于文件量超过1mb的限制。我用Helm部署了我们的图表,并在研究BinaryData,但无法让它正常工作。我想看看是否有人有任何建议,我如何可以集成这与 Helm ,所以当工作完成后,它删除了配置Map与它
下面是我的configmap:

apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ template "db-migration.fullname" . }}
  labels:
    app: {{ template "db-migration.name" . }}
    chart: {{ template "db-migration.chart" . }}
    draft: {{ .Values.draft | default "draft-app" }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
binaryData:
  {{ .Files.Get "migrations.zip" | b64enc }}
immutable: true

---

apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ template "db-migration.fullname" . }}-test
  labels:
    app: {{ template "db-migration.name" . }}
    chart: {{ template "db-migration.chart" . }}
    draft: {{ .Values.draft | default "draft-app" }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
binaryData:
  {{ .Files.Get "test.zip" | b64enc }}
immutable: true

这两个zip文件位于图表中,我有一个命令来解压缩它们,然后运行迁移

dpiehjr4

dpiehjr41#

binaryData exepcts a map,但你传递给它的是一个 string
调试模板时我们可以看到

Error: INSTALLATION FAILED: unable to build kubernetes objects from release manifest: error validating "": error validating data: ValidationError(ConfigMap.binaryData): invalid type for io.k8s.api.core.v1.ConfigMap.binaryData: got "string", expected "map"

解决这个问题的方法是在{{ .Files.Get "test.zip" | b64enc }}之前添加一个键。

apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ template "db-migration.fullname" . }}
  labels:
    app: {{ template "db-migration.name" . }}
    chart: {{ template "db-migration.chart" . }}
    draft: {{ .Values.draft | default "draft-app" }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
binaryData:
  migrations: {{ .Files.Get "migrations.zip" | b64enc }}
immutable: true

---

apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ template "db-migration.fullname" . }}-test
  labels:
    app: {{ template "db-migration.name" . }}
    chart: {{ template "db-migration.chart" . }}
    draft: {{ .Values.draft | default "draft-app" }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
binaryData:
  test: {{ .Files.Get "test.zip" | b64enc }}
immutable: true

相关问题