Serverless On Your Own Terms Using Knative Context Serverless more - - PowerPoint PPT Presentation

serverless on your own terms using knative context
SMART_READER_LITE
LIVE PREVIEW

Serverless On Your Own Terms Using Knative Context Serverless more - - PowerPoint PPT Presentation

Serverless at Google @mchmarny Serverless On Your Own Terms Using Knative Context Serverless more than Function Serverless Models Operator No Infra Management Managed Security Pay only for usage Developer Service-based Event-driven Open


slide-1
SLIDE 1

Serverless On Your Own Terms Using Knative

Serverless at Google

@mchmarny

slide-2
SLIDE 2

Context

slide-3
SLIDE 3

Serverless more than Function

slide-4
SLIDE 4

Operator

No Infra Management Managed Security Pay only for usage Service-based Event-driven Open

Serverless Models

Developer

slide-5
SLIDE 5

Serverless and Container

slide-6
SLIDE 6

Containers

  • Any Language
  • Any Library
  • Any Binary
  • Ecosystem of base images

.js .rb .go .py .sh …

0 1 0 1 0 0 1 1 1

slide-7
SLIDE 7

Serverless with Poruability

slide-8
SLIDE 8

Kubernetes

442 Years of efgoru*

5,500+ Contributors 55k+ GitHub stars

slide-9
SLIDE 9

Scheduling Lifecycle and health Naming and discovery Load balancing Storage volumes Logging and monitoring Identity and authorization

Platform over underlying infrastructure i.e. GKE

Kubernetes for operators

slide-10
SLIDE 10

Have to Build docker image locally Upload image to registry Deploy service Expose to the internet Setup logging & monitoring Scale workload...

Kubernetes for developers

Want to Write code

slide-11
SLIDE 11

Knative

slide-12
SLIDE 12

Knative

  • pen source building blocks

for serverless on Kubernetes

[kay-native]

slide-13
SLIDE 13

Developer-facing Products

Build Serving

Kubernetes

Events ...

Knative Primitives

slide-14
SLIDE 14

July 18

v0.1

Initial release Serving, Build Nov

v0.2

Pluggable networking, autoscaling, and caching Feb

v0.4

Upgradable configs Mounting Secrets GRPC, HTTP/2, WebSockets Jan 19

v0.3

Container resources spec Updated scale-to-zero strategy Cluster-local services Apr

v0.5

Expanded Event API GRPC streaming

Knative Momentum

May

v0.6

Serving Beta API Auto-TLS EventType CRD

v0.7

v1beta1 API HPA-based scaling Non-root containers July

slide-15
SLIDE 15

55+

Contributing Companies

>6K

Pull Requests

~450

Individual Contributors

9

Working Groups

v0.7

Predictable Releases

Knative Community

slide-16
SLIDE 16

Products

Google Cloud Run Red Hat OpenShifu SAP Kyma Google Cloud Run on GKE IBM Cloud Kubernetes Service TriggerMesh

Build Tekton Serving

Kubernetes Platform Primitives

Events ...

Knative Today

slide-17
SLIDE 17

Knative Install

slide-18
SLIDE 18

Confidential & Proprietary

Knative Stack

Build Serving

Kubernetes Platform Products Primitives

Events ...

Serverless Containers on GCF GKE Serverless Add-on SAP Kyma Pivotal Function Service IBM Cloud Functions Red Hat Cloud Functions Pivotal rifg OpenFaaS T-mobile Jazz

Istio Service Mesh

Latest releases: https://knative.dev/docs/install/ $ kubectl apply \

  • f https://github.com/knative/serving/releases/.../serving.yaml \
  • f https://github.com/knative/eventing/releases/.../eventing.yaml \
  • f https://github.com/knative/monitoring/releases/.../monitoring.yaml \
  • f https://github.com/knative/build/releases/.../build.yaml

Optionally apply individual event sources and channel provisioners

Install

slide-19
SLIDE 19

Confidential & Proprietary

Install

$ gcloud beta container \ clusters create my-cluster \

  • -addons=Istio,CloudRun

Quick Start on GCP: bit.ly/cr-gke Also available for:

  • AKS
  • Docker
  • Gardener
  • IKS
  • Minikube
  • OpenShift/Minishift
  • PCS
slide-20
SLIDE 20

Confidential & Proprietary

Confjg

$: kubectl get ns NAME STATUS default Active istio-system Active knative-build Active knative-eventing Active knative-monitoring Active knative-serving Active knative-sources Active kube-public Active kube-system Active $: kubectl get cm -n knative-serving NAME DATA config-autoscaler 1 config-defaults 1 config-deployment 2 config-domain 1 config-gc 1 config-istio 1 config-logging 1 config-network 6 config-observability 1 config-tracing 1

slide-21
SLIDE 21

Knative Features

slide-22
SLIDE 22

Benefjts

  • Activates and scales based on

request (up/down to 0 pods)

  • Manages code/confjg revisions

(updates, rollbacks, traffjc splits)

  • Integrates service mesh

(request path/services access control)

  • Custom domains and

