I am using classic editor to create a release pipeline to deploy to Azure Kubernetes Service, however, I keep getting the error of InvalidImageName after deploying in Azure Kubernetes Service (AKS). The issue is due to aks not being able to find the specified image in Azure Container Registries (ACR) where the docker image tag ${TAG} variable cannot seem to be replaced by the build number from the pipeline $(Build.BuildId).
My Azure Container Registries (ACR) repositories
The error screenshot in aks:
I have tried to create variable in the release pipeline to assign the value to the TAG variable. Thereafter, I went on to create a 'Command line' task step to set the value into the deployment.yml file.
It is setting the value as shown below. However, when I run the kubectl apply
command to run the deployment.yml file, the TAG is not showing the build number. I would greatly appreciate any help on this.
Prior to seeking help, I have try out some of the stackoverflow answers from this questions, but was unable to do so How to kubernetes "kubectl apply" does not update existing deployments How to provide docker image tag dynamically to docker-compose.yml in Azure Release Pipeline Task?
Instead of running
envsubst '${TAG}' <deployment.yml
directly, try this one:And it's recommended to navigate(
cd
) to the directory where yourdepolyment.yml
file exists firstly, then run commandecho "$(envsubst '${TAG}' <deployment.yml)" > deployment.yml
.More details about your issue:
The
<
means infile, you still need to output the changes to one file using>
.Check the Note here: If if we want to use the same file as both source file and destination file, we'll have to use something like moreutil's
sponge
. Howeversponge
is not available in Hosted agent, so I suggest usingecho "$(originalCommand)" > outputfile
as an workaround.