Skip to main content
Redhat Developers  Logo
  • Products

    Featured

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat OpenShift AI
      Red Hat OpenShift AI
    • Red Hat Enterprise Linux AI
      Linux icon inside of a brain
    • Image mode for Red Hat Enterprise Linux
      RHEL image mode
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • Red Hat Developer Hub
      Developer Hub
    • View All Red Hat Products
    • Linux

      • Red Hat Enterprise Linux
      • Image mode for Red Hat Enterprise Linux
      • Red Hat Universal Base Images (UBI)
    • Java runtimes & frameworks

      • JBoss Enterprise Application Platform
      • Red Hat build of OpenJDK
    • Kubernetes

      • Red Hat OpenShift
      • Microsoft Azure Red Hat OpenShift
      • Red Hat OpenShift Virtualization
      • Red Hat OpenShift Lightspeed
    • Integration & App Connectivity

      • Red Hat Build of Apache Camel
      • Red Hat Service Interconnect
      • Red Hat Connectivity Link
    • AI/ML

      • Red Hat OpenShift AI
      • Red Hat Enterprise Linux AI
    • Automation

      • Red Hat Ansible Automation Platform
      • Red Hat Ansible Lightspeed
    • Developer tools

      • Red Hat Trusted Software Supply Chain
      • Podman Desktop
      • Red Hat OpenShift Dev Spaces
    • Developer Sandbox

      Developer Sandbox
      Try Red Hat products and technologies without setup or configuration fees for 30 days with this shared Openshift and Kubernetes cluster.
    • Try at no cost
  • Technologies

    Featured

    • AI/ML
      AI/ML Icon
    • Linux
      Linux Icon
    • Kubernetes
      Cloud icon
    • Automation
      Automation Icon showing arrows moving in a circle around a gear
    • View All Technologies
    • Programming Languages & Frameworks

      • Java
      • Python
      • JavaScript
    • System Design & Architecture

      • Red Hat architecture and design patterns
      • Microservices
      • Event-Driven Architecture
      • Databases
    • Developer Productivity

      • Developer productivity
      • Developer Tools
      • GitOps
    • Secure Development & Architectures

      • Security
      • Secure coding
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
      • View All Technologies
    • Start exploring in the Developer Sandbox for free

      sandbox graphic
      Try Red Hat's products and technologies without setup or configuration.
    • Try at no cost
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • Java
      Java icon
    • AI/ML
      AI/ML Icon
    • View All Learning Resources

    E-Books

    • GitOps Cookbook
    • Podman in Action
    • Kubernetes Operators
    • The Path to GitOps
    • View All E-books

    Cheat Sheets

    • Linux Commands
    • Bash Commands
    • Git
    • systemd Commands
    • View All Cheat Sheets

    Documentation

    • API Catalog
    • Product Documentation
    • Legacy Documentation
    • Red Hat Learning

      Learning image
      Boost your technical skills to expert-level with the help of interactive lessons offered by various Red Hat Learning programs.
    • Explore Red Hat Learning
  • Developer Sandbox

    Developer Sandbox

    • Access Red Hat’s products and technologies without setup or configuration, and start developing quicker than ever before with our new, no-cost sandbox environments.
    • Explore Developer Sandbox

    Featured Developer Sandbox activities

    • Get started with your Developer Sandbox
    • OpenShift virtualization and application modernization using the Developer Sandbox
    • Explore all Developer Sandbox activities

    Ready to start developing apps?

    • Try at no cost
  • Blog
  • Events
  • Videos

Part 1: Introduction to Serverless with Knative

February 19, 2019
Doug Tidwell
Related topics:
ContainersKubernetesServerless

Share:

    The Knative serverless environment lets you deploy code to Kubernetes, but no resources are consumed unless your code needs to do something. With Knative, you create a service by packaging your code as a Docker image and handing it to the system. Your code only runs when it needs to, with Knative starting and stopping instances automatically. This article shows you how to take advantage of this technology.

    coderland_1

    The Compile Driver

    The Compile Driver is a new thrill ride at the Coderland theme park. It starts by hoisting riders to the top of an enormous tower. From there, they plunge through the air towards the reinforced concrete pad at the base of the ride. Unfortunately, as the Compile Driver’s safety record has become public knowledge, ridership has fallen far short of expectations. Here's a video that explains the complete scenario: 

    Your assignment

    With the park’s revenue targets at risk, management turns to you, the most talented developer in all of Coderland, to create a photo booth that captures the faces of delighted riders as they plummet helplessly to the ground. You’ll create a serverless function to take raw image data from a camera planted next to the ride, then stamp a message, the date, and the Coderland logo on the picture. Guests can, of course, purchase a copy of the heirloom-quality photo as they stagger away from the ride, filling the park’s coffers in the process.

    The overall flow looks like this: 

    Your assignment is to take something like this picture of a happy Coderland guest:

    Your assignment is to take something like this picture of a happy Coderland guest

    ...and transform it into this priceless memento, available for $19.95 at the Coderland Swag Shop:

    Add captions and a logo to the image

    Many early riders of the Compile Driver asked for a souvenir photo of their ordeal, something they could share with their friends, loved ones, and attorneys. For that reason, we believe the Coderland Photo Booth will be a smashing success.

    A brief word about serverless

    The main reasons for using serverless computing are more economic than technical. In the case of the Compile Driver Photo Booth, the code only needs to run for a second or two each time we find enough hardy souls willing to be strapped onto the ride. That means that even on a busy day, the code might not run more than a few minutes total. Setting up a server that runs 24/7 to host the image manipulation code means that the vast majority of the time we’re paying for processing power that isn’t being used. Even more troubling, if we maintain our own server, we’re responsible for keeping it up-to-date with patches and upgrades.

    That’s what gives serverless computing its power. We don’t pay per minute, we pay per invocation. So as with most of cloud computing we only pay for what we use, but we use far less than before. We’ll deploy a service to Knative, and Knative will start and stop the service as needed. If we don’t call the image manipulation code for some period of time, Knative shuts it down. You’ll hear the phrase scale to zero often as you work with serverless computing. The service still exists, it’s just not running. When we do call the service, Knative fires it up. And, as the word “serverless” implies, we don’t have our own server to manage or maintain.

    Getting from here to there

    To help you complete your assignment, we’ll go through four steps:

    1. Review the image manipulation code that works with the actual photo (covered in part 2)

    2. Take a look at a React front end that lets you test the image manipulation code easily (covered in part 2)

    3. Deploy the image manipulation code to Knative running inside Kubernetes (covered in part 3)

    4. Work around an issue that prevents the React front end from calling the service inside Knative (covered in part 3)

    Along the way we have more videos, git repos, Docker images, and other useful resources. Good luck and have fun!

    What's next

    We'd love to hear your comments and questions on this content. You can reach us at [email protected].

    Beyond that, there are two more articles in this series: 

    • Part 2: Building a serverless service
    • Part 3: Deploying the serverless service to Knative

    Be aware that the two articles are independent. You can run the image manipulation service without deploying it to Knative, and you can skip directly to the Knative article without having gone through the code. 

    But seriously, you should ignore all of your responsibilities and obligations and go through both articles now. Have fun!

    Last updated: April 21, 2021

    Related Posts

    • Part 2: Building a Serverless Service

    • Part 3: Deploying a Serverless Service to Knative

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Products

    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform

    Build

    • Developer Sandbox
    • Developer Tools
    • Interactive Tutorials
    • API Catalog

    Quicklinks

    • Learning Resources
    • E-books
    • Cheat Sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site Status Dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Report a website issue