Share
Embed
Serverless on your own terms using Knative at Knative Meetup by AT&T in LAX
My "Serverless on your own terms" preso from the Knative meetup in LAX hosted by AT&T - Knative Meetup: Intersection of Kubernetes and Serverless; Present and Future.
https://www.meetup.com/Los-Angeles-Serverless-Meetup/events/258197851
Mark Chmarny
April 18, 2019
Transcript
33 slides
-
Serverless on your own terms using Knative Mark Chmarny Serverless
at Google @mchmarny -
Knative open source building blocks for serverless on Kubernetes [kay-native]
Kubernetes de facto standard for container orchestration -
Serverless Models Operational Model No Infra Management Pay only for
usage Programming Model Service-based Event-driven -
Serverless Models Operational Model No Infra Management Pay only for
usage Programming Model Service-based Event-driven Function Only? Not for Applications? What about Container? -
• Skills (idiomatic) • Tooling (dev & ops) • Investment
(“future-proofing”) Serverless Portability -
Products Google Cloud Run Red Hat OpenShift SAP Kyma Google
Cloud Run on GKE IBM Cloud Kubernetes Service TriggerMesh Build Serving Kubernetes Platform Primitives Events ... Knative-based products -
20% MoM Participation Growth >50 Companies contributing 3.7K Pull Requests
400+ Contributors 9 Working Groups v0.5 Released last week! Knative Community -
Knative Serving Benefits • Activates and scales based on request
(up/down to 0) • Manages code/config revisions • Integrates service mesh (request path/services access control) • Supports custom domains and certificate management Pluggable • Connect with other GCP services like Cloud Build and Stackdriver • Extend with partner integrations like GitLab and Datadog -
Knative Deploy (CLI & UI) knctl deploy -s maxprime \
-i gcr.io/knative-samples/maxprime:latest gcloud beta run deploy maxprime \ --image=gcr.io/knative-samples/klogo:@sha256:a8e… kubectl… kn… os… ibmcloud… … https://maxprime.demo.knative.tech -
# Load (from maxprime src dir) go run load/main.go --count
300 --prime 99999 \ --url https://maxprime.demo.knative.tech # Pods watch kubectl get pods -n demo -l serving.knative.dev/service=maxprime # Proxy (monitoring) kubectl port-forward -n knative-monitoring $(kubectl get pods -n knative-monitoring --selector=app=grafana --output=jsonpath="{.items..metadata.name}") 3000 # Monitor (in browser localhost:3000) http://localhost:3000/d/im_gFbWik/knative-serving-revision-http-requests?refresh=5s&org Id=1&var-namespace=demo&var-configuration=maxprime&var-revision=All Knative Scaling Demo -
# List current revisions in demo namespace (filter on service
name) kubectl get revisions -n demo -l serving.knative.dev/service=mysrv NAME SERVICE NAME GENERATION READY REASON mysrv-qtz5p mysrv-qtz5p-service 2 True mysrv-vq25k mysrv-vq25k-service 3 True # List routes for specific service kubectl get routes -n demo -l serving.knative.dev/service=mysrv NAME DOMAIN READY REASON mysrv mysrv.demo.knative.tech True # Edit service route to point to specific revision # (status/traffic[n]/revisionName) kubectl edit route mysrv -n demo Knative Revision Demo Revision 1 Revision 2 Revision 3 Configuration Route Service -
# github.com/mchmarny/klogo # see service.yaml#L6 apiVersion: serving.knative.dev/v1alpha1 kind: Service metadata:
name: klogo labels: serving.knative.dev/visibility: cluster-local ... # Demo before and after using Curl 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 "." Knative Request Path Demo K8s Knative Frontend UI (External) Microservice A (klogo - Internal) Microservice B (kuser - Internal) GRPC HTTP -
2 1 3 Knative Traffic Splitting Demo • Deploy new
revision • Create named route to new revision • Continue sending all traffic to original revision • Send progressively larger % of traffic to new revision • Monitor metrics/logs • Migrate all traffic to new revision • Create named route to previous revision Full demo walk-through: https://github.com/mchmarny/knative-demos/tree/master/blue-green-deploy Significant changes in v4 & v5, new/better approach coming: https://github.com/knative/serving/pull/3562 -
Knative Eventing Loosely coupled • Use existing event sources available
or build your own • Plugable channel implementation (e.g. PubSub. Kafka, In-Memory) Benefits • Orchestrates on/off cluster event sources • Binds declaratively event sources, triggers, and services • Scales from just few events to live streaming pipelines • Uses standard CloudEvents -
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 -
Namespace subscribe Trigger Service (Callable) Broker Trigger Service (Callable) subscribe
filter= filter= Source Events Source Events ingress ingress publish ✓ ✓ ✓ Knative Eventing Objects -
Knative Events { "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 Receive Adapter GitHub Receive Adapter GCS Receive Adapter CloudEvent -
Knative Event Trigger apiVersion: eventing.knative.dev/v1alpha1 kind: Trigger metadata: name: build-status-slack-notifier
spec: filter: sourceAndType: type: com.slack 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 -
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 - One per NS by default - Discoverable endpoint - Manages • Channels • Ingress filter/policy Twitter hashtag demo: https://github.com/mchmarny/knative-build-status-notifs -
Knative Eventing Demo # Twitter event source, trigger wired to
Knative service https://github.com/mchmarny/next19/blob/master/SVR305/DEMO-2.md # Source (config/source.yaml, query=KnativeDemo) kubectl apply -f source.yaml -n demo kubectl get sources -n demo # Trigger (config/trigger.yaml) kubectl apply -f trigger.yaml -n demo kubectl get triggers -n demo # UI app to display tweets github.com/mchmarny/tevents Twitter Viewer App Knative view Broker Trigger Twitter Event Source search ingress targetable -
# Cron job source to wire up functions github.com/knative/docs/tree/master/docs/eventing/samples/cronjob-source #
Process IoT Core events (through PubSub) https://github.com/knative/docs/tree/master/docs/eventing/samples/iot-core # GCP PubSub event source (connector to many other sources) github.com/knative/docs/tree/master/docs/eventing/samples/gcp-pubsub-source Knative Eventing Demos -
Knative Build Benefits • Reproducible builds • Enables source to
serving URL templates • No cross-compiling toil or need for Docker locally • Cloud caching, elasticity of build resources Loosely coupled • Supports decoupled CI/CD (e.g. Cloud Build or Jenkins X) • Ecosystem for enterprise tooling to manage policy and audit builds -
# On-cluster Build (Build Templates or github.com/tektoncd/pipeline) kubectl apply -f
build.yaml # GitOps (Cloud Build or your CI/CD platform like Jenkins X) git commit # on branch triggers build for test deployment git tag/release # triggers deployment pipeline to active service # Local Build & Deploy docker build/tag/publish # uses Dockerfile Kubectl/knctl deploy --image… # github.com/cppforlife/knctl # ko for quick iteration, no Dockerfile, golang only github.com/google/ko ko apply -f config.yaml Knative Build Options -
# On-cluster build using Service using kaniko template # github.com/mchmarny/maxprime/blob/master/deployments/clusterbuild.yaml
kubectl apply -f deployments/clusterbuild.yaml -n demo # Cloud Build triggered by revision tag with image deploy # Configuration file # github.com/mchmarny/maxprime/blob/master/deployments/cloudbuild.yaml # Demo by creating new release to trigger (release-v0.1.n+1) # github.com/mchmarny/maxprime/releases/new # On-cluster build, image deploy using JIB (dependency caching) # github.com/mchmarny/knative-demos/tree/master/jib-build kubectl apply -f deployments/clusterbuild.yaml -n demo Knative Build Demos -
Knative Events - IRL, not eventing ;) Google Cloud Next
(Last Week, videos available) Knative a Year Later: Serverless, Kubernetes and You bit.ly/kn-1yl Generating Events from Your Internal Systems with Knative bit.ly/kn-events KubeCon Barcelona (May 20, 2019) Serverless Practitioners Summit bit.ly/kn-barcelona -
Docs & Community knative.dev Quick Start bit.ly/cr-gke Source & Samples
github.com/knative Have questions? knative.slack.com Anything else? @mchmarny