Serverless na swoim

jak uruchomić własną platformę serverless w oparciu o Kubernetes

Serverless

Serverless computing is a cloud-computing execution model in which the cloud provider runs the server, and dynamically manages the allocation of machine resources. Pricing is based on the actual amount of resources consumed by an application, rather than on pre-purchased units of capacity.

(https://en.wikipedia.org/wiki/Serverless_computing)

Życie to sztuka wyboru

jedno bardzo, ale to bardzo ważne pytanie...

A komu to potrzebne? A dlaczego?

Zalety rozwiązań szytych na miarę

  • Niezależność od providera
  • Elastyczność
  • Koszty infrastruktury
  • Frajda ;)

Wady

  • Wyższe koszty utrzymania
  • Ryzyko większej awaryjności

Knative

  • Ogłoszone w lipcu 2018
  • aktualna wersja v0.6.0
  • Trzy główne komponenty -

    build, serving, eventing

  • Zarządzanie za pomocą CRD

Build

A Kubernetes-native Build resource.

kind: Build
metadata:
  name: example-build-name
spec:
  serviceAccountName: build-auth-example
  source:
    git:
      url: https://github.com/example/build-example.git
      revision: master
  steps:
  - name: ubuntu-example
    image: ubuntu
    args: ["ubuntu-build-example", "SECRETS-example.md"]
  

Kaniko

  • Narzędzie do budowania obrazów kontenerów
  • Zaprojektowane z myślą o użyciu wewnątrz Kubernetesa
  • Nie wymaga demona dockerowego

serving

 Kubernetes-based, scale-to-zero, request-driven compute

apiVersion: serving.knative.dev/v1alpha1
kind: Service
metadata:
  name: helloworld-java
  namespace: default
spec:
  runLatest:
    configuration:
      revisionTemplate:
        spec:
          container:
            image: docker.io/{username}/helloworld-java
            env:
            - name: TARGET
value: "Spring Boot Sample v1"

Eventing

 Open source specification and implementation of Knative event binding and delivery

Sources

  • AWS SQS
  • Cron Job
  • GCP PubSub
  • GitHub
  • GitLab
  • Google Cloud Scheduler
  • Google Cloud Storage
  • Kubernetes

apiVersion: sources.eventing.knative.dev/v1alpha1
kind: GitHubSource
metadata:
  name: githubsourcesample
spec:
  eventTypes:
  - pull_request
 (...)
  sink:
    apiVersion: serving.knative.dev/v1alpha1
    kind: Service
name: github-message-dumper

CLI

  • TriggerMesh
  • knctl

  • kn
  • gcloud beta run

gcloud beta run deploy --image gcr.io/$PROJECT/helloworld --cluster=standard-cluster-1