我想在修补任何部署配置时动态传递参数
oc patch dc / action-msa -p“ $(cat msa-patch.yml)” --param service_account = msa-service-account
spec:
template:
spec:
serviceAccountName: ${service_account}
restartPolicy: "Always"
initContainers:
- name: vault-init
image: ${init_container_image}
imagePullPolicy: Always
containers:
- name: ${SERVICE_NAME}-java-service
image: ${main_container_image}
在使用openshift oc修补时,是否有任何选项或方法可以动态传递service_account,init_container_image和service_name?
答案 0 :(得分:0)
您需要此解决方案的模板层,例如Kustomize,HELM等。 或者,您可以在部署yaml文件之前使用环境文件作为源,如下所示
您的 deployment.yaml 看起来像这样:
spec:
template:
spec:
serviceAccountName: {{service_account}}
restartPolicy: "Always"
initContainers:
- name: vault-init
image: {{init_container_image}}
imagePullPolicy: Always
containers:
- name: {{SERVICE_NAME}}
image: {{main_container_image}}
您的 env.file 看起来像这样:
service_account="some_account"
init_container_image="some_image"
SERVICE_NAME="service_name"
然后运行
oc patch dc/action-msa -p \
"$(source env.file && cat deployment.yml | \
sed "s/{{service_account}}/service_account/g"| \
sed "s/{{init_container_image}}/init_container_image/g"| \
sed "s/{{SERVICE_NAME}}/SERVICE_NAME/g")" --param service_account=msa-service-account
希望有帮助