// Module included in the following assemblies:
//
// * serverless/develop/serverless-kafka-developer.adoc

:_mod-docs-content-type: PROCEDURE
[id="serverless-kafka-sink_{context}"]
= Creating an Apache Kafka sink by using YAML

You can create a Kafka sink that sends events to a Kafka topic. By default, a Kafka sink uses the binary content mode, which is more efficient than the structured mode. To create a Kafka sink by using YAML, you must create a YAML file that defines a `KafkaSink` object, then apply it by using the `oc apply` command.

.Prerequisites

* The {ServerlessOperatorName}, Knative Eventing, and the `KnativeKafka` custom resource (CR) are installed on your cluster.
* You have created a project or have access to a project with the appropriate roles and permissions to create applications and other workloads in {product-title}.
* You have access to a Red Hat AMQ Streams (Kafka) cluster that produces the Kafka messages you want to import.
* Install the OpenShift CLI (`oc`).

.Procedure

. Create a `KafkaSink` object definition as a YAML file:
+
.Kafka sink YAML
[source,yaml]
----
apiVersion: eventing.knative.dev/v1alpha1
kind: KafkaSink
metadata:
  name: <sink-name>
  namespace: <namespace>
spec:
  topic: <topic-name>
  bootstrapServers:
   - <bootstrap-server>
----

. To create the Kafka sink, apply the `KafkaSink` YAML file:
+
[source,terminal]
----
$ oc apply -f <filename>
----

. Configure an event source so that the sink is specified in its spec:
+
.Example of a Kafka sink connected to an API server source
[source,yaml]
----
apiVersion: sources.knative.dev/v1alpha2
kind: ApiServerSource
metadata:
  name: <source-name> <1>
  namespace: <namespace> <2>
spec:
  serviceAccountName: <service-account-name> <3>
  mode: Resource
  resources:
  - apiVersion: v1
    kind: Event
  sink:
    ref:
      apiVersion: eventing.knative.dev/v1alpha1
      kind: KafkaSink
      name: <sink-name> <4>
----
<1> The name of the event source.
<2> The namespace of the event source.
<3> The service account for the event source.
<4> The Kafka sink name.
