2

按照 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-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 版本:1.3.1.Final

4

1 回答 1

6

您可以在其中使用环境变量,application.properties以便执行以下操作:

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

MY_SERVICE_URL在您的 Yaml 文件中定义。

此外,MicroProfile Config 有办法解决您的问题。COUNTRY_API_MP_REST_URL用作环境变量应该可以工作(大写所有内容,用 替换任何非字母数字)_

于 2020-04-03T15:44:19.810 回答