Skip to content

Instantly share code, notes, and snippets.

@danigian
Last active September 26, 2017 16:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danigian/e6097fad36f03c476a69e6c44fde074f to your computer and use it in GitHub Desktop.
Save danigian/e6097fad36f03c476a69e6c44fde074f to your computer and use it in GitHub Desktop.
Get OpenFaaS running on Azure Container Service with Kubernetes

Get OpenFaaS running on Azure Container Service with Kubernetes

Pre-requisites

Deploying ACS with Kubernetes

You can choose to deploy the ACS Kubernetes cluster using Azure CLI or acs-engine. In this readme you can find a quick guide for the both.

Deploy the cluster with the Azure CLI

  1. Install the official latest version of Azure CLI

  2. Login to your subscription

    az login

Optional: If you have multiple subscriptions linked to your account, remember to select the one on which you want to work. (az account set -s subscription-id)

  1. Create the resource group in which you want to deploy the cluster (in the example k8sRG is the name of the Resource Group and westeurope is the chosen location)

    az group create -l westeurope -n k8sRG

  2. Finally create your cluster. This will create a default cluster with one master and three agents (each VM is sized, by default, as a Standard_D2_v2 with 2vCPUs and 7GiB of RAM)

    az acs create --orchestrator-type Kubernetes -g k8sRG -n k8sCluster -l westeurope --generate-ssh-keys

Optional: you can specify the agent-count, the agent-vm-size and a dns-prefix for your cluster --agent-count 2 --agent-vm-size Standard_A1_v2 --dns-prefix k8sdanigian

  1. Get your cluster credentials ready for kubectl

    az acs kubernetes get-credentials -n k8sCluster -g k8sRG

Deploy the cluster with acs-engine

  1. Download acs-engine

  2. Download and eventually modify the cluster definition file (can find an example here)

  3. Using the just downloaded cluster definition file ("kubernetes.json" in the example), execute acs-engine as below, in order to deploy your cluster on Azure Container Service:

    ./acs-engine deploy --subscription-id your-subscription-id-here
    --dns-prefix friendly-dns-prefix --location westeurope
    --auto-suffix --api-model ./kubernetes.json

  4. After a successful deployment, acs-engine will output ssh keys and a list of kubeconfig files in the "_output" directory. Please choose the json file corresponding to your region and use that to replace your kubeconfig file (you can usually find it in ${HOME}/.kube/config)

Deploy OpenFaaS to the newly created ACS Cluster

You may now use kubectl and go on with the deployment of OpenFaaS to your cluster.

  1. Check if the kubectl configuration is ok and if your cluster is up-and-running

    kubectl cluster-info

  2. Clone the faas-netes repository

    git clone https://github.com/alexellis/faas-netes

  3. Deploy faas-netes to ACS

    kubectl apply -f ./faas.yml,monitoring.yml

  4. Optional: you may choose to expose the gateway to the internet. This could be useful to invoke functions from the internet.

    kubectl edit svc/gateway

When the editor pops up, change the spec/type to LoadBalancer then save and close the file (NodePort is the default spec/type for the gateway).

Congratulations! You now have OpenFaaS deployed to your Azure Container Service!

If you already know what to do now, go ahead and do it!

Otherwise, you can try to deploy an "Hello World" .NET Core 2.0 function to OpenFaaS!

In order to do that you will need a fully functioning Docker installation on your machine and an account on Docker Hub.

  1. Install the OpenFaaS CLI

    curl -sSL https://cli.openfaas.com | sudo sh

  2. Get the domain and port of your externally esposed gateway

    kubectl get svc/gateway

  3. Create a new C# Function

    faas-cli new --name your-function-name --lang csharp --gateway=http://domain:port

  4. Eventually modify the code of your "Hello World" function

  5. Build, push and deploy your newly created function.

    faas-cli build -f your-function-name.yml [--no-cache]

    faas-cli push -f your-function-name.yml

    faas-cli deploy -f your-function-name.yml

The --no-cache option is optional but very useful when updating the code of your function

  1. Test your function with CURL or Postman by just invoking it with a POST request to: http://domain:port/function/your-function-name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment