How to expose a headless service for a StatefulSet externally in Kubernetes

后端 未结 6 1240
甜味超标
甜味超标 2020-12-12 16:03

Using kubernetes-kafka as a starting point with minikube.

This uses a StatefulSet and a headless service for service discovery within the cluster.

The goal i

6条回答
  •  一向
    一向 (楼主)
    2020-12-12 16:43

    From the kubernetes kafka documentation:

    Outside access with hostport

    An alternative is to use the hostport for the outside access. When using this only one kafka broker can run on each host, which is a good idea anyway.

    In order to switch to hostport the kafka advertise address needs to be switched to the ExternalIP or ExternalDNS name of the node running the broker. in kafka/10broker-config.yml switch to

    OUTSIDE_HOST=$(kubectl get node "$NODE_NAME" -o jsonpath='{.status.addresses[?(@.type=="ExternalIP")].address}')
    OUTSIDE_PORT=${OutsidePort}
    

    and in kafka/50kafka.yml add the hostport:

        - name: outside
          containerPort: 9094
          hostPort: 9094
    

提交回复
热议问题