I tried to set variables in Azure Pipelines' Release which can be used Command Task in Release to replace variables' values to Docker Kubernetes' .yaml file.
It works fine for me but I need to prepare several Command Tasks to replace variables one by one.
For example, I set variable TESTING1_(value:Test1), TESTING2_(value:Test2) and TESTING3_(value:Test3) in Pipelines' Release. Then I only used Command Task to replace TESTING1_ to $(TESTING1_) in Docker Kubernetes' .yaml file. Below is original environment setting in .yaml file:
spec:
containers:
- name: devops
env:
- name: TESTING1
value: TESTING1_
- name: TESTING2
value: $(TESTING2_)
After ran Pipelines' Release, print out results in NodeJS were:
console.log(process.env.TESTING1); --> Test1
console.log(process.env.TESTING2); --> $(TESTING2_)
console.log(process.env.TESTING3); --> undefined
i think you should be use config maps for that (maybe update values in config maps). you shouldn't be updating containers directly. this gives you flexibility and management. example:
apiVersion: v1
kind: Pod
metadata:
name: dapi-test-pod
spec:
containers:
- name: test-container
image: k8s.gcr.io/busybox
command: [ "/bin/sh", "-c", "env" ]
env:
- name: SPECIAL_LEVEL_KEY
valueFrom:
configMapKeyRef:
name: special-config
key: special.how
and then if some value changes you update the config map and all the pods that reference this config map get new value.