kafka k8s下镜像配置外部访问

kafka在k8s下最大的坑是访问通讯问题,折腾了4天,今早灵感来解决了

仓库地址https://github.com/liangguohun/dynamic-pvc.git
目录 elk\kafka

RC

核心在于/var/run/docker.sock 挂载 及使用status.hostIP 宿主机ip

apiVersion: v1
kind: ReplicationController
metadata:
  name: kafka-rc
spec:
  replicas: 1
  selector:
    name: kafka-pod
  template:
    metadata:
      labels: 
        name: kafka-pod
    spec:
#      hostNetwork: true
#      dnsPolicy: ClusterFirstWithHostNet
      hostAliases:
#      - ip: "192.168.1.5"
#        hostnames:
#        - "fuck.kafka"
      containers:
      - name: kafka
        image: 192.168.1.4:5000/liangguohun/kafka:1.0 
        imagePullPolicy: IfNotPresent
        env:
        - name: TZ
          value: Asia/Shanghai
        - name: KAFKA_ADVERTISED_HOST_NAME 
          valueFrom: 
            fieldRef: 
              fieldPath: status.hostIP
        - name: ZOOKEEPER_DATADIR
          value: "/workspace/data"
        ports:
        - name: kafka
          containerPort: 9092
        volumeMounts:
        - mountPath: /tmp/kafka-logs 
          name: log-data
        - mountPath: /var/app/config/server.properties 
          name: kafka-conf
          subPath: server.properties
        - mountPath: /var/run/docker.sock
          name: connect
      restartPolicy: "Always"
      volumes:
      - name: connect
        hostPath: 
          path: /var/run/docker.sock
      - name: log-data
        persistentVolumeClaim:
          claimName: kafka-claim
      - name: kafka-conf
        configMap:
          name: kafka-conf

SVC

之前一直通讯不ok最后发现是 selector cp 改的不匹配

apiVersion: v1
kind: Service
metadata:
  name: kafka
  labels:
    name: kafka
spec:
  type: NodePort
  ports:
    - name: kafka
      port: 9092
      targetPort: kafka
      nodePort: 9092
  selector:
    name: kafka-pod

server.properies

相应的属性 在此修改

broker.id=0
listeners=PLAINTEXT://:9092
listener.security.protocol.map=PLAINTEXT:PLAINTEXT
zookeeper.connect=192.168.1.4:2181
num.network.threads=3
num.io.threads=8
socket.send.buffer.bytes=102400
socket.receive.buffer.bytes=102400
socket.request.max.bytes=104857600
log.dirs=/tmp/kafka-logs
num.partitions=1
num.recovery.threads.per.data.dir=1
offsets.topic.replication.factor=1
transaction.state.log.replication.factor=1
transaction.state.log.min.isr=1
#log.flush.interval.messages=10000
#log.flush.interval.ms=1000
log.retention.hours=168
#log.retention.bytes=1073741824
log.segment.bytes=1073741824
log.retention.check.interval.ms=300000
zookeeper.connection.timeout.ms=6000
group.initial.rebalance.delay.ms=0

advertised.listeners
根据rc配置在env.sh 去掉注释的配置自动补上
dataDir 要与zk配置的路径匹配

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值