Command [/usr/local/bin/dub path /var/lib/kafka/data writable] 在 Kafka 中执行失败!

huangapple go评论56阅读模式
英文:

Command [/usr/local/bin/dub path /var/lib/kafka/data writable] FAILED ! in Kafka

问题

我想在K8s集群中部署Kafka。我已经部署了一个Zookeeper,没有任何问题,但部署Kafka后它无法正常运行,卡在crashloopbackoff中。我检查了它的日志,以下是日志内容:

===> 用户 uid=1000(appuser) gid=1000(appuser)=1000(appuser)
===> 配置中...
===> 运行预检查...
===> 检查 /var/lib/kafka/data 是否可写...
命令 [/usr/local/bin/dub path /var/lib/kafka/data writable] 失败!

以下是我的部署文件:

kind: Deployment
apiVersion: apps/v1
metadata:
  name: kafka-broker0
spec:
  replicas: 2
  selector:
    matchLabels:
        app: kafka
        id: "0"
  template:
    metadata:
      labels:
        app: kafka
        id: "0"
    spec:
      containers:
      - name: kafka
        image: confluentinc/cp-kafka:6.2.2
        ports:
        - containerPort: 9092
        env:
        - name: KAFKA_ADVERTISED_LISTENERS
          value: PLAINTEXT://127.0.0.1:9092
        - name: KAFKA_ZOOKEEPER_CONNECT
          value: zoo1:2181
        - name: KAFKA_BROKER_ID
          value: "0"
        - name: KAFKA_CREATE_TOPICS
          value: input:1:1, output:1:1
        volumeMounts:
        - mountPath: /var/lib/kafka/data
          name: kafka-data
      volumes:
      - name: kafka-data
        persistentVolumeClaim:
          claimName: kafka-data

我发现了这个链接,但所有解决方案都是关于使用Docker部署,没有Kubernetes的解决方案。我也尝试添加 user: rootuser: "0:0",但找不到如何添加它的方法。

英文:

I want to deploy a kafka in k8s cluster.I have a zookeeper which is deploy without any issue but for deploying the kafka it doesnot become running and stuck in crashloopbackoff.I check it logs and here is its log:

===> User uid=1000(appuser) gid=1000(appuser) groups=1000(appuser)
===> Configuring ...
===> Running preflight checks ...
===> Check if /var/lib/kafka/data is writable ...
Command [/usr/local/bin/dub path /var/lib/kafka/data writable] FAILED !

And here is my deployment file :

kind: Deployment
apiVersion: apps/v1
metadata:
  name: kafka-broker0
spec:
  replicas: 2
  selector:
    matchLabels:
        app: kafka
        id: "0"
  template:
    metadata:
      labels:
        app: kafka
        id: "0"
    spec:
      containers:
      - name: kafka
        image: confluentinc/cp-kafka:6.2.2
        ports:
        - containerPort: 9092
        env:
        - name: KAFKA_ADVERTISED_LISTENERS
          value: PLAINTEXT://127.0.0.1:9092
        - name: KAFKA_ZOOKEEPER_CONNECT
          value: zoo1:2181
        - name: KAFKA_BROKER_ID
          value: "0"
        - name: KAFKA_CREATE_TOPICS
          value: input:1:1, output:1:1
        volumeMounts:
        - mountPath: /var/lib/kafka/data
          name: kafka-data
      volumes:
      - name: kafka-data
        persistentVolumeClaim:
          claimName: kafka-data

I find this link but in all sulotions the talk about deploy with docker and there isn't any solution for kubernetes.Also I try to add user: root or user: "0:0" but I couldn't find out how to add it.

答案1

得分: 1

I had the same problem and I found a way to do a similar thing to the link you are talking about but using Kubernetes.

In the pod configuration you can add:

spec:
      containers:
      - name: kafka
        image: confluentinc/cp-kafka:6.2.2
        securityContext:
          runAsUser: 0
          runAsGroup: 0

I'm not sure whether it's the proper solution but it should work.
In my case I cannot use it as a solution because my cluster configuration does not allow me to run the pod as root.

Perhaps you can try to set runAsUser: 1000 and runAsGroup: 1000. That's the ID I see when I run the image via docker. Although not sure if that's gonna work because I can see that the ID in your logs is the same.

==> User
uid=1000(appuser) gid=1000(appuser) groups=1000(appuser)
英文:

I had the same problem and I found a way to do a similar thing to the link you are talking about but using Kubernetes.

In the pod configuration you can add:

spec:
      containers:
      - name: kafka
        image: confluentinc/cp-kafka:6.2.2
        securityContext:
          runAsUser: 0
          runAsGroup: 0

I'm not sure whether it's the proper solution but it should work.
In my case I cannot use it as a solution because my cluster configuration does not allow me to run the pod as root.

Perhaps you can try to set runAsUser: 1000 and runAsGroup: 1000. That's the ID I see when I run the image via docker. Although not sure if that's gonna work because I can see that the ID in your logs is the same.

===> User
uid=1000(appuser) gid=1000(appuser) groups=1000(appuser)

huangapple
  • 本文由 发表于 2023年2月19日 19:32:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/75499821.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定