I have one kubernetes deployment file for e.g:
I want that image_tag is passed at the command line when running the kubectl create -f deployment.yaml command. and suppose i did the export IMAGE_TAG=1.4.3 and want to use that ENV variable value is inserted at the position of image tag.
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
spec:
selector:
matchLabels:
app: nginx
replicas: 1
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:{IMAGE_TAG}
ports:
- containerPort: 80most elegant way. you need to install envsubst binary
export key1=val1
export key2=val2
envsubst < deployment.yaml | kubectl apply -f -
I do this:
sed -i "s/{IMAGE_TAG}/${IMAGE_TAG}/" deployment.yml
kubectl apply -f deployment.ymlas it is not supported by kubectl
Kubectl doesn't support out of the box variables. Because it's tags based. For what you want to achieve you have different options. The most popular option is Helm, but,Kustomize, a new player is getting a lot of traction from the community. You can also use other tools like Terraform which I think a very decent option but unfortunately overlooked.