How to connect to a kafka instance in a kubernetes cluster?

3/9/2019

I just used rancher to deploy a kubernetes cluster and deployed kafka using rancher's cloud apps (If I'm correct, it's using helm charts to do this). Unfortunately, I'm unable to connect to it from outside. I just created an ingress pointing to the kafka-dtxkf-kafka service on port 9092. But still, it won't connect.

My cluster is as follows:

NAME                                               READY     STATUS    RESTARTS   AGE
pod/kafka-dtxkf-kafka-0                            1/1       Running   0          13m
pod/kafka-dtxkf-kafka-1                            1/1       Running   0          13m
pod/kafka-dtxkf-kafka-2                            1/1       Running   1          13m
pod/kafka-dtxkf-kafka-rest-85d899545f-jzq4g        1/1       Running   1          13m
pod/kafka-dtxkf-kafka-topics-ui-654d9c455d-pw74m   1/1       Running   0          13m
pod/kafka-dtxkf-schema-registry-6c54bdf8c4-ktjkg   1/1       Running   5          13m
pod/kafka-dtxkf-zookeeper-0                        1/1       Running   0          13m
pod/kafka-dtxkf-zookeeper-1                        1/1       Running   0          13m
pod/kafka-dtxkf-zookeeper-2                        1/1       Running   0          13m

NAME                                               TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)                      AGE
service/ingress-aef7dfa8ffc7dc6099c8c10a74d8e962   ClusterIP   10.43.219.128   <none>        9092/TCP                     3m
service/kafka-dtxkf-kafka                          ClusterIP   10.43.241.160   <none>        9092/TCP                     13m
service/kafka-dtxkf-kafka-headless                 ClusterIP   None            <none>        9092/TCP                     13m
service/kafka-dtxkf-kafka-rest                     ClusterIP   10.43.134.186   <none>        8082/TCP                     13m
service/kafka-dtxkf-kafka-topics-ui                NodePort    10.43.210.62    <none>        8000:31547/TCP               13m
service/kafka-dtxkf-schema-registry                ClusterIP   10.43.101.213   <none>        8081/TCP                     13m
service/kafka-dtxkf-zookeeper                      ClusterIP   10.43.242.136   <none>        2181/TCP                     13m
service/kafka-dtxkf-zookeeper-headless             ClusterIP   None            <none>        2181/TCP,2888/TCP,3888/TCP   13m
service/kubernetes                                 ClusterIP   10.43.0.1       <none>        443/TCP                      1d

NAME                                          DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/kafka-dtxkf-kafka-rest        1         1         1            1           13m
deployment.apps/kafka-dtxkf-kafka-topics-ui   1         1         1            1           13m
deployment.apps/kafka-dtxkf-schema-registry   1         1         1            1           13m

NAME                                                     DESIRED   CURRENT   READY     AGE
replicaset.apps/kafka-dtxkf-kafka-rest-85d899545f        1         1         1         13m
replicaset.apps/kafka-dtxkf-kafka-topics-ui-654d9c455d   1         1         1         13m
replicaset.apps/kafka-dtxkf-schema-registry-6c54bdf8c4   1         1         1         13m

NAME                                     DESIRED   CURRENT   AGE
statefulset.apps/kafka-dtxkf-kafka       3         3         13m
statefulset.apps/kafka-dtxkf-zookeeper   3         3         13m

My ingress configuration:

enter image description here

kubectl describe service/ingress-aef7dfa8ffc7dc6099c8c10a74d8e962:

    Name:              ingress-aef7dfa8ffc7dc6099c8c10a74d8e962
    Namespace:         default
    Labels:            cattle.io/creator=norman
    Annotations:       field.cattle.io/targetWorkloadIds=["statefulset:default:kafka-dtxkf-kafka"]
    Selector:          workloadID_ingress-aef7dfa8ffc7dc6099c8c10a74d8e962=true
    Type:              ClusterIP
    IP:                10.43.219.128
    Port:              <unset>  9092/TCP
    TargetPort:        9092/TCP
    Endpoints:         10.42.0.111:9092,10.42.1.83:9092,10.42.1.84:9092
    Session Affinity:  None
    Events:            <none>
-- THpubs
apache-kafka
kubernetes
rancher

1 Answer

3/19/2019

I think that Load balancer export only http/https traffic, for kafka you can use tcp-service https://github.com/rancher/rancher/issues/14744

-- Negash
Source: StackOverflow