Container and serverless technologies bring important improvements to developer productivity. These technologies resolve developers’ concerns about differences between production and development environments. They also improve applications’ ability to execute more reliable and in scale. The two were being developed separately for a while and both have advantages and disadvantages. Serverless services generally have some platform limitations like supported programming langugage runtimes and operating environment. One of the difficulties with container environments was management of the container host environment. Schedulers like Kubernetes came to our life and helped us for container management, and evolved to managed services. But still there were nodes on which our pods are running and we pay for, monitor and scale them.
The innovative introduction of serverless containers makes it possible to access both of them. Deploying applications in containers without worrying about the host environment, server pool and supported runtimes was the next step of serverless and containers concept. With Virtual Kubelet, it is possible to integrate them to Kubernetes environments. Using Virtual Kubelet, we get a virtual node in Kubernetes where we can deploy limitless pods in it in theory (it is only limited by the serverless container service’s limit). Brandan Burns has published a nice article on this subject and telling that The future of Kubernetes is serverless
Azure Container Instances (ACI) is the Microsoft’s serverless container service where we can directly create our containers in it. We use Virtual Kubelet ACI Connector to itegrate ACI with Kubernetes.
Managing ACI Containers
One method for managing our container workflow is using Azure Functions by calling the ACI api. Brian Peek and Dimitris Gkanatsios have created a demo that shows use Azure Container Instances to automatically scale a multiplayer backend and how Azure Container Instances can be managed from Azure Functions. They demnstrate monitoring how many players are connected in an online game, and if there are too many players for one server to handle, they spin up a new server instance with ACI. They also shut them down when they’re no longer needed. The video and code can be find in Brian’s post Build 2018 - GameDev Goodness.
Another one is using Azure Logic Apps, which contains ACI Connector that supports creating and deleting container groups, getting the status or logs of a container group, and listing container groups. The Azure Sample Run sentiment analysis based on triggers with Azure Container Instances (ACI) and the ACI Logic Apps connector descibes how to integrate ACI with Logic Apps
A Use Case Scenario for ACI: Static Site Generation
There are many use case scenarios like batch or bursty workloads that we can use ACI for. One of them is static site generation pipeline with serverless containers. We can use Hugo, Azure logic apps, ACI, Azure Container Registry (ACR), VSTS/Github and Azure Blob Storage as components of this pipeline. Hugo is an open source static site generator written in Go. It compiles static web sites from markdown files and we can deploy them to one of the static file serving services. Azure Blob Storage is a managed service which supports serving static websites and we can also integrate it with CDN to lower the costs of metwork bandwidth.
The workflow is, first we create a docker image with Hugo installed in it. Then, we push the image to a docker registry. After we create a new post in a markdown file, we push it to our git repository either in Github or VSTS. A Logic App triggers and launches a container from our Hugo docker image. Using the container we compile static files from our markdown post and deploy it to Azure Blob storage. When the job is done, container is closed and website is ready to be published from Blob Storage and CDN.
Thare are various ways of preparing static site generation, but with this scenario we don’t need to provision and manage servers to compile our markdown post with Hugo and publish. All flow is done with serverless services together with ACI.