To expose Kafka port externally enable SSL/TLS configuration in Kafka.
- Build the image based on this Dockerfile
- Generate all keys and certificates based on gen.sh. Note Replace
<YOUR_KAFKA_DOMAIN_HERE>
and passphrase (i.e. test1234). - Create a secret based to store all certificates:
oc create secret generic kafka-ssl --from-file=/absolute/path/to/generated/certs/dir
- Update Kafka's Statefulset to enable SSL (statefulset.yml holds already patched version of our template):
- Configure Kafka brokers (Statefulset) to listen on SSL port:
# Add this to Statefulset/Deployment > containers > command # Remove advertised.host.name if already defined # Note KAFKA_ADVERTISED_HOST_NAME env is defined via downward API from podIP --override listeners=SSL://$KAFKA_ADVERTISED_HOST_NAME:9093
- Mount
kafka-ssl
secret to/var/private/ssl
path of Kafka's Statefulset. - Update containers > image to your newly built Kafka image. Note Replace
<YOUR_PROJECT_NAME_HERE>
instatefulset.yml
- Configure Kafka brokers (Statefulset) to listen on SSL port:
- Create/Update
kafka
service - Create a
passthrough
Route (e.g. kafka-ssl.abar.cloud) to point tokafka
Service port 9093. - Test the connection via Kafka's consumer / producer utilities. Use correct path for certificates. You may run these in one of
kafka-0/1/2
pods 'cause they already hold certificates in/var/private/ssl
dir:# Create client configuration file: cat >client-ssl.properties <<EOL bootstrap.servers=kafka-ssl.abar.cloud:443 security.protocol=SSL ssl.truststore.location=/var/private/ssl/kafka.client.truststore.jks ssl.truststore.password=test1234 ssl.keystore.location=/var/private/ssl/kafka.client.keystore.jks ssl.keystore.password=test1234 ssl.key.password=test1234 EOL # Run a producer and type something then press ENTER ./bin/kafka-console-producer.sh --broker-list kafka-ssl.abar.cloud:443 --topic test --producer.config client-ssl.properties # Since previous command is blocking you may run command below in a separate terminal session # You should see anything you type in producer session. ./bin/kafka-console-consumer.sh --bootstrap-server kafka-ssl.abar.cloud:443 --topic test --new-consumer --consumer.config client-ssl.properties --from-beginning