SSL ceru supporu

Knative Serving

Integrations

  • Connect with other GCP

services like Cloud Build and Stackdriver

  • Extend with paruner

integrations like GitLab and Datadog

slide-23
SLIDE 23

Deployment

CLI release: github.com/knative/client

kn service create service-name \

  • -image registry/image-name

Result: service-name.namespace.domain.dev

slide-24
SLIDE 24

Deployment

kubectl apply -f service.yaml # service.yaml apiVersion: serving.knative.dev/v1beta1 kind: Service metadata: name: service-name spec: template: spec: containers:

  • image: registry/image-name
slide-25
SLIDE 25

Deployment

gcloud beta run deploy service-name \

  • -image=gcr.io/project/image-name

Other CLIs: knctl, os, ibmcloud

slide-26
SLIDE 26

Autoscaling

slide-27
SLIDE 27

GitOps using Cloud Build, GitLab, Jenkins (e.g. branch or release triggers) github.com/mchmarny/maxprime/blob/master/deployments/cloudbuild.yaml Local Build uses Dockerfile, deploy using gcloud docker build/tag/publish gcloud beta run deploy app --image=gcr.io/project/image On-cluster Build (Build Templates or github.com/tektoncd/pipeline) kubectl apply -f build.yaml ko for quick iteration, no Dockerfile (golang only) github.com/google/ko ko apply -f config.yaml

Deployment Options

slide-28
SLIDE 28

Day 2+

Service v2 v1

slide-29
SLIDE 29

Knative Object Model

Revision 1 Revision 2 Revision 3

Configuration Route

Service

Route - named endpoint and a mechanism for routing traffjc Revisions - immutable snapshots

  • f code + confjg

Confjguration - stream of environments for Revisions Service - top-level wrapper for managing Route/Confjgurations sets

slide-30
SLIDE 30

# List current revisions in demo namespace (filter on service name) kubectl get revisions -n demo -l serving.knative.dev/service=maxprime NAME SERVICE NAME GENERATION READY maxprime-vq25k maxprime-vq25k-service 3 True maxprime-wtz1g maxprime-wtz1g-service 2 True maxprime-qtz5p maxprime-qtz5p-service 1 True # Edit revision in service traffic section # (status/traffic[n]/revisionName) kubectl edit ksvc maxprime -n demo

Simple Revision Management

slide-31
SLIDE 31

apiVersion: serving.knative.dev/v1beta1 kind: Service metadata: name: bg namespace: demo spec: template: spec: containers:

  • image: gcr.io/knative-samples/knative-route-demo:blue

Blue/Green (deployment)

Service 100% Revision

github.com/mchmarny/knative-demos/tree/master/blue-green-deploy

slide-32
SLIDE 32

spec: template: metadata: name: bg-2 ... traffic:

  • tag: current

revisionName: bg-1 percent: 100

  • tag: candidate

revisionName: bg-2 percent: 0

  • tag: latest

latest Revision: true percent: 0

Blue/Green (update)

Service Revision (bg-2) Revision (bg-1) 0% - bg-candidate.demo.knative.tech 100% - bg.demo.knative.tech

github.com/mchmarny/knative-demos/tree/master/blue-green-deploy

slide-33
SLIDE 33

... traffic:

  • tag: current

revisionName: bg-1 percent: 50

  • tag: candidate

revisionName: bg-2 percent: 50

  • tag: latest

latest Revision: true percent: 0

Blue/Green (traffjc split)

Service Revision (bg-1) Revision (bg-2)

90%

80%

70%

60%

50% 40%

60%

50%

40%

30%

20%

10%

github.com/mchmarny/knative-demos/tree/master/blue-green-deploy

slide-34
SLIDE 34

... traffic:

  • tag: previous

revisionName: bg-1 percent: 100

  • tag: current

revisionName: bg-2 percent: 0

  • tag: latest

latestRevision: true percent: 0

Blue/Green (rollback)

Service Revision (bg-1) Revision (bg-2)

100% 0%

github.com/mchmarny/knative-demos/tree/master/blue-green-deploy

slide-35
SLIDE 35

Usage Patuerns

Public Service

  • Website
  • API endpoint

Internal Service

  • Backing Microservices
  • Eventing Targets
  • Mobile backend
  • Webhook
slide-36
SLIDE 36

Request Path Demo

Kubernetes Cluster Knative Logo Service Vision API

User

HTTPS HTTPS

curl -H "Content-Type: application/json" \

  • d '{"id":"test","url":"https://storage.googleapis.com/kdemo-logos/k8s.png"}' \
  • X POST https://klogo.demo.knative.tech/ | jq "."
slide-37
SLIDE 37

Request Path Demo

Kubernetes Cluster Knative Frontend UI Logo Service User Service Vision API Firestore API

User

HTTP HTTP HTTPS HTTPS HTTPS

demo

OAuth

slide-38
SLIDE 38

Request Path Demo

Kubernetes Cluster Knative Frontend UI Logo Service User Service Vision API Firestore API

User

