Reader small image

You're reading from  Mastering Kubernetes, - Third Edition

Product typeBook
Published inJun 2020
PublisherPackt
ISBN-139781839211256
Edition3rd Edition
Right arrow
Author (1)
Gigi Sayfan
Gigi Sayfan
author image
Gigi Sayfan

Gigi Sayfan has been developing software for 25+ years in domains as diverse as instant messaging, morphing, chip fabrication process control, embedded multimedia applications for game consoles, brain-inspired ML, custom browser development, web services for 3D distributed game platforms, IoT sensors, virtual reality, and genomics. He has written production code in languages such as Go, Python, C, C++, C#, Java, Delphi, JavaScript, and even Cobol and PowerBuilder for operating systems such as Windows (3.11 through 7), Linux, macOS, Lynx (embedded), and Sony PlayStation. His technical expertise includes databases, low-level networking, distributed systems, containers, unorthodox user interfaces, modern web applications, and general SDLC.
Read more about Gigi Sayfan

Right arrow

Serverless Computing on Kubernetes

In this chapter, we will explore the fascinating world of serverless computing in the cloud. The term "serverless" is getting a lot of attention, but it is a misnomer used to describe two different paradigms. A true serverless application runs as a web application in the user's browser or a mobile app and only interacts with external services. The types of serverless systems we build on Kubernetes are different. We will explain exactly what serverless means on Kubernetes and how it relates to other serverless solutions. We will cover serverless cloud solutions, introduce Knative – the Kubernetes foundation for functions as a service – and dive into Kubernetes Functions as a Service (FaaS) frameworks.

Let's start by clarifying what serverless is all about.

Understanding serverless computing

OK. Let's get it out of the way. The servers are still there. The term "serverless" means that you don't have to provision, configure, and manage the servers yourself. Public cloud platforms were a real paradigm shift by eliminating the need for dealing with physical hardware, data centers, and networking. But, even on the cloud it takes a lot of work and knowhow to create and provision machine images, provision instances, configure them, upgrade and patch operating systems, define network policies, and manage certificates and access control. With serverless computing, large chunks of this important but tedious work go away.

The allure of serverless is multi-pronged:

  • A whole category of problems dealing with provisioning goes away
  • Capacity planning is a non-issue
  • You pay only for what you use

You lose some control because you have to live with the choices made by the cloud provider. But, there...

Serverless Kubernetes in the cloud

All the major cloud providers now supports serverless long-running services for Kubernetes. Surprisingly, Microsoft Azure was the first to offer this. Kubernetes interacts with nodes via the kubelet. The basic idea of serverless infrastructure is that instead of provisioning actual nodes (be they physical or on virtual machines (VMs)), a virtual node is created in some fashion. Different cloud providers use different solutions to accomplish this goal.

Don't forget the cluster autoscaler

Before jumping into cloud provider-specific solutions, make sure to check out the Kubernetes-native option of the cluster autoscaler. The cluster autoscaler scales the nodes in your cluster and doesn't suffer from the limitations of some of the other solutions. All the Kubernetes scheduling and control mechanisms work out of the box with the cluster autoscaler because it just automates adding and removing regular nodes from your cluster. No exotic...

Knative

Kubernetes doesn't have built-in support for FaaS. As a result, many solutions were developed by the community for the ecosystem. The goal of Knative is to provide building blocks that multiple FaaS solutions can utilize without reinventing the wheel.

But that's not all! Knative also offers the unique capability of scaling long-running services all the way down to zero. This is a big deal. There are many use cases where you may prefer to have a long-running service that can handle a lot of requests coming its way in rapid succession. In those situations, it is not the best approach to fire a new function instance per request. But, when there is no traffic coming in, it's great to scale the service to zero instances, pay nothing, and leave more capacity for other services that may need more resources at that time. Knative supports other important use cases including load balancing based on percentages, load balancing based on metrics, blue-green deployments...

Kubernetes FaaS frameworks

Let's acknowledge the elephant in the room – FaaS. The Kubernetes Job and CronJob are great, and having cluster autoscaling and cloud providers managing the infrastructure is awesome. Knative, with its scale-to-zero and traffic routing functionalities, is super cool. But what about actual FaaS? Fear not – Kubernetes has many options here. Maybe too many options. There are more than ten FaaS frameworks for Kubernetes:

  • Fission
  • Kubeless
  • FaaS
  • OpenWhisk
  • Riff (built on top of Knative)
  • Nuclio
  • Funktion
  • BlueNimble
  • Fn
  • Gestalt
  • Rainbond
  • IronFunctions

We will look into a few of the more popular options.

Fission

Fission (https://fission.io/) is a mature and well-documented framework. It models the FaaS world as environments, functions, and triggers. Environments are needed to build and run your function code for the specific languages. Each language environment...

Summary

In this chapter, we covered the hot topic of serverless computing. We explained the two meanings of serverless – eliminating the need to manage servers, and deploying and running FaaS. We explored in depth the aspects of serverless infrastructure in the cloud, especially in the context of Kubernetes. We compared the built-in cluster autoscaler as a Kubernetes-native serverless solution to the offerings of cloud providers such as AWS EKS+Fargate, Azure AKS+ACI, and Google Cloud Run. We switched gears and dove into the exciting and promising Knative project with its scale-to-zero capabilities and advanced deployment options. Then, we moved to the wild world of FaaS on Kubernetes. We mentioned the plethora of solutions out there and examined them in detail with hands-on experiments for some of the prominent solutions out there: Fission, Kubeless, and riff. The bottom line is that both flavors of serverless computing bring real benefits as far as operations and cost management...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Mastering Kubernetes, - Third Edition
Published in: Jun 2020Publisher: PacktISBN-13: 9781839211256
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime

Author (1)

author image
Gigi Sayfan

Gigi Sayfan has been developing software for 25+ years in domains as diverse as instant messaging, morphing, chip fabrication process control, embedded multimedia applications for game consoles, brain-inspired ML, custom browser development, web services for 3D distributed game platforms, IoT sensors, virtual reality, and genomics. He has written production code in languages such as Go, Python, C, C++, C#, Java, Delphi, JavaScript, and even Cobol and PowerBuilder for operating systems such as Windows (3.11 through 7), Linux, macOS, Lynx (embedded), and Sony PlayStation. His technical expertise includes databases, low-level networking, distributed systems, containers, unorthodox user interfaces, modern web applications, and general SDLC.
Read more about Gigi Sayfan