无效的 Quarkus RestClient 属性值在创建 Kubernetes 部署时的环境值。

huangapple go评论69阅读模式
英文:

Invalid env value with Quarkus RestClient property when create kubernetes deployment

问题

在遵循Quarkus Rest Client教程的过程中,我需要将类似以下内容添加到application.properties文件中:

country-api/mp-rest/url=https://restcountries.eu/rest

使用Docker可以工作,并且我可以通过参数传递属性值:

docker run -it --privileged --rm --env country-api/mp-rest/url="https://restcountries.eu/rest" mydockerhost/my-project:SNAPSHOT

用于Kubernetes的YAML文件如下所示:

apiVersion: "apps/v1"
kind: "Deployment"
metadata:
  labels:
    app.kubernetes.io/name: "my-project"
    app.kubernetes.io/version: "SNAPSHOT"
  name: "my-project-deployment"
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: "my-project"
      app.kubernetes.io/version: "SNAPSHOT"
  template:
    metadata:
      labels:
        app.kubernetes.io/name: "my-project"
        app.kubernetes.io/version: "SNAPSHOT"
    spec:
      containers:
      - env:
        - name: "country-api/mp-rest/url"
          value: "https://restcountries.eu/rest"

然而,在执行命令kubectl apply -f my-project.yaml时出现了以下错误:

`Deployment "my-project-deployment" 无效:

  • spec.template.spec.containers[0].env[1].name:无效值:"country-api/mp-rest/url":有效的环境变量名称必须由字母、数字、下划线(_)、短划线(-)或点(.)组成,并且不能以数字开头(例如'my.env-name'、'MY_ENV.NAME'、'MyEnvName1',验证时使用的正则表达式为'[-._a-zA-Z][-._a-zA-Z0-9]*')
    `

Quarkus版本:1.3.1.Final

英文:

Following the Quarkus Rest Client tutorial I need to add something similar to this to the application.properties file:

country-api/mp-rest/url=https://restcountries.eu/rest

With Docker it works and I can pass the property value by parameter:

docker run -it --privileged --rm --env country-api/mp-rest/url="https://restcountries.eu/rest" mydockerhost/my-project:SNAPSHOT

The YAML file for Kubernetes looks like this:

apiVersion: "apps/v1"
kind: "Deployment"
metadata:
  labels:
    app.kubernetes.io/name: "my-project"
    app.kubernetes.io/version: "SNAPSHOT"
  name: "my-project-deployment"
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: "my-project"
      app.kubernetes.io/version: "SNAPSHOT"
  template:
    metadata:
      labels:
        app.kubernetes.io/name: "my-project"
        app.kubernetes.io/version: "SNAPSHOT"
    spec:
      containers:
      - env:
        - name: "country-api/mp-rest/url"
          value: "https://restcountries.eu/rest"

However the following error is occurring when executing the command kubectl apply -f my-projetc.yaml

`The Deployment "my-project-deployment" is invalid:

  • spec.template.spec.containers[0].env[1].name: Invalid value: "country-api/mp-rest/url": a valid environment variable name must consist of alphabetic characters, digits, '_', '-', or '.', and must not start with a digit (e.g. 'my.env-name', or 'MY_ENV.NAME', or 'MyEnvName1', regex used for
    validation is '[-._a-zA-Z][-._a-zA-Z0-9]*')
    `

Quarkus version: 1.3.1.Final

答案1

得分: 7

你可以在application.properties中使用环境变量,就像这样:

country-api/mp-rest/url=${MY_SERVICE_URL}

并在你的Yaml文件中定义MY_SERVICE_URL

另外,MicroProfile Config有一种解决你问题的方法。使用COUNTRY_API_MP_REST_URL作为环境变量应该可以解决(将所有内容都转换为大写,将所有非字母数字字符替换为_)。

英文:

You can use environment variables in application.properties so you could do something like:

country-api/mp-rest/url=${MY_SERVICE_URL}

and define MY_SERVICE_URL in your Yaml file.

Also, MicroProfile Config has a way to work around your issue. Using COUNTRY_API_MP_REST_URL as an environment variable should work (uppercase everything, replace anything non alphanumeric with _).

huangapple
  • 本文由 发表于 2020年4月3日 23:16:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/61015005.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定