A Kubernetes Init Container as a wait mechanism for Kafka availability and topic configuration.
This project serves as a means to block service startup until Kafka eventing and topic dependencies have been fulfilled.
The following example assumes the use of Helm (A Package manager for Kubernetes), however this is not a requirement and appropriate K8s manifests can be constructed without the use of Helm's templating functionality.
- A ConfigMap should be provided with the required Kafka Topics. For Example:
apiVersion: v1
kind: ConfigMap
metadata:
name: service-x-topics-config
data:
topics.yml: |
topics:
{{- range .Values.kafka.topics }}
- {{ . | quote }}
{{- end }}
- Topic entries should be supplied through
values.yaml
For Example:
...
kafka:
topics:
- notification-events
- request-events
- An
initContainers
entry should be added to the service Deployment PodSpec with avolumeMounts
entry specifying the associated ConfigMap. Environment variables can be provided in the Container spec, if omitted the default configuration fallbacks are used for Kafka host, port and version.
For Example:
spec:
initContainers:
- name: eventing-init
image: damiannolan/eventing-init:0.1.0
imagePullPolicy: Always
volumeMounts:
- name: topics-config
mountPath: /etc/config
...
volumes:
- name: topics-config
configMap:
name: sevice-x-topics-config