Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Knative Presentation from OSCON 2019 Portland, OR

Knative Presentation from OSCON 2019 Portland, OR

Knative is an open source serverless platform extending Kubernetes to help developers build, deploy, and manage modern serverless workloads. Whether you write functions or applications, Knative solves many of the common developer burdens like scaling, resource and route management, or logging and tracing without you needing to worry about the underlying infrastructure.

Mark Chmarny offers an overview of the Knative project, covering many of the common developer and operational patterns used to run real-world solutions. You’ll discover how easy it is to wire up your application and trigger your code using the vibrant ecosystem of multi cloud event sources. And because Knative is open, you can run it on any cloud or in your own data center where Kubernetes is offered.

Mark Chmarny

July 18, 2019
Tweet

More Decks by Mark Chmarny

Other Decks in Technology

Transcript

  1. Operator No Infra Management Managed Security Pay only for usage

    Service-based Event-driven Open Serverless Models Developer
  2. 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
  3. 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
  4. 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
  5. 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
  6. 55+ Contributing Companies >6K Pull Requests ~450 Individual Contributors 9

    Working Groups v0.7 Predictable Releases Knative Community
  7. Products Google Cloud Run Red Hat OpenShift SAP Kyma Google

    Cloud Run on GKE IBM Cloud Kubernetes Service TriggerMesh Build Tekton Serving Kubernetes Platform Primitives Events ... Knative Today
  8. 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 riff 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
  9. 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
  10. Confidential & Proprietary Config $: 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
  11. Benefits • Activates and scales based on request (up/down to

    0 pods) • Manages code/config revisions (updates, rollbacks, traffic splits) • Integrates service mesh (request path/services access control) • Custom domains and SSL cert support Knative Serving Integrations • Connect with other GCP services like Cloud Build and Stackdriver • Extend with partner integrations like GitLab and Datadog
  12. Deployment CLI release: github.com/knative/client kn service create service-name \ --image

    registry/image-name Result: service-name.namespace.domain.dev
  13. 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
  14. 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
  15. Knative Object Model Revision 1 Revision 2 Revision 3 Configuration

    Route Service Route - named endpoint and a mechanism for routing traffic Revisions - immutable snapshots of code + config Configuration - stream of environments for Revisions Service - top-level wrapper for managing Route/Configurations sets
  16. # 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
  17. 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
  18. 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
  19. ... traffic: - tag: current revisionName: bg-1 percent: 50 -

    tag: candidate revisionName: bg-2 percent: 50 - tag: latest latest Revision: true percent: 0 Blue/Green (traffic 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
  20. ... 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
  21. Usage Patterns Public Service • Website • API endpoint Internal

    Service • Backing Microservices • Eventing Targets • Mobile backend • Webhook
  22. 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 "."
  23. Request Path Demo Kubernetes Cluster Knative Frontend UI Logo Service

    User Service Vision API Firestore API User HTTP HTTP HTTPS HTTPS HTTPS demo OAuth
  24. 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
  25. 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
  26. # 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
  27. Knative Eventing Loosely coupled • Use existing event sources available

    or build your own • Plugable channel provisioners (e.g. PubSub. Kafka, NATS, 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 (CNCF Project)
  28. 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
  29. 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
  30. Namespace subscribe Trigger Service (Callable) Broker Trigger Service (Callable) subscribe

    filter= filter= Source Events Source Events ingress ingress publish ✓ ✓ ✓ Knative Eventing Objects
  31. 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
  32. 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
  33. 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
  34. 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
  35. Docs, Blog, Community knative.dev Quick Start bit.ly/cr-gke Anything else @mchmarny

    Source & Samples github.com/knative Questions? slack.knative.dev