I'm trying to figure out what the easiest way of running a "one time job" on Azure Container Apps is.
I know that it can be done with Azure Container Instances or Azure Kubernetes Service, but is there something similar for ACA?
Ideally, I'm looking for some kind of cli command like az containerapps run --image <some-image> that can run in an environment and is cleaned up when it has finished running.
Is that possible?
Related
I have a container instance and would like to have azure send an email when some command fails inside my azure container instance.
I was thinking of having an azure function scheduled at a certain period of time to run every 30 minutes between 00:00:00 utc and 2h utc and it would check the state of the azure container instance and if a certain string was present in the logs of that ACI and then send an email.
But I've found that azure functions don't allow to use the azure cli commands inside the azure functions and as such I cannot access the logs of my ACI with az container logs.
I also thought of using an azure batch job, but I don't know if I can create a pool with my ACI which uses an image I have created running at the abovementioned period of time and check the logs of my ACI and have azure send an email with the logs if a certain string is present in the logs.
I am new to Azure and any help on this would be appreciated.
But I’ve found that azure functions don’t allow to use the azure cli commands inside the azure functions and as such I cannot access the logs of my ACI with az container logs.
As of now, Azure Functions doesn’t support the CLI Commands directly as the supported Languages are C#, F#, Java, Java Script, PowerShell, Python and Typescript shown in this MS Doc.
But you can use the Python Stack Azure Function where you can use the az cli commands with the help of pip packages of azure-cli.
To invoke the Azure resources like containers, logs using az commands, you can refer to SO thread which has a sample example of using the az cli cmdlets in Python Azure Functions given by #PeterPan.
You can achieve the same directly in Azure PowerShell Language Functions to invoke the container resource logs.
I'm currently using resource: container in azure pipeline to pull my custom image tools from ACR, and use this image to create a container than can run several CLI commands on my pipeline.
Pulling this custom image tools takes so much time, roughly around 5mins and I want to avoid that as it is considered as a wasted time and a blockage since I do debugging most of the time.
Question: Is it possible to create an Azure Container Instance that constantly run my custom image tools then call this container inside my pipeline to run some cli commands?
I'm having a hard time finding documentation, so I'm not really sure if it is possible.
You can try to set up a self-hosted agent in your custom Docker image, and when running the container on ACI, it will install the agent and connect it to your Azure DevOps.
Then, you can use this self-hosted agent to run your pipeline job which needs to run the CLI commands. Since the self-hosted agent is hosted in the container, the job runs on the self-hosted agent will run in the container.
About how to configure set up self-hosted agent in Docker image, you can reference the document "Run a self-hosted agent in Docker".
I have a multi-container app that I need to run twice a day at specific times for about 30 mins each time. To save costs, I would like to:
Turn on a Linux VM on Microsoft Azure
Run a script that runs docker-compose up -d, waits 30 mins, then calls docker-compose stop
Turn off the VM
I'd love for this to happen automatically on a cron schedule.
So far, I've failed to find any Azure solution that can do all of this. Azure automation allows you to turn on/off VMs but it doesn't allow you to run a sh script on it after you've turned it on. Azure Logic apps allows you to spin up containers on a schedule but not with docker-compose.
Any idea on how I might accomplish this in a way that doesn't involve me having a VM that is always on?
No worries , you can use this AZ powershell command to run sh script on your Azure VMs directly via Azure automation runbook with prarm : -CommandId 'RunShellScript'
For AzureRM commands , refer to here
I have tested on my side and it works perfectly for me .
I did create a simple 'Hello World' Web Job and placed that Web Job inside a Docker Windows Container/Nanoserver
I did push that Docker Windows Container into an Azure Container Registry
I did follow this article and successfully created Virtual AKS pods/nodes
When I run 'get pods' I do see the pods created and running
I do see IP's generated reflected in the 'get pods' command
My question is how do I run the container inside these pods/nodes?
I did try to reference the IP's but those IP's don't load anything
How can I run those containers that I successfully placed into Virtual Kubelet pods/nodes
If the containers in the get fired up by themselves, do they fire up/get invoked only once or every n number of minutes?
Is there a way to check on how the last run went, like log files?
Thank you very much for your help
First of all, I see you create your web job inside a Windows-based Docker. If so, you cannot run the container in the AKS while it does not support Windows nodes, at least current. For window container, I suggest you could use the Azure Container Instance or Web App for Container.
For Linux containers, the pod in AKS is a group of one or more containers (such as Docker containers), with shared storage/network, and a specification for how to run the containers. If you already have the Docker image, you can create the container inside the pod follow the steps in Running the application in AKS.
In addition, you can set the restart policy for your container. See Restart Policy for the container in Kubernetes. For the logs, I suggest you could use the persist volumes. If not, the files will be lost if the container crash.\
Update
If you really want to run windows container in AKS cluster, there is also a way for you. You can use the virtual Kubelet and Azure Container Instance in AKS. Follow the steps Run Windows container in AKS.
How do I start a container in ACI Container Group which is already deployed and in terminated state. Can it be done either through some automation or from logic app? CLI commands show az container restart but not start. The logic app connectors seem to pull the image every time and start it.Is there no means to just start an existing terminated container?
Once a container is terminated there is not a start action you can do. You can deploy a new container which will pull the image you have setup and run whatever app is setup.
If the container is in a failed state you could issue a restart command but the results are basically the same. It re-initializes the container, pulls the image and deploys the app.
This is how containers work. They are not a persistent item such as a Virtual Machine. They are designed to be removed, added, and upgraded as needed.
This is a pain point on Azure. While container instances are not meant to be restarted after being terminated, the container groups they sit inside are meant to be flexible enough to be restarted. And they have that capability - Microsoft Azure's docs just don't really talk about it. It's left for you to figure out.
The main problem is that when you deploy an updated container instance to an existing container group in Azure, and the matching container instance in Azure is terminated, the deployment will not automatically trigger the new version of that container instance to run again.
In my case, I'm scheduling a container deployment to occur from inside an Logic App using the "Create or update a container group" connector (because Microsoft removed the cloud scheduler earlier this year, forcing people to use Logic Apps for simple tasks like this). If I delete the existing container group and run the Logic App, then it will automatically start the Docker container instance as expected. When I re-run it subsequent times, it fails to start the container, because the previous instance inside the container group is in a terminated state. The solution is to add an additional "Start containers in a container group" action, which will start the container instances anew and allow them to run to completion (at which point my containers terminate again, because they're one-off ETL jobs).