在minikube部署Kafka

lpwwtiir  于 2021-06-08  发布在  Kafka
关注(0)|答案(4)|浏览(870)

嗨,我是kubernets的新手,我正在使用minikube单节点集群进行本地开发和测试。

Host: Ubuntu 16.04 LTS.
Minikube: Virtual box running minikube cluster

我的要求是我需要在minikube上部署kafka和zookeeper,应该用来生成或消费消息。我遵循这个链接,并成功地部署在minikube它的详细信息如下

$ kubectl get services
NAME            CLUSTER-IP   EXTERNAL-IP   PORT(S)                      AGE
kafka-service   10.0.0.15    <pending>     9092:30244/TCP               46m
kubernetes      10.0.0.1     <none>        443/TCP                      53m
zoo1            10.0.0.43    <none>        2181/TCP,2888/TCP,3888/TCP   50m
zoo2            10.0.0.226   <none>        2181/TCP,2888/TCP,3888/TCP   50m
zoo3            10.0.0.6     <none>        2181/TCP,2888/TCP,3888/TCP   50m

$ kubectl get pods
NAME                                      READY     STATUS    RESTARTS   AGE
kafka-deployment-3583985961-f2301         1/1       Running   0          48m
zookeeper-deployment-1-1598963595-vgx1l   1/1       Running   0          52m
zookeeper-deployment-2-2038841231-tdsff   1/1       Running   0          52m
zookeeper-deployment-3-2478718867-5vjcj   1/1       Running   0          52m

$ kubectl describe service kafka-service
Name:           kafka-service
Namespace:      default
Labels:         app=kafka
Annotations:    <none>
Selector:       app=kafka
Type:           LoadBalancer
IP:             10.0.0.15
Port:           kafka-port  9092/TCP
NodePort:       kafka-port  30244/TCP
Endpoints:      172.17.0.7:9092
Session Affinity:   None
Events:         <none>

我已经将kafka\u播发的\u主机名设置为minikube ip(192.168.99.100)。现在我使用的消息生产者 $cat textfile.log | kafkacat -b $(minikube ip):30244 -t mytopic 它不发布下面给出的消息消息

% Auto-selecting Producer mode (use -P or -C to override)
% Delivery failed for message: Local: Message timed out

任何人都可以帮助如何发布和消费信息。

ryoqjall

ryoqjall1#

离开前面的答案和您的评论,这里是一个kafka服务的非常基本的示例代码 type=Nodeport .

apiVersion: v1
kind: Service
metadata:
  name: kafka-service
  labels:
    name: kafka
spec:
  ports:
  - port: 9092
    name: kafka-port
    protocol: TCP
  selector:
    app: kafka
  type: NodePort
wsxa1bj1

wsxa1bj12#

我遵循如下所示。

$ git clone https://github.com/d1egoaz/minikube-kafka-cluster

$ cd minikube-kafka-cluster

$ kubectl apply -f 00-namespace/

$ kubectl apply -f 01-zookeeper/

$ kubectl apply -f 02-kafka/

$ kubectl apply -f 03-yahoo-kafka-manager/

$ kubectl get svc -n kafka-ca1 (get the port of kafka manager like 31445)

$ minikube ip

放http://minikube-ip:在浏览器中输入端口以获取kafka manager的ui页。
来源https://technology.amis.nl/2019/03/24/running-apache-kafka-on-minikube/

pgpifvop

pgpifvop3#

我知道这是一篇很老的文章。你能在minikube解决并运行kafka+zookeeper吗?我能够使用minikubev0.17.1成功地运行一个简单的单集群kafka和zookeeper部署,并分别使用kafkacat producer和consumer生成和使用消息。我能够在ubuntu和macosx上成功运行这些程序。部署和服务YAML如下: zookeeper-deployment.ymlapiVersion: extensions/v1beta1 kind: Deployment metadata: labels: app: zookeeper name: zookeeper spec: replicas: 1 template: metadata: labels: app: zookeeper spec: containers: - image: wurstmeister/zookeeper imagePullPolicy: IfNotPresent name: zookeeper ports: - containerPort: 2181zookeeper-service.yml ```
apiVersion: v1
kind: Service
metadata:
labels:
app: zookeeper-service
name: zookeeper-service
spec:
type: NodePort
ports:

  • name: zookeeper-port
    port: 2181
    nodePort: 30181
    targetPort: 2181
    selector:
    app: zookeeper
    `kafka-deployment.yml`
    apiVersion: extensions/v1beta1
    kind: Deployment
    metadata:
    labels:
    app: kafka
    name: kafka
    spec:
    replicas: 1
    template:
    metadata:
    labels:
    app: kafka
    spec:
    containers:
    • env:
      • name: KAFKA_ADVERTISED_HOST_NAME
        value: "192.168.99.100"
      • name: KAFKA_ADVERTISED_PORT
        value: "30092"
      • name: KAFKA_BROKER_ID
        value: "1"
      • name: KAFKA_ZOOKEEPER_CONNECT
        value: 192.168.99.100:30181
      • name: KAFKA_CREATE_TOPICS
        value: "test-topic:1:1"
        image: wurstmeister/kafka
        imagePullPolicy: IfNotPresent
        name: kafka
        ports:
      • containerPort: 9092
        `kafka-service.yml`
        apiVersion: v1
        kind: Service
        metadata:
        labels:
        app: kafka-service
        name: kafka-service
        spec:
        type: NodePort
        ports:
  • name: kafka-port
    port: 9092
    nodePort: 30092
    targetPort: 9092
    selector:
    app: kafka
您可以通过安装kafkacat客户端并在不同的终端窗口上运行以下命令来测试部署:
echo "Am I receiving this message?" | kafkacat -P -b 192.168.99.100:30092 -t test-topic `kafkacat -C -b 192.168.99.100:30092 -t test-topic` % Reached end of topic test-topic [0] at offset 0 `Am I receiving this message?` 我能够在minikube版本v0.17.1和v0.19.0上成功运行这个。如果你想在minikube版本v0.21.1和v0.23.0上运行这个,请参考我的回复:kafka一旦进入kubernetes/minikube就无法访问
谢谢。
tpxzln5u

tpxzln5u4#

您使用了一个类型为loadbalancer的服务,该服务用于云提供程序(您可以看到该服务正在等待外部ip地址)。。挂起状态。。。这永远不会发生)。你应该试试nodeport。

相关问题