day18 : kafka服务应用 on K8S (下)

昨天介绍了kafka的机制,今天将会透过strimzi的方式配置kafka cluster,同样的会介绍用operator的方式进行布署,strimzi可以管理kafka的丛集、user、topic跟bridge连线,那麽就来尝试玩看看吧。

首先创建一个kafka的namespaces

kubectl create ns strimzi
#下载yaml 
wget https://strimzi.io/install/latest?namespace=strimzi
kubectl apply -f yaml -n strimzi

https://ithelp.ithome.com.tw/upload/images/20210918/20139661QucwtDWO9h.png
完成crd後就可以创建kafka cluster的instance罗

apiVersion: kafka.strimzi.io/v1beta2
kind: Kafka
metadata:
  name: lab1-kafka
spec:
  kafka:
    version: 2.8.0
    replicas: 1
    listeners:
      - name: plain
        port: 9092
        type: internal
        tls: false
      - name: tls
        port: 9093
        type: internal
        tls: true
    config:
      offsets.topic.replication.factor: 1
      transaction.state.log.replication.factor: 1
      transaction.state.log.min.isr: 1
      log.message.format.version: "2.8"
      inter.broker.protocol.version: "2.8"
    storage:
      type: jbod
      volumes:
      - id: 0
        type: persistent-claim
        size: 20Gi
        deleteClaim: false
    template:
      pod:
        securityContext:
          runAsUser: 0
          fsGroup: 0
  zookeeper:
    replicas: 1
    storage:
      type: persistent-claim
      size: 20Gi
      deleteClaim: false
    template:
      pod:
        securityContext:
          runAsUser: 0
          fsGroup: 0
  entityOperator:
    topicOperator: {}
    userOperator: {}

https://ithelp.ithome.com.tw/upload/images/20210918/20139661n61N60nvU1.png
这样就会建出kafka罗,那就来使用看看吧

kubectl -n strimzi run kafka-producer -ti --image=quay.io/strimzi/kafka:0.25.0-kafka-2.8.0 --rm=true --restart=Never -- bin/kafka-console-producer.sh --broker-list my-cluster-kafka-bootstrap:9092 --topic my-topic

https://ithelp.ithome.com.tw/upload/images/20210918/20139661oFglrmu06j.png

kubectl -n strimzi run kafka-consumer-2 -ti --image=quay.io/strimzi/kafka:0.25.0-kafka-2.8.0 --rm=true --restart=Never -- bin/kafka-console-consumer.sh --bootstrap-server my-cluster-kafka-bootstrap:9092 --topic my-topic --from-beginning

https://ithelp.ithome.com.tw/upload/images/20210918/20139661kkKVKRKIdo.png

看起来没什麽问题呢,那麽要从外部使用kafka的话,strimzi有开发kafka-bridge让外部使用http或是amqp的方式连线进去使用kafka,而topic也可以用crd进行控管。


<<:  [Angular] Day18. Introduction to services and dependency injection

>>:  实验 Spring boot 将 Log 传给 EFK

[Day27] swift & kotlin 上架篇!(1) 小鸡BB-游戏上架流程-swift

上架 终於来到上架的部分了 我们要把写好的APP上架到商店给人下载 一起来看看怎麽处理吧! Appl...

Java 关於发送 Https 请求 (HttpsURLConnection 和 HttpURLConnection)

https 协议对於开发者而言其实只是多了一步证书验证的过程,这个证书正常情况下被 jdk/jre/...

切换群集的 context

本篇文章实现从本地端的 K8s 群集操作 GKE。先从 GKE 上的群集 .kube/config ...

Day30. Model 与关联 - preload, join, includes 一次厘清

今天我们会用部落格跟使用者的关系来讲解关联,首先先做设定,部落格跟使用者的关系为 使用者对应多个部落...

Day07 X Image Sprites

经过昨天的一番折腾,我想读者们都对基本的图片优化稍有概念了,今天要介绍的优化技巧其实严格来说也算是...