{"id":593,"date":"2021-05-29T19:13:00","date_gmt":"2021-05-29T17:13:00","guid":{"rendered":"https:\/\/nubisoft.io\/blog\/?p=593"},"modified":"2021-06-01T08:57:46","modified_gmt":"2021-06-01T06:57:46","slug":"openfaas-avoiding-serverless-vendor-lock-in","status":"publish","type":"post","link":"https:\/\/nubisoft.io\/blog\/openfaas-avoiding-serverless-vendor-lock-in\/","title":{"rendered":"OpenFaaS &#8211; how to avoid vendor lock-in when doing serverless"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">Recently serverless computing gets more and more attention and popularity. Thanks to this concept you can increase your productivity because it let you focus almost exclusively on implementing business logic and getting, at the same time, all the enterprise-ready scalability and availability. <a href=\"https:\/\/www.openfaas.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">OpenFaaS<\/a> is a very interesting player here, as it can be easily deployed on execution environments of ANY size, and ANY flavor.<\/h3>\n\n\n\n<p>When our customers, those more IT educated, ask us if we could develop for them something serverless-like, our answer is: yes we can, and we can do this in a way not letting you cry when you get billings from your cloud service providers.<\/p>\n\n\n\n<p>Currently, each and every big cloud service provider offers serverless computing services. AWS offers their <a rel=\"noreferrer noopener\" href=\"https:\/\/aws.amazon.com\/lambda\/\" target=\"_blank\">Lambda <\/a>and <a rel=\"noreferrer noopener\" href=\"https:\/\/aws.amazon.com\/fargate\/\" target=\"_blank\">Fargate<\/a>, Microsoft offers <a rel=\"noreferrer noopener\" href=\"https:\/\/azure.microsoft.com\/en-us\/services\/functions\/\" target=\"_blank\">Functions <\/a>and <a rel=\"noreferrer noopener\" href=\"https:\/\/azure.microsoft.com\/en-us\/services\/container-instances\/\" target=\"_blank\">Container Instances<\/a>, and Google offers <a rel=\"noreferrer noopener\" href=\"https:\/\/cloud.google.com\/functions\/\" target=\"_blank\">Cloud Functions<\/a> and <a rel=\"noreferrer noopener\" href=\"https:\/\/cloud.google.com\/run\/\" target=\"_blank\">Cloud Run<\/a>. Each of them tempts with unique options, interesting offers, and easy integration with the rest of their monitoring, security, and repositories ecosystem. Let&#8217;s not forget, however, that there are no free lunches and that we will have to pay for everything &#8211; sooner or later. Once we find out how much all these costs, some will decide to take the path of unlocking-in from the given cloud provider. So you better read this article BEFORE you make decisions.<\/p>\n\n\n\n<p><a rel=\"noreferrer noopener\" href=\"https:\/\/www.openfaas.com\/\" target=\"_blank\">OpenFaaS <\/a>is a solution that has been gaining popularity for some time, mainly due to the ease of implementation and the constantly growing support of the community. Today we will show you how easy it can be deployed for testing purposes, even on a single computing node. Of course, it will be on our beloved Ubuntu \ud83d\ude09<\/p>\n\n\n\n<p>First, let us set up a minimal but production-ready Kubernetes implementation &#8211; <a href=\"https:\/\/rancher.com\/docs\/k3s\/\" target=\"_blank\" rel=\"noreferrer noopener\">k3s<\/a>! <\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">curl -sfL https:\/\/get.k3s.io | sh -<\/pre>\n\n\n\n<p>Let&#8217;s check if k3s services are up and running.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo systemctl status k3s<\/pre>\n\n\n\n<p>In response, you should get something like that:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"467\" src=\"https:\/\/nubisoft.io\/blog\/wp-content\/uploads\/2021\/05\/OpenFaaS-k3s_services-1024x467.png\" alt=\"\" class=\"wp-image-598\" srcset=\"https:\/\/nubisoft.io\/blog\/wp-content\/uploads\/2021\/05\/OpenFaaS-k3s_services-1024x467.png 1024w, https:\/\/nubisoft.io\/blog\/wp-content\/uploads\/2021\/05\/OpenFaaS-k3s_services-300x137.png 300w, https:\/\/nubisoft.io\/blog\/wp-content\/uploads\/2021\/05\/OpenFaaS-k3s_services-768x350.png 768w, https:\/\/nubisoft.io\/blog\/wp-content\/uploads\/2021\/05\/OpenFaaS-k3s_services-1536x701.png 1536w, https:\/\/nubisoft.io\/blog\/wp-content\/uploads\/2021\/05\/OpenFaaS-k3s_services-2048x935.png 2048w, https:\/\/nubisoft.io\/blog\/wp-content\/uploads\/2021\/05\/OpenFaaS-k3s_services-1200x548.png 1200w, https:\/\/nubisoft.io\/blog\/wp-content\/uploads\/2021\/05\/OpenFaaS-k3s_services-1980x904.png 1980w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Now, to be able to interact with our FaaS component, we have to install faas-cli:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">curl -sL https:\/\/cli.openfaas.com | sudo sh<\/pre>\n\n\n\n<p>The easiest option to install OpenFaaS is to use the light K8S package manager &#8211; <a rel=\"noreferrer noopener\" href=\"https:\/\/www.openfaas.com\/blog\/openfaas-arkade\/\" target=\"_blank\">Arkade<\/a>:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">curl -sLS https:\/\/dl.get-arkade.dev | sudo sh<\/pre>\n\n\n\n<p>Since on my Ubuntu I got the following error:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">[Warning] unable to create secret basic-auth, may already exist ... unable to read \/etc\/rancher\/k3s.yaml, please start server with --write-kubeconfig-mode to modify kube config permissions ... error loading config file \"\/etc\/rancher\/k3s\/k3s.yaml\" open \/etc\/rancher\/k3s\/k3s.yaml: permission denied<\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"177\" src=\"https:\/\/nubisoft.io\/blog\/wp-content\/uploads\/2021\/05\/Fig-FaaS_error-1024x177.png\" alt=\"\" class=\"wp-image-599\" srcset=\"https:\/\/nubisoft.io\/blog\/wp-content\/uploads\/2021\/05\/Fig-FaaS_error-1024x177.png 1024w, https:\/\/nubisoft.io\/blog\/wp-content\/uploads\/2021\/05\/Fig-FaaS_error-300x52.png 300w, https:\/\/nubisoft.io\/blog\/wp-content\/uploads\/2021\/05\/Fig-FaaS_error-768x133.png 768w, https:\/\/nubisoft.io\/blog\/wp-content\/uploads\/2021\/05\/Fig-FaaS_error-1536x266.png 1536w, https:\/\/nubisoft.io\/blog\/wp-content\/uploads\/2021\/05\/Fig-FaaS_error-2048x355.png 2048w, https:\/\/nubisoft.io\/blog\/wp-content\/uploads\/2021\/05\/Fig-FaaS_error-1200x208.png 1200w, https:\/\/nubisoft.io\/blog\/wp-content\/uploads\/2021\/05\/Fig-FaaS_error-1980x343.png 1980w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>&#8230; I changed the permission for \/etc\/rancher\/k3s\/ks3.yaml to 744 \ud83d\ude42<\/p>\n\n\n\n<p>Then I&#8217;ve hit the next problem:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Error: Kubernetes cluster unreachable: Get \"http:\/\/localhost:8080\/version?timeout=32s\": dial tcp &#91;::1]:8080: connect: connection refused<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"151\" src=\"https:\/\/nubisoft.io\/blog\/wp-content\/uploads\/2021\/05\/Fig-FaaS_error2-1024x151.png\" alt=\"\" class=\"wp-image-600\" srcset=\"https:\/\/nubisoft.io\/blog\/wp-content\/uploads\/2021\/05\/Fig-FaaS_error2-1024x151.png 1024w, https:\/\/nubisoft.io\/blog\/wp-content\/uploads\/2021\/05\/Fig-FaaS_error2-300x44.png 300w, https:\/\/nubisoft.io\/blog\/wp-content\/uploads\/2021\/05\/Fig-FaaS_error2-768x113.png 768w, https:\/\/nubisoft.io\/blog\/wp-content\/uploads\/2021\/05\/Fig-FaaS_error2-1536x227.png 1536w, https:\/\/nubisoft.io\/blog\/wp-content\/uploads\/2021\/05\/Fig-FaaS_error2-2048x302.png 2048w, https:\/\/nubisoft.io\/blog\/wp-content\/uploads\/2021\/05\/Fig-FaaS_error2-1200x177.png 1200w, https:\/\/nubisoft.io\/blog\/wp-content\/uploads\/2021\/05\/Fig-FaaS_error2-1980x292.png 1980w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>.. and found a solution on <a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/k3s-io\/k3s\/issues\/1126#issuecomment-560504204\" target=\"_blank\">github<\/a>:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">kubectl config view --raw > ~\/.kube\/config<\/pre>\n\n\n\n<p>Then, you can repeat the installation of OpenFaaS using <code>arkade<\/code> again and this time it should be hopefully successful, but the output includes important information which we need to get started with <code>faas-cli<\/code> and <code>OpenFaaS<\/code>. As we have already install <code>faas-cli<\/code>, we will now need to forward the gateway to the machine.<\/p>\n\n\n\n<p>First, we will check the rollout status of the <code>gateway<\/code> by issuing the below command:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">kubectl rollout status -n openfaas deploy\/gateway<\/pre>\n\n\n\n<p>After that, we can forward the gateway to the machine:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">kubectl port-forward -n openfaas svc\/gateway 8080:8080 &amp;<\/pre>\n\n\n\n<p>Now, the last step is to discover the password for OpenFaaS UI which we will use to manage OpenFaaS. To do that execute the below command:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">PASSWORD=$(kubectl get secret -n openfaas basic-auth -o jsonpath=\"{.data.basic-auth-password}\" | base64 --decode; echo)\necho -n $PASSWORD | faas-cli login --username admin --password-stdin<\/pre>\n\n\n\n<p>You can read and store the password securly:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">echo $PASSWORD<\/pre>\n\n\n\n<p>Now, it is time to open your web browser and type in the address bar: <code>http:\/\/localhost:31112<\/code><\/p>\n\n\n\n<p><code>Username<\/code> is set to <code>admin<\/code> by default and the password is the one which you saved in the above step.<\/p>\n\n\n\n<p>Now by pressing the button &#8220;Deploy New Function&#8221; you open the gate to the world of experimentation and magic \ud83d\ude42<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"493\" src=\"https:\/\/nubisoft.io\/blog\/wp-content\/uploads\/2021\/05\/Fig-FaaS_deploy-1024x493.png\" alt=\"\" class=\"wp-image-601\" srcset=\"https:\/\/nubisoft.io\/blog\/wp-content\/uploads\/2021\/05\/Fig-FaaS_deploy-1024x493.png 1024w, https:\/\/nubisoft.io\/blog\/wp-content\/uploads\/2021\/05\/Fig-FaaS_deploy-300x144.png 300w, https:\/\/nubisoft.io\/blog\/wp-content\/uploads\/2021\/05\/Fig-FaaS_deploy-768x370.png 768w, https:\/\/nubisoft.io\/blog\/wp-content\/uploads\/2021\/05\/Fig-FaaS_deploy-1536x739.png 1536w, https:\/\/nubisoft.io\/blog\/wp-content\/uploads\/2021\/05\/Fig-FaaS_deploy-2048x986.png 2048w, https:\/\/nubisoft.io\/blog\/wp-content\/uploads\/2021\/05\/Fig-FaaS_deploy-1200x578.png 1200w, https:\/\/nubisoft.io\/blog\/wp-content\/uploads\/2021\/05\/Fig-FaaS_deploy-1980x953.png 1980w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>You can start safely with the <a href=\"https:\/\/github.com\/jmkhael\/faas-figlet\" target=\"_blank\" rel=\"noreferrer noopener\">figlet <\/a>function!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recently serverless computing gets more and more attention and popularity. Thanks to this concept you can increase your productivity because it let you focus almost exclusively on implementing business logic and getting, at the same time, all the enterprise-ready scalability and availability. OpenFaaS is a very interesting player here, as it can be easily deployed [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":595,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_case_study_excerpt":"","footnotes":""},"categories":[55,5,45],"tags":[207,206,208],"class_list":["post-593","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-devops","category-infrastructure","category-system-architecture","tag-k3s","tag-openfaas","tag-serverless"],"_links":{"self":[{"href":"https:\/\/nubisoft.io\/blog\/wp-json\/wp\/v2\/posts\/593","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nubisoft.io\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nubisoft.io\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nubisoft.io\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/nubisoft.io\/blog\/wp-json\/wp\/v2\/comments?post=593"}],"version-history":[{"count":7,"href":"https:\/\/nubisoft.io\/blog\/wp-json\/wp\/v2\/posts\/593\/revisions"}],"predecessor-version":[{"id":606,"href":"https:\/\/nubisoft.io\/blog\/wp-json\/wp\/v2\/posts\/593\/revisions\/606"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nubisoft.io\/blog\/wp-json\/wp\/v2\/media\/595"}],"wp:attachment":[{"href":"https:\/\/nubisoft.io\/blog\/wp-json\/wp\/v2\/media?parent=593"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nubisoft.io\/blog\/wp-json\/wp\/v2\/categories?post=593"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nubisoft.io\/blog\/wp-json\/wp\/v2\/tags?post=593"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}