Serverless using openfaas - Openfaas on MAC

Please follow the step to run openfaas on MAC with Docker Swarm:

  • Clone faas from github which has a shell script to deploy faas stack:
    • $ git clone https://github.com/openfaas/faas
  • Initialize Swarm on docker demon:
    • $ docker swarm init
  • Deploy the faas stack:
    • $ cd faas
      $ ./deploy_stack.sh
      • Get the credentials which is displayed here:

        • [Credentials]
          username: admin
          password: <password_displayed_here>
  • Login to openfaas GUI using the above auth:
  • Install faas-cli which will be used to work with openfaas:
    • $ brew install faas-cli
  • Lets create a sample python hello-world function:
    • ~$mkdir functions
    • cd ~/functions
  • Create the below files
    • test1 $ls -l
      total 16
      -rw-r--r--  1 zulfi  MS\Domain Users   44 Jun 15 08:34 handler.py
      -rw-------  1 zulfi  MS\Domain Users  143 Jun 15 08:35 test1.yml
      test1 $
    • handler.py
      • test1 $cat handler.py
        def handle(par):
            print("Hello! " + par)
      • test1 $cat handler.py
        def handle(par):
            print("Hello! " + par)
        test1 $cat test1.yml
        version: 1.0
        provider:
          name: openfaas
          gateway: http://127.0.0.1:8080
        functions:
          test1:
            lang: python
            handler: .
            image: test1

  • Build the image using the .py
    • test1 $faas-cli build -f ./test1.yml     #verify the image using $docker images | grep test1
      • test1 $docker images | grep test1
        test1                                    latest              520c8f8c918a        25 seconds ago      87.1MB

  • Deploy faas function:
    • test1 $faas-cli deploy -f ./test1.yml
      Deploying: test1.
      WARNING! Communication is not secure, please consider using HTTPS. Letsencrypt.org offers free SSL/TLS certificates.

      Deployed. 202 Accepted.
      URL: http://127.0.0.1:8080/function/test1
  • Test the function using curl:
    • test1 $curl http://127.0.0.1:8080/function/test1 -d "zulfi"
      Hello! zulfi
    • Using GUI:

Comments

Popular Posts