×
Community Blog How to Set Up Apache OpenWhisk on Ubuntu 18.04 – Part I

How to Set Up Apache OpenWhisk on Ubuntu 18.04 – Part I

This tutorial aims at detailing the installation process of Apache OpenWhisk onto an Alibaba Cloud Elastic Compute Service (ECS) Ubuntu 18.

By Sai Sarath Chandra, Alibaba Cloud Tech Share Author. Tech Share is Alibaba Cloud's incentive program to encourage the sharing of technical knowledge and best practices within the cloud community.

Many organizations today are looking at adopting serverless computing to improve efficiency and reduce costs. The significant feature of serverless computing is that it supports event-based programming, which is the heart of the entire Internet of Things (IoT) industry. Serverless computing is capable of handling burstable workloads while supporting virtually infinite scalability.

Serverless is not for everyone because of the potential latency increase in the request-response times. However, even though serverless may not be for everyone, it has played a prominent role in the newer architectures. The reason behind that is because event-based programming helps us save a considerable amount of cost when you compare with the workloads on virtual servers. Plus, there are a lot of applications out there that are not latency sensitive.

There are several open source technologies built by the support of different organizations concentrated on different use-cases. Every open source serverless framework have their uniqueness, which we cannot compare. This tutorial aims at detailing the installation process of Apache OpenWhisk onto your Alibaba Cloud Elastic Compute Service (ECS) Ubuntu 18.04(64-bit) machine.

What Is Apache OpenWhisk?

Apache OpenWhisk (Incubating) is an open source, distributed serverless platform that executes functions (fx) in response to events at any scale. OpenWhisk manages the infrastructure, servers and scaling using Docker containers so you can focus on building amazing and efficient applications.

The OpenWhisk platform supports a programming model in which developers write functional logic (called Actions), in any supported programming language, that can be dynamically scheduled and run in response to associated events (via Triggers) from external sources (Feeds) or HTTP requests. The project includes a REST API-based Command Line Interface (CLI) along with another tooling to support packaging, catalogue services and many popular container deployment options.

If you didn't understand any of the terms, don't worry. Let's look at the definitions of several important terms.

Feeds: A feed is a stream of events which all belong to some trigger T. A feed is controlled by a feed action which handles creating, deleting, pausing, and resuming the stream of events which comprise a feed. The feed action typically interacts with external services which produce the events, via a REST API that manages notifications.

Triggers: A trigger is technically a name for a class of events. Each event belongs to precisely one trigger; by analogy, a trigger resembles a topic in topic-based pub-sub systems. A rule T -> A means "whenever an event from trigger T arrives, invoke action A with the trigger payload.

Actions: Actions are stateless functions that run on the OpenWhisk platform. For example, an action can be used to detect the faces in an image, respond to a database change, react to an API call, or post a Tweet. In general, an action is invoked in response to an event and produces some observable output.

Setting Up Your ECS Instance

You will need an Alibaba Cloud ECS instance with Ubuntu 18.04(64-bit) system image installed. If you are new to Alibaba Cloud, You can create an account by clicking here through which you can use Alibaba Cloud products values over $300 - $1200

There are already many articles that describe the steps for spinning up an ECS instance in detail, so I will briefly go over the steps below.

Steps involved in creating instances:

  • Basic Configurations:
    • Billing method: Make sure you choose "Pay-As-You-Go" if you are prototyping the application
    • Image: You need to select Ubuntu 18.04(64-bit)

      1

  • Networking
    • All the obvious options here, make sure you select the proper security group here, anyways we can open the ports while we are working on this
  • System Configurations
    • I choose password-based authentication, choose according to your requirement
  • Grouping
  • Preview
    • The complete information of the selected configuration which you can also save it as a template for future single click ECS instance provision.
    • If you wish to release the instance at the later point of time select the Auto-Release schedule

Once your instance is up and running like below,

2

Let's connect to the instance using ssh like below

ssh root@<IP ADDRESS>
The authenticity of host 'AAA.CCC.BBB.DDD' can't be established.
ECDSA key fingerprint is SHA256:/il4fRYvgAake/ENoBgJSZvdO8DxY7H99oeIuye8AEo.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ' AAA.CCC.BBB.DDD ' (ECDSA) to the list of known hosts.

