在Kubernetes ConfigMap中指定一个`int`值? [英] Specify an `int` value in Kubernetes ConfigMap?

查看:150
本文介绍了在Kubernetes ConfigMap中指定一个`int`值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在ConfigMap中指定int值?当我尝试指定端口号时,出现以下错误.

Is there a way to specify int values in ConfigMap? When I try to specify a port number I get the following error.

error: error validating "my-deployment.yml": error validating data: expected type int, for field spec.template.spec.containers[0].ports[0].containerPort, got string; if you choose to ignore these errors, turn validation off with --validate=false

这是我正在使用的示例配置文件:

Here is the sample config file I am using:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: my-service
spec:
  replicas: 2
  template:
    metadata:
      labels:
        app: poweramp-email-service
    spec:
      containers:
      - name: poweramp-email-service
        env:
          - name: SERVICE_PORT_NUM
            valueFrom:
              configMapKeyRef:
                name: stg-config
                key: poweramp-email-service.port
        image: nginx
        ports:
        - containerPort: my-service.port

这是我用来使用以下命令生成ConfigMap的简单stg.properties文件:kubectl create configmap stg-config --from-file stg.properties

And here is the simple stg.properties file I am using to generate the ConfigMap using the command: kubectl create configmap stg-config --from-file stg.properties

my-service.port=9513

推荐答案

恐怕您不能在spec.template.spec.containers[0].ports[0].containerPort中使用configmap值,它用于配置值.

You can't use configmap values in spec.template.spec.containers[0].ports[0].containerPort I'm afraid, it's for configuration values.

您可以将其用于的选项(在本指南中指定)是

The options you can use it for (specified in this guide) are

  • 作为环境变量
  • 作为命令行配置标志(使用环境变量)
  • 使用音量插件.

如果您想为您的部署/吊舱配置端口,则可以考虑使用 Helm . Helm允许您在清单/定义中使用Go模板,然后可以在调用时覆盖它们.

If you want to make the port configurable for your deployment/pod, you might consider using Helm. Helm allows you to use Go templates in your manifests/definitions, and then you can override them upon invocation.

以以下 MySQL图表模板为例,您可以在此处将端口设置为配置选项,如下所示:

Take this MySQL Chart template as an example, you could set the port here as a config option like so:

ports:
  - name: mysql
  containerPort: {{ default 3306 .Values.mysqlPort }}

然后从那里在您的值中设置此值.yaml

这篇关于在Kubernetes ConfigMap中指定一个`int`值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