我希望能够从Kubernetes的yaml文件中将一些值传递给容器。这些值将由我的Java应用程序使用System.getenv(“x_slave_host”)
读取。
我有以下Dockerfile:
FROM jetty:9.4
...
ARG slave_host
ENV x_slave_host $slave_host
...
$JETTY_HOME/start.jar -Djetty.port=9090
这个 Kubernetes 的 YAML 文件包含了我添加的 env
部分:
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: master
spec:
template:
metadata:
labels:
app: master
spec:
volumes:
- name: shared-data
emptyDir: {}
containers:
- name: master
image: xregistry.azurecr.io/Y:latest
ports:
- containerPort: 9090
volumeMounts:
- name: shared-data
mountPath: ~/.X/experiment
- env:
- name: slave_host
value: slavevalue
- name: jupyter
image: xregistry.azurecr.io/X:latest
ports:
- containerPort: 8000
- containerPort: 8888
volumeMounts:
- name: shared-data
mountPath: /var/folder/experiment
imagePullSecrets:
- name: acr-auth
当我在本地使用docker compose时,使用args参数可以正常工作。这是一个片段:
master:
image: master
build:
context: ./master
args:
- slave_host=slavevalue
ports:
- "9090:9090"
现在我正在尝试在Kubernetes中做同样的事情。然而,在Azure上部署时出现以下错误:
error: error validating "D:\\a\\r1\\a\\_X\\deployment\\kub-deploy.yaml": error validating data: field spec.template.spec.containers[1].name for v1.Container is required; if you choose to ignore these errors, turn validation off with --validate=false
换句话说,如何将我的Docker Compose文件重写为Kubernetes并传递此参数。谢谢!