I am unable to start a producer to write on a kafka topic. My kafka service has been deployed on k8s with strimzi. My k8s cluster has 2 nodes on google cloud service.
As I can see from the k8s config, all the services are on:
The kafka-cluster-kafka-external-bootstrap
is a service (nodeport
) for the communication with the kafka broker. Basically it forwards the requests from the external node to the internal broker service. Here some details:
Following the guide (which use minikube as cluster example) I extracted the nodes' ip:
kubectl get nodes --output=jsonpath='{range .items[*]}{.status.addresses[?(@.type=="ExternalIP")].address}{"\n"}{end}'
35.xxx.xxx.xxx
34.xxx.xxx.xxx
(the main difference with the guide here is that I am using "ExternalIP" instead of "InternalIP", because I am doing everything remotely)
Then I search for the port on which is exposed the service:
kubectl get service kafka-cluster-kafka-external-bootstrap -n xxxx-kafka -o=jsonpath='{.spec.ports[0].nodePort}{"\n"}'
30680
But when I try to start my producer, using a local bin of apache-kafka, I get this:
sh kafka-console-producer.sh --broker-list 35.xxx.xxx.xxx:30680 --topic test
>[2020-02-11 16:37:18,388] WARN [Producer clientId=console-producer] Connection to node -1 (/35.xxx.xxx.xxx:30680) could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient)
So I tried to ping the ip, to see if it is reachable:
ping 35.xxx.xxx.xxx
PING 35.xxx.xxx.xxx (35.xxx.xxx.xxx) 56(84) bytes of data.
64 bytes from 35.xxx.xxx.xxx: icmp_seq=1 ttl=54 time=63.4 ms
64 bytes from 35.xxx.xxx.xxx: icmp_seq=2 ttl=54 time=51.4 ms
It is reachable, but the port isn't:
telnet 35.xxx.xxx.xxx 30680
Trying 35.xxx.xxx.xxx...
telnet: Unable to connect to remote host: Connection timed out
This is my yaml configuration for the kafka cluster:
apiVersion: kafka.strimzi.io/v1beta1
kind: Kafka
metadata:
creationTimestamp: "2020-02-10T15:04:38Z"
generation: 1
name: kafka-cluster
namespace: xxxx-kafka
resourceVersion: "5868409"
selfLink: /apis/kafka.strimzi.io/v1beta1/namespaces/xxxx-kafka/kafkas/kafka-cluster
uid: 93d0d9b6-7c88-4e01-af9c-49f9fcaac1d1
spec:
entityOperator:
topicOperator: {}
userOperator: {}
kafka:
config:
offsets.topic.replication.factor: 1
transaction.state.log.min.isr: 1
transaction.state.log.replication.factor: 1
listeners:
external:
tls: false
type: nodeport
plain: {}
tls: {}
replicas: 1
storage:
type: jbod
volumes:
- deleteClaim: false
id: 0
size: 100Gi
type: persistent-claim
zookeeper:
replicas: 1
storage:
deleteClaim: false
size: 100Gi
type: persistent-claim
status:
conditions:
- lastTransitionTime: 2020-02-11T15:33:50+0000
status: "True"
type: Ready
listeners:
- addresses:
- host: kafka-cluster-kafka-bootstrap.xxxx-kafka.svc
port: 9092
type: plain
- addresses:
- host: kafka-cluster-kafka-bootstrap.xxxx-kafka.svc
port: 9093
type: tls
- addresses:
- host: <AnyNodeAddress>
port: 30680
type: external
observedGeneration: 1
Does anyone know why this problem occurs and how to run the producer properly?
EDIT:
this is the yaml of the kafka-cluster-kafka-bootstrap
apiVersion: v1
kind: Service
metadata:
creationTimestamp: "2020-02-11T15:31:57Z"
labels:
app.kubernetes.io/instance: kafka-cluster
app.kubernetes.io/managed-by: strimzi-cluster-operator
app.kubernetes.io/name: strimzi
strimzi.io/cluster: kafka-cluster
strimzi.io/kind: Kafka
strimzi.io/name: kafka-cluster-kafka-bootstrap
name: kafka-cluster-kafka-bootstrap
namespace: xxxx-kafka
ownerReferences:
- apiVersion: kafka.strimzi.io/v1beta1
blockOwnerDeletion: false
controller: false
kind: Kafka
name: kafka-cluster
uid: 93d0d9b6-7c88-4e01-af9c-49f9fcaac1d1
resourceVersion: "5867902"
selfLink: /api/v1/namespaces/xxxx-kafka/services/kafka-cluster-kafka-bootstrap
uid: 3dfdbd89-fc97-43d3-8e10-4f6a23eae20e
spec:
clusterIP: 10.0.2.111
ports:
- name: replication
port: 9091
protocol: TCP
targetPort: 9091
- name: clients
port: 9092
protocol: TCP
targetPort: 9092
- name: clientstls
port: 9093
protocol: TCP
targetPort: 9093
selector:
strimzi.io/cluster: kafka-cluster
strimzi.io/kind: Kafka
strimzi.io/name: kafka-cluster-kafka
sessionAffinity: None
type: ClusterIP
status:
loadBalancer: {}
I also tried to connect internally from the GCP node, but I get the same problem. I extracted the internal Ips:
kubectl get nodes --output=jsonpath='{range .items[*]}{.status.addresses[?(@.type=="InternalIP")].address}{"\n"}{end}'
10.132.0.4
10.132.0.5
Then I tried to connect the producer from the GCP node and this is what I got:
sh kafka-console-producer.sh --broker-list 10.132.0.4:30680 --topic test_topic
>hello
[2020-02-12 15:31:15,033] ERROR Error when sending message to topic test_topic with key: null, value: 4 bytes with error: (org.apache.kafka.clients.producer.internals.ErrorLoggingCallback)
org.apache.kafka.common.errors.TimeoutException: Topic test_topic not present in metadata after 60000 ms.
>[2020-02-12 15:32:24,629] WARN [Producer clientId=console-producer] Connection to node 0 (/34.xxx.xxx.xxx:30350) could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient)
Now, before getting the connection error I got also this one:
[2020-02-12 15:31:15,033] ERROR Error when sending message to topic test_topic with key: null, value: 4 bytes with error: (org.apache.kafka.clients.producer.internals.ErrorLoggingCallback)
org.apache.kafka.common.errors.TimeoutException: Topic test_topic not present in metadata after 60000 ms.
This is the kafka-cluster-kafka-brokers
yaml:
apiVersion: v1
kind: Service
metadata:
annotations:
service.alpha.kubernetes.io/tolerate-unready-endpoints: "true"
creationTimestamp: "2020-02-11T15:31:57Z"
labels:
app.kubernetes.io/instance: kafka-cluster
app.kubernetes.io/managed-by: strimzi-cluster-operator
app.kubernetes.io/name: strimzi
strimzi.io/cluster: kafka-cluster
strimzi.io/kind: Kafka
strimzi.io/name: kafka-cluster-kafka-brokers
name: kafka-cluster-kafka-brokers
namespace: xxxx-kafka
ownerReferences:
- apiVersion: kafka.strimzi.io/v1beta1
blockOwnerDeletion: false
controller: false
kind: Kafka
name: kafka-cluster
uid: 93d0d9b6-7c88-4e01-af9c-49f9fcaac1d1
resourceVersion: "5867905"
selfLink: /api/v1/namespaces/xxxx-kafka/services/kafka-cluster-kafka-brokers
uid: 42d7fa08-cf52-47e1-9746-89a45d65351b
spec:
clusterIP: None
ports:
- name: replication
port: 9091
protocol: TCP
targetPort: 9091
- name: clients
port: 9092
protocol: TCP
targetPort: 9092
- name: clientstls
port: 9093
protocol: TCP
targetPort: 9093
publishNotReadyAddresses: true
selector:
strimzi.io/cluster: kafka-cluster
strimzi.io/kind: Kafka
strimzi.io/name: kafka-cluster-kafka
sessionAffinity: None
type: ClusterIP
status:
loadBalancer: {}