Questo contenuto non è disponibile nella lingua selezionata.

Chapter 15. Using ContainerSource with Service Mesh


You can use ContainerSource with Service Mesh.

15.1. Configuring ContainerSource with Service Mesh

This procedure describes how to configure container source with Service Mesh.

Prerequisites

  • You have set up integration of Service Mesh and Serverless.

Procedure

  1. Create a Service in a namespace that is member of the ServiceMeshMemberRoll:

    Example event-display-service.yaml configuration file

    apiVersion: serving.knative.dev/v1
    kind: Service
    metadata:
      name: event-display
      namespace: <namespace> 
    1
    
    spec:
      template:
        metadata:
          annotations:
            sidecar.istio.io/inject: "true" 
    2
    
            sidecar.istio.io/rewriteAppHTTPProbers: "true"
        spec:
          containers:
          - image: quay.io/openshift-knative/knative-eventing-sources-event-display:latest

    • namespace: <namespace>: A namespace that is a member of the ServiceMeshMemberRoll.
    • sidecar.istio.io/inject: "true": This annotation injects Service Mesh sidecars into the Knative service pods.
  2. Apply the Service resource by running the following command:

    $ oc apply -f event-display-service.yaml
  3. Create a ContainerSource object in a namespace that is member of the ServiceMeshMemberRoll and sink set to the event-display:

    The following example displayes test-heartbeats-containersource.yaml configuration file:

    apiVersion: sources.knative.dev/v1
    kind: ContainerSource
    metadata:
      name: test-heartbeats
      namespace: <namespace>
    spec:
      template:
        metadata:
          annotations:
            sidecar.istio.io/inject": "true"
            sidecar.istio.io/rewriteAppHTTPProbers: "true"
        spec:
          containers:
            # This corresponds to a heartbeats image URI that you have built and published
            - image: quay.io/openshift-knative/heartbeats
              name: heartbeats
              args:
                - --period=1s
              env:
                - name: POD_NAME
                  value: "example-pod"
                - name: POD_NAMESPACE
                  value: "event-test"
      sink:
        ref:
          apiVersion: serving.knative.dev/v1
          kind: Service
          name: event-display-service
    • namespace: <namespace>: A namespace that is part of the ServiceMeshMemberRoll.
    • metadata: These annotations enable Service Mesh integration with the ContainerSource object.
  4. Apply the ContainerSource resource by running the following command:

    $ oc apply -f test-heartbeats-containersource.yaml
  5. Optional: Verify that events reach the Knative event sink by checking the message dumper function logs:

    You get an output similar to the following example command:

    $ oc logs $(oc get pod -o name | grep event-display) -c user-container

    You get an output similar to the following example:

    ☁️  cloudevents.Event
    Validation: valid
    Context Attributes,
      specversion: 1.0
      type: dev.knative.eventing.samples.heartbeat
      source: https://knative.dev/eventing-contrib/cmd/heartbeats/#event-test/mypod
      id: 2b72d7bf-c38f-4a98-a433-608fbcdd2596
      time: 2019-10-18T15:23:20.809775386Z
      contenttype: application/json
    Extensions,
      beats: true
      heart: yes
      the: 42
    Data,
      {
        "id": 1,
        "label": ""
      }
Red Hat logoGithubredditYoutubeTwitter

Formazione

Prova, acquista e vendi

Community

Informazioni su Red Hat

Forniamo soluzioni consolidate che rendono più semplice per le aziende lavorare su piattaforme e ambienti diversi, dal datacenter centrale all'edge della rete.

Rendiamo l’open source più inclusivo

Red Hat si impegna a sostituire il linguaggio problematico nel codice, nella documentazione e nelle proprietà web. Per maggiori dettagli, visita il Blog di Red Hat.

Informazioni sulla documentazione di Red Hat

Legal Notice

Theme

© 2026 Red Hat
Torna in cima