HTTP HTTP HTTPS HTTPS HTTPS

github.com/mchmarny/kdemo

OAuth

slide-39
SLIDE 39

Request Path Demo

Kubernetes Cluster Knative Frontend UI (external) Logo Service (cluster-local) User Service (cluster-local) Vision API Firestore API

User

HTTP HTTP HTTPS HTTPS HTTPS

github.com/mchmarny/kdemo

OAuth

slide-40
SLIDE 40

# github.com/mchmarny/klogo # service.yaml apiVersion: serving.knative.dev/v1alpha1 kind: Service metadata: name: klogo labels: serving.knative.dev/visibility: cluster-local ...

Request Path

github.com/mchmarny/kdemo

slide-41
SLIDE 41

Knative Eventing

Loosely coupled

  • Use existing event sources

available or build your own

  • Plugable channel

provisioners (e.g. PubSub. Kafla, NATS, In-Memory)

Benefjts

  • Orchestrates on/ofg cluster

event sources

  • Binds declaratively event

sources, triggers, and services

  • Scales from just few events to

live streaming pipelines

  • Uses standard CloudEvents

(CNCF Project)

slide-42
SLIDE 42

Name Description

Apache Camel Allows to use Apache Camel components for pushing events into Knative Apache Kafka Brings Apache Kafka messages into Knative AWS SQS Brings AWS Simple Queue Service messages into Knative Cron Job Uses an in-memory timer to produce events on the specified Cron schedule. GCP PubSub Brings GCP PubSub messages into Knative GitHub Brings GitHub organization/repository events into Knative GitLab Brings GitLab repository events into Knative. Google Cloud Scheduler Google Cloud Scheduler events in Knative when jobs are triggered Google Cloud Storage Brings Google Cloud Storage bucket/object events into Knative Kubernetes Brings Kubernetes cluster/infrastructure events into Knative

Full lists: https://github.com/knative/docs/tree/master/docs/eventing/sources

Knative Event Sources

slide-43
SLIDE 43

Knative Event Broker

apiVersion: eventing.knative.dev/v1alpha1 kind: Broker metadata: name: b1 namespace: demo spec: {} status: address: hostname: b1-broker.demo.svc.cluster.local

Simple Broker

  • 1-n per NS by default
  • Discoverable endpoint
  • Manages
  • Channels
  • Ingress filter/policy
slide-44
SLIDE 44

Namespace subscribe

Trigger Service

(Callable)

Broker Trigger Service

(Callable) subscribe filter= filter=

Source

Events

Source

Events ingress ingress publish

✓ ✓ ✓

Knative Eventing Objects

slide-45
SLIDE 45

CloudEvents

{ "specversion": "0.2", "type": "com.github.pull.create", "source": "https://github.com/cloudevents/spec/pull/123", "id": "A234-1234-1234", "time": "2019-04-08T17:31:00Z", "datacontenttype": "application/json", "data": "{ GitHub Payload... }" }

FTP GitHub GCS

Broker

FTP Event Source GitHub Event Source GCS Event Source

CloudEvent

slide-46
SLIDE 46

Knative Event Trigger

apiVersion: eventing.knative.dev/v1alpha1 kind: Trigger metadata: name: build-status-slack-notifier spec: filter: sourceAndType: type: com.google.build.status subscriber: ref: apiVersion: serving.knative.dev/v1alpha1 kind: Service name: slack-sender

Simple Trigger

  • Uses CloudEvents
  • Supports Filtering
  • Can produce new events

Build status Slack notifications demo: https://github.com/mchmarny/knative-build-status-notifs

slide-47
SLIDE 47

Knative Eventing Demo

Twitter

Event Source

query:knative

type:com.twitter

Broker (default)

Trigger type filter: com.twitter .negative

Slack Publishing Service

Slack Channel (#twitterback)

Trigger type filter: com.twitter

Sentiment Scoring Service

Trigger type filter: com.twitter

Event Store Service

FireStore Collection (knative-tweets )

Trigger type filter: com.twitter. positive

Event Viewer (WebSocket)

  • 1. Save all tweets

for reference

  • 2. Classify tweets

based on sentiment

  • 3. Send negative to

Slack for review

  • 4. Display positive

tweets in UI

1 2 3 4 com.twitter.negative com.twitter.positive

bit.ly/kn-tw-event

slide-48
SLIDE 48

bit.ly/kn-event-samples

* Cron job source to wire up weekly report * Process IoT Core events (through PubSub) * GCP PubSub (connector to many other GCP event sources) * Actuate on Kubernetes events * GitHub Webhooks processing ...

Knative Eventing Demos

slide-49
SLIDE 49

In Closing

Infrastructure Primitives Knative Kubernetes

Knative-based Products

Optimized Experience

slide-50
SLIDE 50

Docs, Blog, Community knative.dev Quick Staru bit.ly/cr-gke Anything else @mchmarny Source & Samples github.com/knative Questions? slack.knative.dev

slide-51
SLIDE 51

Rate today's session, please

Session page on conference website O’Reilly Events App