创建 kubernetes 部署时 Quarkus RestClient 属性 的环境值无效
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-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
您可以在 application.properties
中使用环境变量,这样您就可以执行以下操作:
country-api/mp-rest/url=${MY_SERVICE_URL}
并在 Yaml 文件中定义 MY_SERVICE_URL
。
另外,MicroProfile Config 有办法解决您的问题。使用 COUNTRY_API_MP_REST_URL
作为环境变量应该可以工作(大写一切,用 _
替换任何非字母数字)。
按照 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
您可以在 application.properties
中使用环境变量,这样您就可以执行以下操作:
country-api/mp-rest/url=${MY_SERVICE_URL}
并在 Yaml 文件中定义 MY_SERVICE_URL
。
另外,MicroProfile Config 有办法解决您的问题。使用 COUNTRY_API_MP_REST_URL
作为环境变量应该可以工作(大写一切,用 _
替换任何非字母数字)。