Serverless On Your Own Terms Using Knative
Serverless at Google
@mchmarny
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
Serverless at Google
@mchmarny
Operator
No Infra Management Managed Security Pay only for usage Service-based Event-driven Open
Developer
.js .rb .go .py .sh …
0 1 0 1 0 0 1 1 1
Scheduling Lifecycle and health Naming and discovery Load balancing Storage volumes Logging and monitoring Identity and authorization
Platform over underlying infrastructure i.e. GKE
Have to Build docker image locally Upload image to registry Deploy service Expose to the internet Setup logging & monitoring Scale workload...
Want to Write code
[kay-native]
Developer-facing Products
Build Serving
Kubernetes
Events ...
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
May
v0.6
Serving Beta API Auto-TLS EventType CRD
v0.7
v1beta1 API HPA-based scaling Non-root containers July
Contributing Companies
Pull Requests
Individual Contributors
Working Groups
Predictable Releases
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 ...
Confidential & Proprietary
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 \
Optionally apply individual event sources and channel provisioners
Confidential & Proprietary
$ gcloud beta container \ clusters create my-cluster \
Quick Start on GCP: bit.ly/cr-gke Also available for:
Confidential & Proprietary
$: 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
Benefjts
request (up/down to 0 pods)
(updates, rollbacks, traffjc splits)
(request path/services access control)
SSL ceru supporu
Integrations
services like Cloud Build and Stackdriver
integrations like GitLab and Datadog
kubectl apply -f service.yaml # service.yaml apiVersion: serving.knative.dev/v1beta1 kind: Service metadata: name: service-name spec: template: spec: containers:
gcloud beta run deploy service-name \
Other CLIs: knctl, os, ibmcloud
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
Revision 1 Revision 2 Revision 3
Configuration Route
Service
Route - named endpoint and a mechanism for routing traffjc Revisions - immutable snapshots
Confjguration - stream of environments for Revisions Service - top-level wrapper for managing Route/Confjgurations sets
# 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
apiVersion: serving.knative.dev/v1beta1 kind: Service metadata: name: bg namespace: demo spec: template: spec: containers:
Service 100% Revision
github.com/mchmarny/knative-demos/tree/master/blue-green-deploy
spec: template: metadata: name: bg-2 ... traffic:
revisionName: bg-1 percent: 100
revisionName: bg-2 percent: 0
latest Revision: true percent: 0
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
... traffic:
revisionName: bg-1 percent: 50
revisionName: bg-2 percent: 50
latest Revision: true percent: 0
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
... traffic:
revisionName: bg-1 percent: 100
revisionName: bg-2 percent: 0
latestRevision: true percent: 0
Service Revision (bg-1) Revision (bg-2)
100% 0%
github.com/mchmarny/knative-demos/tree/master/blue-green-deploy
Public Service
Internal Service
Kubernetes Cluster Knative Logo Service Vision API
User
HTTPS HTTPS
curl -H "Content-Type: application/json" \
Kubernetes Cluster Knative Frontend UI Logo Service User Service Vision API Firestore API
User
HTTP HTTP HTTPS HTTPS HTTPS
demo
OAuth
Kubernetes Cluster Knative Frontend UI Logo Service User Service Vision API Firestore API
User
HTTP HTTP HTTPS HTTPS HTTPS
github.com/mchmarny/kdemo
OAuth
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
# github.com/mchmarny/klogo # service.yaml apiVersion: serving.knative.dev/v1alpha1 kind: Service metadata: name: klogo labels: serving.knative.dev/visibility: cluster-local ...
github.com/mchmarny/kdemo
Loosely coupled
available or build your own
provisioners (e.g. PubSub. Kafla, NATS, In-Memory)
Benefjts
event sources
sources, triggers, and services
live streaming pipelines
(CNCF Project)
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
apiVersion: eventing.knative.dev/v1alpha1 kind: Broker metadata: name: b1 namespace: demo spec: {} status: address: hostname: b1-broker.demo.svc.cluster.local
Simple Broker
Namespace subscribe
Trigger Service
(Callable)
Broker Trigger Service
(Callable) subscribe filter= filter=
Source
Events
Source
Events ingress ingress publish
✓ ✓ ✓
{ "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
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
Build status Slack notifications demo: https://github.com/mchmarny/knative-build-status-notifs
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)
for reference
based on sentiment
Slack for review
tweets in UI
1 2 3 4 com.twitter.negative com.twitter.positive
bit.ly/kn-tw-event
* 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 ...
Infrastructure Primitives Knative Kubernetes
Knative-based Products
Optimized Experience
Docs, Blog, Community knative.dev Quick Staru bit.ly/cr-gke Anything else @mchmarny Source & Samples github.com/knative Questions? slack.knative.dev
Session page on conference website O’Reilly Events App