fast-data-dev
fast-data-dev copied to clipboard
Exposing via minikube
Hello, I've been trying to setup the image to run inside a local minikube deployment but I'm not able to manage to access kafka from the host. It is not fully clear to me if I should use ADV_HOST or not, and which value should be published there. I tried it by setting the nodeIP (Virtual box machine), but in that case the broker connection fails even from internally.
Configuration for reference:
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: kafka
labels:
chart: kafka
system: kafka
type: messaging
component: kafka
spec:
replicas: 1
template:
metadata:
labels:
app: kafka
spec:
hostname: kafka-ms
containers:
- name: kafka-container
image: landoop/fast-data-dev
ports:
- containerPort: 9092
- containerPort: 3030
- containerPort: 2181
env:
- name: RUNTESTS
value: "0"
- name: SAMPLEDATA
value: "0"
# - name: ADV_HOST
# valueFrom:
# fieldRef:
# fieldPath: status.hostIP
apiVersion: v1
kind: Service
metadata:
name: kafka
labels:
chart: kafka
system: calypso
type: messaging
component: kafka
spec:
type: NodePort
ports:
- port: 3030
name: "web"
nodePort: 30001
- port: 9092
name: "messaging"
nodePort: 30002
- port: 2181
name: "zoo"
nodePort: 30003
selector:
app: kafka
Any inputs are appreciated.
Thanks
@rafaelnferreira if you want access to the fast data dev brokers from outside minikube you will need to expose the pod ip or set up ingress resources with nginx or traefik. Your service for selecting the brokers by label looks good for pods inside minikube.
I have to admit the image was not designed with k8s in mind.
The issue you hit comes from the way Kafka works. When the broker starts, it autodetects its address, usually as hostname:port
, for example kafka:9092
.
Now you expose this at the minikube host, port 30002, something like 192.168.99.100:30002
.
The way Kafka works, when your app connects to the broker (192.168.99.100:30002
), the brokers say hey, I am at kafka:9092
. So your client disconnects and tries to connect to this address.
A way to fix this, is to set ADV_HOST to your k8s host ip (is it 192.168.99.100
?) and set the nodePort same as the broker port (9092
). If you can't use 9092
, try to set the env variable BROKER_PORT
, e.g BROKER_PORT=30002
, though I am not sure how robust this (setting a custom port) will be.
A caveat is that now your broker says hey, I am at 192.168.99.100:30002
. So in order for Schema Registry, Connect and Kafka REST to work (all of them are kafka clients), they need to be able to access 192.168.99.100:30002
.