開発者向け機能 - OpenShift Serverless

HOMEデベロッパー向け開発者向け機能OpenShift Serverless

OpenShift Serverless

“Event-driven サーバレス・コンテナ”

  • サーバレスコンテナのデプロイと実行
  • 任意のプログラミング言語とランタイムのサポート
  • 既存のアプリをサーバレスとしてモダナイズ
  • Powered by a rich ecosystem of event sources
  • Kubernetesネイティブ
  • OSSプロジェクト Knativeがベース
  • 任意のインフラ環境で実行可能

What is Knative ?

アプリケーション実行のためのKubernetesリソースを抽象化し、開発者がコードに集中することを可能とする

SERVING

ゼロスケール可能なイベントドリブンアプリケーションの実行機能

EVENTING

アプリケーション実行の契機となるイベント作成/管理のための共通基盤

Knative Serving

“Request-drivenによる実行とScale-to-zeroの仕組みを提供”

  • Knative Serviceの作成・削除に基づいてKubernetesのDeployment、Service、Routeを同期して管理
  • バージョン管理、トラフィックスプリットがビルトイン
  • オートスケール
    • 負荷がなければreplicas=0までスケールイン
    • スケールアウトはコネクション数に応じて素早く反応
  • 軽量なIngress gateway (Kourier)がリクエストの受付を代行 Automatic TLS/SSL
$ kn service create --
image=<container>

Kubernetes vs. Knative

Kubernetes : ~70 lines

apiVersion: apps/v1
kind: Deployment
metadata:
name: frontend
labels:
  app: guestbook
spec:
selector:
  matchLabels:
    app: guestbook
    tier: frontend
replicas: 1
template:
  metadata:
    labels:
      app: guestbook
      tier: frontend
  spec:
    containers:
    - image: markusthoemmes/guestbook
      name: guestbook
      resources:
        requests:
          cpu: 100m
          memory: 100Mi
      env:
      - name: GET_HOSTS_FROM
        value: dns
      ports:
      - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: frontend-service
labels:
  app: guestbook
  tier: frontend
spec:
ports:
- port: 80
selector:
  app: guestbook
  tier: frontend
---
apiVersion: route.openshift.io/v1
kind: Route
metadata:
name: frontend-route
spec:
to:
  kind: Service
  name: frontend-service

Knative : 22 lines

apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: frontend
spec:
template:
  metadata:
    labels:
      app: guestbook
      tier: frontend
  spec:
    containers:
    - image: markusthoemmes/guestbook
      resources:
        requests:
          cpu: 100m
          memory: 100Mi
      env:
      - name: GET_HOSTS_FROM
        value: dns
      ports:
      - containerPort: 80

Knative Eventing

“様々なイベントソースとKnative Serviceを仲介”

  • イベントソースごとに固有のカスタムリソースを作成
  • イベント発生時のあて先(sink)を設定
    • Source to Sink:sinkとしてKnative Serviceを設定
    • Channel and Subscribers Model:イベント情報の一時的な保管場所としてChannelを設定し、SubscriptionでChannelとServiceを結ぶ
    • Broker and Triggers Model:複数のKnative Serviceをあて先とする場合、イベント属性ごとにあて先を振り分ける
Source 概要
PingSource 定期的に固定的なメッセージを送信する
CronJobSource 定期的に固定的なメッセージを送信する(PingSourceと同じ)
ContainerSource 定期的にカスタムのイベントを送信するカスタムイメージをソースとして利用する
KafkaSource KafkaのTopicメッセージをソースとして利用する
ApiServerSource APIサーバから得られるKubernetesイベントをKnativeイベントとして利用する
CamelSource Camelがサポートする様々のEndpointコンポーネントをソースとして利用することにより、様々な外部プロトコルをイベントソースとして利用できる

Channel and Subscribers Model

apiVersion: messaging.knative.dev/v1beta1
kind: Channel
metadata:
 name: hello-channel

※デフォルトで作成されるChannelはInMemoryChannelだが、設定によりKafka等の実装に変更することが可能[1]

apiVersion: sources.knative.dev/v1alpha2
kind: PingSource
metadata:
 name: test-ping-source
spec:
 schedule: "*/2 * * * *"
 jsonData: '{"message": "Hello world!"}'
 sink:
   ref:
     apiVersion: messaging.knative.dev/v1
     kind: Channel
     name: hello-channel
apiVersion: messaging.knative.dev/v1beta1
kind: Subscription
metadata:
 name: hello-subscription
spec:
 channel:
   apiVersion: messaging.knative.dev/v1beta1
   kind: Channel
   name: hello-channel
 subscriber:
   ref:
     apiVersion: serving.knative.dev/v1
     kind: Service
     name: hello-service

[1]
Knative Available Channels, https://knative.dev/docs/eventing/channels/channels-crds/

選ぶなら業界をリードするコンテナプラットフォーム

OpenShiftならインフラ運用の効率化はもとよりアプリケーション開発者がソースコードの開発に専念できるように必要な機能までも提供してくれます