Auto deploy on azure kubernates when docker image is updated: possible? - azure

I have created an application by using azure's kubernates service.
In my yaml I specified "latest" as image version for every image I'm using.
Is there any option to make so that, when I update the image registry so that "latest" changes, kubernates auto-deploys that? And everything is managed so that it only updates one replica and then scales so that service is not interrupted during deploy?

Is there any option to make so that, when I update the image registry so that "latest" changes, kubernates auto-deploys that?
It's not kubernetes's work to handle this. There are two steep to work on this:
Add webhook on docker registry, for docker-hub, it is Docker Hub Webhooks. When new image has been pushed to registry, you can send a POST request to somewhere as notification.
Deploy a CI/CD to receive that notification and roll update your application. Or just create a simple HTTP Server to handle notification request and do something like kubectl ....
And everything is managed so that it only updates one replica and then scales so that service is not interrupted during deploy?
Kubernetes handle this by rolling update. For Deployment or StatefulSet, current kubernetes auto update pods by rolling update, all you need to do is kubectl apply -f new-spec.yaml.

Kubernetes is not aware of the changes at your registry, it is not monitoring for new container images. You would need to create a process that is triggered when a new version is released and updates your Kubernetes deployment. You could use CI/CD tools for this, or things like Azure Functions, Azure Automation etc.
For deploying without downtime you would want to look at rolling updates.

you should really use release management for this or something like gitops that would trigger updates when new version of container is available. using Azure Functions\Automation for this is just not right. Its not meant for that, it would be complicated\unreliable.

Related

Azure app service not pulling latest image from docker registry

I have a pipeline that publishes to my private Azure container registry but if I push a new image tagged with latest, my Azure app service does not pull the newly tagged latest image. I have Continuous deployment turned on via the DOCKER_ENABLE_CI app setting.
Additionally, I'm using a managed identity to authenticate with the ACR. I feel like the CD portion was working when I was using credentials to pull the image but after switching to managed identity it appears to have stopped. In order to get the new image I have to restart the app service which is not idea and makes this CD option useless...
When you enable Continuous deployment, App Service adds a webhook to your ACR to notify the web apps. The webhook causes your App Service app to restart and run the docker pull to get the updated image.
So, please go to your ACR, and under webhook, please check if there are running webhooks or not, if not you can create a webhook manually and see if the WebApp get the latest image in the following deployment.
source

Update the image of azure container instance?

Azure Container instances
This is the first time i use docker image
when i trying build and upload new version code and push in Azure Container registries
but if i want to apply new version code , i must restart Container instances by manual to apply new version code , it annoys me and is a waste of time
How to resolove auto restart or redeploy when i push new version code in Container registries in Azure ?
this is log deploy azure of myself
I can think of a couple of ways to do this.
AKR Webhooks
I probably will approach this by looking at the webhooks in AKR.
Then, create a Logic App to receive the webhook call when a new image is pushed. References.
In the Logic App, you can call one of the Azure Container Instance APIs to restart the container group.
You will need to consider the security of the Logic App, which can only be called by your AKR's webhook.
CI/CD Pipelines
Assume that you have used a CI/CD platform like Azure DevOps, where you can create build pipelines.
The pipeline can build and push the images to your AKR, then create a step to run Az command to update the instance group.
I probably prefer the pipeline approach as I can see the history of what images have been released on the DevOps page.

Azure Pipeline with Review Apps - Cleanup after merge

I've been setting up a pipeline for our project with Azure Pipeline using yaml. Currently adding review apps with Azure Kubernetes Service and was wondering how we should clean up after the PR is merged.
We are building docker images, pushing them to our registry, deploying them to a new dev space. Then it's all just left there.
After merge we're never going to bed those images again, not like we're going to deploy from a unapproved PR and there's dozens of them every day. We also would like to delete the review app and take down those extra deployments after we're done with them
I can't find anything in the documentation for this. Am I missing something?
I’ve been wondering the same thing, how does one clean-up all the “ephemeral” resources? Seeing the documentation says “ephemeral” I had hoped this functionality was built in.
Even though we trigger on master, I don’t believe there is enough information available in the pipeline to know which PR caused the commit to master, thus we cannot be guaranteed to tear down the correct review app.
I've been working on this today and think I've got it working.
I made a new pipeline that uses the kubectl task to delete the review app namespace, it also uses the azure cli task to run az acr purge to delete the images created for the PR, the tags of which are prefixed with the pr number so it can identify them.
I set this pipeline to not run with CI and not download the source.
Then I made an Azure Function that uses calls the Run Pipeline API to run it, passing the PR number as a variable to the pipeline.
Finally I used Service Hooks to invoke the Azure Function on PR Updated.
The only thing outstanding is the Environment Resource that is created automatically on the DevOps site does not get deleted. I cannot find an API for this so we might have to live with that.
By using browser dev tools and click the delete button in ADO I managed to find out how to delete environment resources using the Azure DevOps Rest API.
You can send:
DELETE <azure-dev-ops-base-url>/<organization>/_apis/distributedtask/environments/{environment-id}/providers/kubernetes/{resource-id}?api-version=6.0-preview.1
To find environment-id and resource-id use:
GET: <azure-dev-ops-base-url>/<organization>/_apis/distributedtask/environments?api-version=6.0-preview.1
GET: <azure-dev-ops-base-url>/<organization>/_apis/distributedtask/environments/{environment-id}?expands=resourceReferences&api-version=6.0-preview.1

Continuously deploy (CD) SignalR console app to Azure App Services

I'm trying Azure App Services. I've set up a build pipeline in Azure DevOps which builds and pushes my image to Docker Hub and then publishes docker-compose.yml as an artifact.
My release pipeline takes the docker-compose.yml and feeds it to the "Azure Web App for Container" task which succeeds. But the bot goes down and doesn't get back up after the deployment unless I access http://<myappname>.azurewebsites.net, then it starts and is of the latest pushed version. So everything seems to work, except the "restart" or docker-compose up.
I've been reading that I want to add a WebJob to my app service, but since I am using a Linux host I cannot seem to configure this. I've tried adding a curl task after deployment, but this probably executes too early.
Any ideas on how I would get to solve this last piece of the puzzle to have a simple CI/CD environment?
Currently there is zero out of the box support for hosting WebJobs in a Linux hosted app service. I've heard there's a hacky way of doing it (I'll have to find the post) but since it's not supported out of the gate, there's no guarantee it'll work.

Azure App Service + Docker Autodeploy?

I have setup an Azure App Service to host a docker container. This is all running fine -- pointing at a private Docker repository/image, using the latest tag.
I would like to be able to publish a new Dockage image from my CI server to the Docker repository under the latest tag and somehow trigger the App Service to pick up that there is a change of the latest image.
It seems I can trigger the change by modifying an Application Setting on the App Service and saving it -- but this does not seem like the correct way to handle it.
Is there a best practise for this kind of deployment?
In the properties section of the web app you'll find a DEPLOYMENT TRIGGER URL.
This URL should point to the /deploy endpoint. Remove that part and use the /docker/hook endpoint.
Your URL should look something like this: https://xxxx.scm.azurewebsites.net/docker/hook
If you POST to that URL with empty body it will trigger a deployment using the latest docker image.
Currently they are working on a solution for this scenario but as stated in their FAQ about Web App on Linux either modifying the application settings or restarting the web app is the only way of triggering the change.

Resources