root@<IP ADDRESS>'s password: 
Welcome to Ubuntu 18.04 LTS (GNU/Linux 4.15.0-23-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

Welcome to Alibaba Cloud Elastic Compute Service !

You will see the latest installed Ubuntu along with the welcome message, we will update the package entries by running the following command

sudo apt-get update

Once done, we will upgrade any obsolete packages. We will know what packages are to be updated and removed by executing below

sudo apt-get upgrade

You will see similar message as below, where it asks for your consent to upgrade

The following packages were automatically installed and are no longer required:
  libopts25 sntp
Use 'sudo apt autoremove' to remove them.
The following packages have been kept back:
  linux-generic linux-headers-generic linux-image-generic
The following packages will be upgraded:
  amd64-microcode apparmor apt apt-utils base-files bind9-host binutils binutils-common binutils-x86-64-linux-gnu
  bsdutils chrony console-setup console-setup-linux cpp cpp-7 cups-bsd cups-client cups-common curl
  distro-info-data dnsutils dpkg dpkg-dev fdisk friendly-recovery g++ g++-7 gcc gcc-7 gcc-7-base gcc-8-base
  grub-common grub-pc grub-pc-bin grub2-common guile-2.0-libs initramfs-tools initramfs-tools-bin
  initramfs-tools-core intel-microcode iperf keyboard-configuration kmod language-pack-en language-pack-en-base
  language-pack-gnome-en language-pack-gnome-en-base libapparmor1 libapt-inst2.0 libapt-pkg5.0
  libarchive-zip-perl libarchive13 libasan4 libatomic1 libavahi-client3 libavahi-common-data libavahi-common3
  libbind9-160 libbinutils libblkid1 libcc1-0 libcilkrts5 libcryptsetup12 libcups2 libcupsimage2 libcurl4
  libdns-export1100 libdns1100 libdpkg-perl libfdisk1 libgcc-7-dev libgcc1 libglib2.0-0 libglib2.0-data libgomp1
  libirs160 libisc-export169 libisc169 libisccc160 libisccfg160 libitm1 libjpeg-turbo8 libkmod2 liblsan0
  liblwres160 libmount1 libmpx2 libmysqlclient20 libnss-systemd libpam-systemd libparted2 libperl5.26
  libplymouth4 libpng16-16 libpolkit-gobject-1-0 libpython3-stdlib libpython3.6 libpython3.6-minimal
  libpython3.6-stdlib libquadmath0 librados2 librbd1 libsmartcols1 libstdc++-7-dev libstdc++6 libsystemd0
  libtsan0 libubsan0 libudev1 libuuid1 libx11-6 libx11-data libxml2 linux-libc-dev lshw man-db mount netplan.io
  networkd-dispatcher nplan openssh-client openssh-server openssh-sftp-server parted perl perl-base
  perl-modules-5.26 plymouth plymouth-theme-ubuntu-text python-apt-common python3 python3-apt python3-distupgrade
  python3-minimal python3-requests python3-update-manager python3.6 python3.6-minimal sntp ssh systemd
  systemd-sysv tzdata ubuntu-release-upgrader-core udev update-manager-core util-linux uuid-runtime
148 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.
Need to get 79.6 MB of archives.
After this operation, 312 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y

Input 'Y' and also if you wish to remove the unused packages, unlike upgrade where it happens after giving consent, removal have to be done by executing below

sudo apt autoremove

Which will also give the similar prompt asking for the same. The upgrade will take a while, there might be some warning you might see while installing like below

perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
  LANGUAGE = (unset),
  LC_ALL = (unset),
  LC_CTYPE = "UTF-8",
  LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to a fallback locale ("en_US.UTF-8").

Fix:

Check for locale, of the target system, by running 'locale', you will see the below output

root@iZa2d4spx9n9e90jofcyxoZ:~# locale
LANGUAGE=
LC_CTYPE=C.UTF-8
LC_NUMERIC="C.UTF-8"
LC_TIME="C.UTF-8"
LC_COLLATE="C.UTF-8"
LC_MONETARY="C.UTF-8"
LC_MESSAGES="C.UTF-8"
LC_PAPER="C.UTF-8"
LC_NAME="C.UTF-8"
LC_ADDRESS="C.UTF-8"
LC_TELEPHONE="C.UTF-8"
LC_MEASUREMENT="C.UTF-8"
LC_IDENTIFICATION="C.UTF-8"
LC_ALL=

You need to set the "LC_ALL" and "Language" by running

~root@iZa2d4spx9n9e90jofcyxoZ:~# export LANGUAGE="en_US.UTF-8"
~root@iZa2d4spx9n9e90jofcyxoZ:~# export LC_ALL="en_US.UTF-8"

Before we proceed any other we need to point the pip registry to the global site, this can be done by executing the following command

~root@iZa2d4spx9n9e90jofcyxoZ:~# sudo nano /root/.pip/pip.conf

Replace the output with the below text

## Note, this file is written by cloud-init on first boot of an instance
## modifications made here will not survive a re-bundle.
###[m
[global]
## index-url=http://ap-south-1.mirrors.cloud.aliyuncs.com/pypi/simple/
index-url=https://pypi.python.org/simple/
[install]
## trusted-host=ap-south-1.mirrors.cloud.aliyuncs.com
trusted-host=pypi.python.org

Now install all the required tools and other packages using the following command

sudo apt-get install git python-pip python-setuptools build-essential libssl-dev libffi-dev python-dev software-properties-common

Once the packages are installed, we are ready to install the ansible

~root@iZa2d4spx9n9e90jofcyxoZ:~# sudo pip install ansible==2.1.2.0

If the installation is successful you will get the following message

Successfully installed ansible-2.1.2.0 bcrypt-3.1.4 cffi-1.11.5 paramiko-2.4.2 pyasn1-0.4.4 pycparser-2.19 pynacl-1.3.0
You are using pip version 10.0.1, however version 18.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

Installing Docker

Now we will install Docker on our ECS instance. First, add we will add the key and the repository.

~root@iZa2d4spx9n9e90jofcyxoZ:~# curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
OK
root@iZa2d4spx9n9e90jofcyxoZ:~# sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable"

Update the repository.

~root@iZa2d4spx9n9e90jofcyxoZ:~# sudo apt update

We will set and make sure that stable version from the Docker repository, we can also verify that using the Docker command.

~root@iZa2d4spx9n9e90jofcyxoZ:~# apt-cache policy docker-ce

The output should/will be

docker-ce:
  Installed: (none)
  Candidate: 5:18.09.0~3-0~ubuntu-bionic
  Version table:
     5:18.09.0~3-0~ubuntu-bionic 500
        500 https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages
     18.06.1~ce~3-0~ubuntu 500
        500 https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages
     18.06.0~ce~3-0~ubuntu 500
        500 https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages
     18.03.1~ce~3-0~ubuntu 500
        500 https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages

We will install the docker by running the install command

~root@iZa2d4spx9n9e90jofcyxoZ:~# sudo apt install docker-ce

You can verify the installation by running the following command

~root@iZa2d4spx9n9e90jofcyxoZ:~# sudo systemctl status docker

The output will show running

docker.service - Docker Application Container Engine[m
   Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
   Active: active (running) since Sat CST; 4s ago
     Docs: https://docs.docker.com[m
 Main PID: 25119 (dockerd)
    Tasks: 9
   CGroup: /system.slice/docker.service
           └─25119 /usr/bin/dockerd -H unix://

We need to make some changes to the configuration file, edit the config file using the command below

~root@iZa2d4spx9n9e90jofcyxoZ:~# sudo vi /lib/systemd/system/docker.service

And update the "ExecStart" with the line below

/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock

We will reload the docker daemon and restart the docker service

root@iZa2d4spx9n9e90jofcyxoZ:~# sudo systemctl daemon-reload
root@iZa2d4spx9n9e90jofcyxoZ:~# sudo systemctl restart docker.service

Once we see the status as running, we can check the other environment details by running the following command

~root@iZa2d4spx9n9e90jofcyxoZ:~# curl http://localhost:2375/version
{"Platform":{"Name":"Docker Engine - Community"},"Components":[{"Name":"Engine","Version":"18.09.0","Details":{"ApiVersion":"1.39","Arch":"amd64","BuildTime":"ABCD","Experimental":"false","GitCommit":"4d60db4","GoVersion":"go1.10.4","KernelVersion":"4.15.0-23-generic","MinAPIVersion":"1.12","Os":"linux"}}],"Version":"18.09.0","ApiVersion":"1.39","MinAPIVersion":"1.12","GitCommit":"4d60db4","GoVersion":"go1.10.4","Os":"linux","Arch":"amd64","KernelVersion":"4.15.0-23-generic","BuildTime":"ABCD"}

In next part of this tutorial , we will see the detailed installation instructions for CouchDB, different ways of configuring it either in clustered mode or on a single machine format. Once we complete that, we will proceed with OpenWhisk installation and testing.

0 0 0
Share on

Alibaba Clouder

2,599 posts | 758 followers

You may also like

Comments

Alibaba Clouder

2,599 posts | 758 followers

Related Products

  • Function Compute

    Alibaba Cloud Function Compute is a fully-managed event-driven compute service. It allows you to focus on writing and uploading code without the need to manage infrastructure such as servers.

    Learn More
  • OSS(Object Storage Service)

    An encrypted and secure cloud storage service which stores, processes and accesses massive amounts of data from anywhere in the world

    Learn More
  • Marketplace

    Marketplace is an online market for users to search and quickly use the software as image for Alibaba Cloud products.

    Learn More