3.3 Create a Secret for Kafka Credentials

Earlier, we created a Kafka instance, along with multiple topics, but now need to connect to it. To do so, we’ll create a Secret that contains the credentials for our Kafka instance.

Create the Secret from YAML

  • From the Developer perspective, navigate to Secrets

  • Click Create and choose From YAML

alt text
  • Paste the following YAML into your secret

apiVersion: v1
kind: Secret
metadata:
  name: object-detection-kafka
  labels:
    app: object-detection
    app.kubernetes.io/component: object-detection
    app.kubernetes.io/instance: object-detection
    app.kubernetes.io/part-of: object-detection
data:
stringData:
  KAFKA_BOOTSTRAP_SERVER: <Enter your Kafka Bootstrap server>
  KAFKA_TOPIC_IMAGES: images
  KAFKA_TOPIC_OBJECTS: objects
  • Modify the values for KAFKA_BOOTSTRAP_SERVER to match your recorded information.

    • KAFKA_BOOTSTRAP_SERVER location of the Kafka bootstrap Server. e.g. "abc.xyz.kafka.rhcloud.com:443".

The KAFKA_BOOTSTRAP_SERVER will be the hostname of the object-detection brokers service of the Kafka instance.

alt text
  • Click Create to save your new secret.

alt text

Add the Secret to the Front-End Application

Now let’s add this information as environment variables to our deployed application.

  • Click Add Secret to workload

alt text
  • Select object-detection-app deployment as the workload.

  • Click Save

alt text

You’ll be redirected to you application. It will redeploy a new pod to pick up the changes.

  • Navigate to the Environment tab. There you can see the values have been added to your deployment.

alt text

Now that the front-end application can connect to Kafka, let’s create and connect a consumer in the next section.