kubernetes - 环境变量不适用于整数

问题描述 投票:0回答:2

我在“docker”中运行了一个.netcore Web App。所以开始用kubernetes聚集它。在appsettings.json上有四个配置,它们将由环境变量转换(全部在“$ {}”之间):

   {
  "ConnectionSettings": [
    {
      "id": "${connectionSettings.connectionString.idMongoDb}",
      "databaseName": "${connectionSettings.connectionString.databaseName}",
      "connectionString": "${connectionSettings.connectionString.mongoDB}"
    }
  ],
    {
      "Key": "Token.Issuer",
      "Value": "${configuration.token.issuer}",
      "Description": "",
      "ModifiedDate": "2018-05-05 00:00:00.0000000",
      "ModifiedBy": "system",
      "AllowedProfiles": 1
    }
}

这是我的.yaml文件的一点:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp-dev-api-dep
  labels:
    app: myapp-dev-api-dep
    tier: app
    version: v1
spec:
  selector:
    matchLabels:
      app: myapp-dev-api
      tier: app
      version: v1
  replicas: 1
  template:
    metadata:
      labels:
        app: myapp-dev-api
        tier: app
        version: v1
    spec:
      containers:
        - name: myapp-dev-api
          image: 'myappapi_tstkube:latest'
          env:
            - name: connectionSettings.connectionString.mongoDB
              value: mongodb://192.168.20.99:27017
            - name: configuration.token.issuer
              value: '86400'
          ports:
            - name: http 
              containerPort: 80
              protocol: TCP
          livenessProbe:
            initialDelaySeconds: 30
            periodSeconds: 3600
            httpGet:
              path: /swagger/index.html
              port: 80
          resources:
            requests:
              cpu: 25m
              memory: 200Mi
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          imagePullPolicy: IfNotPresent
      restartPolicy: Always
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 25%
      maxSurge: 25% 

看看我的配置:

enter image description here

变量“connectionSettings.connectionString.mongoDB”有效。但变量“configuration.token.issuer”无法替代appsetting。

做了一些测试。我发现问题只与数字变量有关。

有人有想法或者你有问题吗?

VLW

docker kubernetes environment-variables yaml appsettings
2个回答
0
投票

您必须使用ASCII码代码。因此,您的部署规范将如下所示

env:
  - name: connectionSettings.connectionString.mongoDB
    value: "mongodb://192.168.20.99:27017"
  - name: configuration.token.issuer
    value: "\x38\x36\x34\x30\x30"

并检查env变量:

sukhoversha@sukhoversha:~/GCP$ kubectl  exec myapp-dev-api-dep-7948866b56-6cnmk  env | grep con
connectionSettings.connectionString.mongoDB=mongodb://192.168.20.99:27017
configuration.token.issuer=86400

0
投票

问题出在yamls识别码中。您可能在yaml文件中的错误空间有很多问题。

https://github.com/helm/helm/blob/master/docs/chart_template_guide/yaml_techniques.md

关于号码。两个答案都是对的。您可以使用单引号'86400'和ACII“\ x38 \ x36 \ x34 \ x30 \ x30”。

谢谢大家

© www.soinside.com 2019 - 2024. All rights reserved.