6

Some general advice and pointers.

I want to run a task in a container from an azure function. So either triggered by a queue or HTTP the function would spin up a container, passing some parameters and that container would do it's work and then be deleted, so just paying for computation time. This could happen in parallel but each time is totally independent from others.

So i believe i can use Powershell with Azure functions but i would prefer to create a c# function through a VS template. Is there an SDK that would allow me to run containers in c#? Can someone point me to docks?

I know that there are orchestration frameworks (maybe too complicated) and there are Batch jobs that would spin up one - but it strikes me that i need a very simple approach?

One of the challenges with Azure is too much choice!

thanks in advance Paul

paulinventome
  • 1,047
  • 2
  • 10
  • 11
  • Do you REALLY want to use an Azure Function for this? I think using an Azure Logic App makes more sense. Some inspiration can be found over here: https://blogs.technet.microsoft.com/uktechnet/2018/04/04/run-your-python-script-on-demand-with-azure-container-instances-and-azure-logic-apps/ – Jan_V May 29 '18 at 12:05
  • 1
    Maybe you could use ACI. Have a look at [this blog post](http://markheath.net/post/aci-integration-ideas) – Mikhail Shilkov May 29 '18 at 12:07
  • Jan - yes, i guess i could use ALA (I hadn't looked into these). It was just azure functions seemed pretty lightweight and simple to set up - what in your opinion would the differences between between Logic App and functions? – paulinventome May 29 '18 at 13:52
  • Mikhail, thanks for that post it seems to cover a lot of what i'm looking for, really appreciate it – paulinventome May 29 '18 at 13:56
  • You won't be able to do that within Azure Functions. I'd encourage you to look at something like the ACI recommendation above. – Fabio Cavalcante May 29 '18 at 23:56

2 Answers2

2

My suggestion would be to use an HTTP trigger to call an Azure function to start an Azure Container Instance using the ACI SDK.

Here is a good example walkthrough.

Good luck.

Lou O.
  • 599
  • 4
  • 17
0

One way is to make use of a K8s CronJob.

  1. Create Kubernetes Service on Azure
  2. Open Cloud Shell
  3. Choose Bash
  4. az aks get-credentials --resource-group myResourceGroup --name myAKSCluster
  5. mkdir jobs
  6. cd jobs
  7. nano cronjob.yaml and paste the below sample with your details
  8. ctrl+X
  9. kubectl apply -f .
  10. kubectl get cronjobs
  11. After applying the yaml definition it should respond with created and the command at point 10 will show the cronjob schedule.

Here is a link and example: https://kubernetes.io/docs/tasks/job/automated-tasks-with-cron-jobs/

*Below yaml does not want to format properly *

apiVersion: batch/v1beta1 kind: CronJob metadata: name: some-cronjob spec: schedule: "0 * * * *" jobTemplate: spec: template: spec: restartPolicy: Never containers: - name: some-job image: someuser/someimage env: - name: SOMESETTING value: somevalue

Anton Swanevelder
  • 1,025
  • 1
  • 14
  • 31