\nSpin up an Ubuntu instance, test and delete<\/p>\n
Spin up (this took about 5 minutes the first time to get the latest Ubuntu LTS image)<\/p>\n
$ multipass launch --name test\n Launched: test\n<\/code><\/pre>\nTest a command<\/p>\n
$ multipass exec test -- lsb_release -a\n No LSB modules are available.\n Distributor ID:\tUbuntu\n Description:\tUbuntu 20.04.2 LTS\n Release:\t20.04\n Codename:\tfocal\n<\/code><\/pre>\nList instances<\/p>\n
$ multipass list\n Name State IPv4 Image\n test Running 192.168.64.2 Ubuntu 20.04 LTS\n<\/code><\/pre>\nStop and clean up\n$ multipass stop test\n$ multipass delete test\n$ multipass purge<\/p>\n<\/li>\n<\/ul>\n
Installing faasd<\/h2>\n\n\nCreate a new Ubuntu instance using multipass<\/code><\/p>\n2 cores and 2 gigs of RAM<\/p>\n
$ multipass launch --name faasd --cpus 2 --mem 2G\n Launched: faasd\n<\/code><\/pre>\n<\/li>\n\nOpen a bash shell on the Ubuntu instance<\/p>\n
$ multipass exec faasd \/bin\/bash \n To run a command as administrator (user "root"), use "sudo <command>".\n See "man sudo_root" for details.\n\n ubuntu@faasd:~$\n<\/code><\/pre>\n <\/p>\n<\/li>\n
\nCopy your ssh public key over to the instance so we can run ssh sessions directly against the instance<\/p>\n
NOTE: See the last section on how to create a SSH key if you don’t already have one.<\/p>\n
$ cat ~\/.ssh\/id_rsa.pub | pbcopy\n [pbcopy copies to the clipboard on macOS]\n \n Edit the authorized ssh keys for the instance and add the id_rsa.pub value\n ubuntu@faasd:~$ nano ~\/.ssh\/authorized_keys\n<\/code><\/pre>\n<\/li>\n\nTest ssh to the instance. Open a new terminal.<\/p>\n
Get the IP address of the instance<\/p>\n
$ multipass info faasd\n Name: faasd\n State: Running\n IPv4: 192.168.64.4\n Release: Ubuntu 20.04.2 LTS\n Image hash: c5f2f08c6a1a (Ubuntu 20.04 LTS)\n Load: 0.00 0.00 0.00\n Disk usage: 1.2G out of 4.7G\n Memory usage: 148.6M out of 1.9G\t\t\n<\/code><\/pre>\nSSH into the instance (note: ubuntu is the default username)<\/p>\n
$ ssh ubuntu@192.168.64.4\n<\/code><\/pre>\nIn my case because I have multiple keys for a number of services and because of the way my ~\/.ssh\/config file is setup, I need to explicitly state to use PreferredAuthentications=publickey<\/code><\/p>\n $ ssh -i ~\/.ssh\/id_rsa -o PreferredAuthentications=publickey ubuntu@192.168.64.4\n<\/code><\/pre>\n<\/li>\n\nNow you have two ways to get a shell on the running instance<\/p>\n
$ multipass exec faasd \/bin\/bash\n or\n $ ssh ubuntu@INSTANCE_IP\n<\/code><\/pre>\n<\/li>\n\nInstall faasd on the instance<\/p>\n
Drop to root user (just incase sudo fails along the way)<\/p>\n
ubuntu@faasd:~$ sudo -i\n root@faasd:~#\n<\/code><\/pre>\nClone the repo<\/p>\n
root@faasd:~# git clone https:\/\/github.com\/openfaas\/faasd --depth=1\n Cloning into 'faasd'...\n ...\n<\/code><\/pre>\nInstall<\/p>\n
root@faasd:~# cd faasd\n root@faasd:~# .\/hack\/install.sh\n ...\n Creating alias 'faas' for 'faas-cli'.\n ___ _____ ____\n \/ _ \\ _ __ ___ _ __ | ___|_ _ __ _\/ ___|\n | | | | '_ \\ \/ _ \\ '_ \\| |_ \/ _` |\/ _` \\___ \\\n | |_| | |_) | __\/ | | | _| (_| | (_| |___) |\n \\___\/| .__\/ \\___|_| |_|_| \\__,_|\\__,_|____\/\n |_|\n \n CLI:\n commit: 6b5e7a14a598527063c7c05fb4187739b6eb6d38\n version: 0.13.6\n<\/code><\/pre>\nVerify faasd is running<\/p>\n
root@faasd:~\/faasd# systemctl status faasd\n \u25cf faasd.service - faasd\n Loaded: loaded (\/lib\/systemd\/system\/faasd.service; enabled; vendor preset: enabled)\n Active: active (running) since Mon 2021-03-08 20:25:14 GMT; 5min ago\n Main PID: 14201 (faasd)\n Tasks: 7 (limit: 2344)\n Memory: 37.8M (limit: 500.0M)\n CGroup: \/system.slice\/faasd.service\n \u2514\u250014201 \/usr\/local\/bin\/faasd up\n<\/code><\/pre>\n<\/li>\n<\/ul>\nDeploying your first function<\/h2>\n I will be using the UI (web portal) for exploring the faasd setup as well as deploy my first FaaS.<\/p>\n
\n\nGet the admin user’s password<\/p>\n
ubuntu@faasd:~$ sudo cat \/var\/lib\/faasd\/secrets\/basic-auth-password ;echo\n zI24jRLe45DhUPa21S6BoNy5q1DpYUb0FuDwlLfUoBNo6yaDBMZEPTO2W3K\n<\/code><\/pre>\n<\/li>\n\nOpen up the UI in your browser. E.g. http:\/\/INSTANCE_IP:8080<\/p>\n<\/li>\n
\nProvide username "admin" and the password from the previous steps<\/p>\n
<\/p>\n<\/li>\n
\nSelect "Deploy New Function" and search for "ASCII Cows". Deploy it.<\/p>\n<\/li>\n
\nAfter a few seconds or so you will see COWS in the sidebar. Select it.<\/p>\n<\/li>\n
\nInvoke the function and you will get a random ascii cow<\/p>\n<\/li>\n
\nYou can also run curl against the deployed function<\/p>\n
$ curl http:\/\/192.168.64.4:8080\/function\/cows\n * (__)\n \\ (OO)\n \\-------\\\/\n \/ \\\\\n \/\/------\\\\\n ^^ ^^\n Cow who's just\n seen a McDonalds\n<\/code><\/pre>\n<\/li>\n<\/ul>\nMiscellaneous<\/h2>\nCreating a SSH key-pair<\/h3>\n I like to have a SSH key-pair per machine or service I use and store a backup copy in my password manager (1Password). For this example I will just create the default id_rsa key pair that will also be used for connecting to the Ubuntu local instances.<\/p>\n
Run the following command to create a 4kb RSA public and private key-pair. The filenames will be id_rsa (the private key, never ever share this one!) and id_rsa.pub (the public key)<\/p>\n
$ ssh-keygen -t rsa -b 4096 -f ~\/.ssh\/id_rsa -C "Add a comment here if you want"\n<\/code><\/pre>\n <\/p>\n
I use the password manager to generate a strong passphrase. To rule out any copy\/paste and unrecoverable errors in the future, I like to copy\/paste the stored secret from my recording (password manager entry) and then when asked to confirm, I manually type it in. This way I can be sure that what I copy\/paste will always be correct and at the very least I would be able to manually type it in if the need ever presented itself.<\/p>\n
Backup the generated key-pair (~\/.ssh\/id_rsa and ~\/.ssh\/id_rsa.pub) to your password manager. Tip:<\/strong> To see hidden files on macOS (in Finder or File dialogue) enter Cmd + Shift + .<\/code> (period for dot files).<\/p>\nAdd the key to your macOS login keychain so you don’t have to always enter the passphrase.<\/p>\n
$ ssh-add -K ~\/.ssh\/id_rsa<\/code><\/pre>\n<\/div>\n","protected":false},"excerpt":{"rendered":"Photo by Luca Bravo on Unsplash […]<\/p>\n
Read more →<\/a><\/p>\n","protected":false},"author":2,"featured_media":204,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[37],"tags":[35,36],"yoast_head":"\n100 Days of Learning: Day 0 - Serverless, OpenFaaS and Multipass - Andr\u00e9 Jacobs<\/title>\n \n \n \n \n \n \n \n \n \n \n \n \n\t \n\t \n\t \n \n \n \n \n \n\t \n\t \n\t \n