Before You Start

This documentation assumes that the Kubernetes cluster has been created and that you have access to it.

The cluster used for implementation was a GKE 1.19

Change the URL to your test domain

Dependencies

  • Kubernetes cluster
  • nginx-ingress as ingress controller
  • kubectl
  • unzip
  • apache-utils (Apache Benchmark package for load testing)

Installing Kubeless

asciicast

  1. Export the environment variable by fetching the latest Kubeless version from the git repository.

    export RELEASE=$(curl -s https://api.github.com/repos/kubeless/kubeless/releases/latest | grep tag_name | cut -d '"' -f 4)
    
  2. Execute the command to install Kubeless on the cluster

    kubectl create -f https://github.com/kubeless/kubeless/releases/download/$RELEASE/kubeless-non-rbac-$RELEASE.yaml
    
  3. Check if the Kubeless controller is running correctly (Running)

    kubectl get pods -n kubeless
    

Installing the Kubeless CLI

asciicast

  1. Export the environment variable to set the operating system.

    export OS=$(uname -s| tr '[:upper:]' '[:lower:]')
    
  2. Execute the curl command to download and install the Kubeless CLI.

    mkdir -p ~/bin; curl -OL https://github.com/kubeless/kubeless/releases/download/$RELEASE/kubeless_$OS-amd64.zip && unzip kubeless_$OS-amd64.zip mv bundles/kubeless_$OS-amd64/kubeless ~/bin; chmod +x ~/bin/kubeless
    
  3. Check if the command was installed correctly

    kubeless -h
    

Implementing a Sample Go Function

asciicast

  1. Clone the example repository

    git clone https://github.com/rafaelperoco/using-kubernetes-as-a-serverless-platform.git
    
  2. Enter the directory and execute the command to create the Function

    cd using-kubernetes-as-a-serverless-platform/
    kubeless function deploy goserverless --cpu 100m --runtime go1.14 --handler helloget.Hello --from-file helloget.go --dependencies go.mod
    
  3. Create the trigger that will be used to activate the Function created earlier

    kubeless trigger http create goserverless --function-name goserverless --hostname kubeless.rafaelperoco.dev --gateway nginx
    
  4. Create the test Autoscale rule, allowing for simple load testing

    kubeless autoscale create goserverless --min 1 --max 1000 --metric cpu --value 1
    
  5. Wait a few minutes for resource creation and test the endpoint

    curl --header "Host: kubeless.rafaelperoco.dev" --header "Content-Type:application/json" kubeless.rafaelperoco.dev --data '{"message": "Hello World from Kubeless"}'
    

Simple Load Test

  1. Run the load test with Apache Benchmark

    ab -n 50000 -c 1000 kubeless.rafaelperoco.dev/
    
  2. Check if the nodes are scaling

    watch kubectl get nodes