kubernetes - 如何为应用程序 dotnetcore 编写 configmap
问题描述
我有一个用于应用程序 dotnetcore 的 docker-composes,我是 k8s 的新手,我的应用程序有一个很长的 envvariable。“ConnectionStrings__DefaultConnection”如下
productstudio:
volumes:
- ${USERPROFILE}/.aws:/root/.aws
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ConnectionStrings__DefaultConnection=Username=someuser;Password=somepassword;Server=postgres;Port=5432;Database=somedb;Search Path=some
- EventBus__Enable=true
- EventBus__HostUri=rabbitmq://eventbus/
我写了configmap
apiVersion: v1
kind: ConfigMap
metadata:
name: be-productstudio-configmap
labels:
app: product-builder-be
tier: backend
data:
ASPNETCORE_ENVIRONMENT: Development
EventBus__Enable: true
EventBus__HostUri: rabbitmq://eventbus/
ConnectionStrings__DefaultConnection: |-
Username=someuser;
Password=somepassword;
Server=postgres;
Port=5432;
Database=somedb;
Search Path=some
但我有一个错误
Error from server (BadRequest): error when creating "manifect-be.yml": ConfigMap in version "v1" cannot be handled as a ConfigMap: v1.ConfigMap.Data: ReadString: expects " or n, but found t, error found in #10 byte of ...|_Enable":true,"Event|..., bigger context ...|nSearch Path=productstudio\"","EventBus__Enable":true,"EventBus__HostUri":"rabbitmq://eventbus/"},"k|...
谁能帮帮我,谢谢
解决方案
我在这里看到两个问题:
- 您看到的错误意味着
true
for的值EventBus__Enable
没有被引用,它被视为表示布尔值 true 的关键字。环境变量是字符串,必须在您的 yaml 定义中引用。你需要让它看起来更像这样:
EventBus__Enable: "true"
- 你不应该在你的关键定义中使用空格
ConfigMap
:
Search Path=productstudio
作为:
data
或字段下的每个键binaryData
必须由字母数字字符-
、_
或组成.
。
您可以使用官方文档作为正确配置的 ConfigMaps 的参考,例如:
apiVersion: v1
kind: ConfigMap
metadata:
name: game-demo
data:
# property-like keys; each key maps to a simple value
player_initial_lives: "3"
ui_properties_file_name: "user-interface.properties"
# file-like keys
game.properties: |
enemy.types=aliens,monsters
player.maximum-lives=5
user-interface.properties: |
color.good=purple
color.bad=yellow
allow.textmode=true
推荐阅读
- python - matplotlib:从数据集中删除数据时散点图不更新
- hibernate - JPA persistence.xml 我希望它连接到 MariaDB,但它总是连接到 hsqldb
- c - 从 GSM-TCAP asn1 文件生成 C 代码时出错
- c# - 如何将“AddDbContext”与“AddSingleton”一起使用?
- asp.net - 将 FCM 消息从 API 服务器发送到多个设备?
- python - Pytest - 将夹具传递给 mark.parametrize
- react-native - 通过 onPress 传递数据不允许在函数中正确传递参数
- jquery - jquery 文件上传不适用于 bootstrap v4.1.3
- javascript - 将响应从 fetch() 转换为 JSON 对象
- c - 限制输入字符串字符