K8S部署Kafka界面管理工具(kafkamanager)方法详解
程序员文章站
2022-03-01 20:28:51
kafka-manager 是雅虎开源的apache-kafka管理工具,是用scala编写的,可以在web页面进行kafka的相关操作。一、制作kafkamanager的image镜像下载kafka...
kafka-manager 是雅虎开源的apache-kafka管理工具,是用scala编写的,可以在web页面进行kafka的相关操作。
一、制作kafkamanager的image镜像
下载kafka-manager-2.0.0.2.zip,在解压目录的conf下的application.conf文件里,修改kafka-manager.zkhosts地址和cmake.zkhosts地址为:
zok-0.zk-hs.wiseco.svc.cluster.local:2181,zok-1.zk-hs.wiseco.svc.cluster.local:2181,zok-2.zk-hs.wiseco.svc.cluster.local:2181
[root@k8s-storage01 kafkamanager]# pwd /home/k8s_deploy/fin/online/deploy/kafkamanager [root@k8s-storage01 kafkamanager]# ll total 59228 -rw-r--r-- 1 root root 353 jan 27 17:42 dockerfile -rw-r--r-- 1 root root 60639694 jan 27 17:48 kafka-manager-2.0.0.2.zip [root@k8s-storage01 kafkamanager]# unzip kafka-manager-2.0.0.2.zip [root@k8s-storage01 kafkamanager]# ll total 59228 -rw-r--r-- 1 root root 353 jan 27 17:42 dockerfile drwxr-xr-x 6 root root 4096 jan 27 18:09 kafka-manager-2.0.0.2 -rw-r--r-- 1 root root 60639694 jan 27 17:48 kafka-manager-2.0.0.2.zip [root@k8s-storage01 kafkamanager]# cd kafka-manager-2.0.0.2/conf/ [root@k8s-storage01 conf]# vim application.conf ........... ........... kafka-manager.zkhosts="zok-0.zk-hs.wiseco.svc.cluster.local:2181,zok-1.zk-hs.wiseco.svc.cluster.local:2181,zok-2.zk-hs.wiseco.svc.cluster.local:2181" ........... ........... basicauthentication.enabled=true #这里启用了用户密码登录,默认false不启用 (除了这里启用用户登录, 后面也可以启用ldap) basicauthentication.enabled=${?kafka_manager_auth_enabled} ........... ........... basicauthentication.username="admin" basicauthentication.username=${?kafka_manager_username} basicauthentication.password="admin@123" #修改用户登录密码 basicauthentication.password=${?kafka_manager_password} ........... ........... 重新打包 [root@k8s-storage01 conf]# cd ../../ [root@k8s-storage01 kafkamanager]# ll total 59228 -rw-r--r-- 1 root root 353 jan 27 17:42 dockerfile drwxr-xr-x 6 root root 4096 jan 27 18:09 kafka-manager-2.0.0.2 -rw-r--r-- 1 root root 60639694 jan 27 17:48 kafka-manager-2.0.0.2.zip [root@k8s-storage01 kafkamanager]# rm -rf kafka-manager-2.0.0.2.zip [root@k8s-storage01 kafkamanager]# tar -zvcf kafka-manager-2.0.0.2.tar.gz kafka-manager-2.0.0.2 [root@k8s-storage01 kafkamanager]# rm -rf kafka-manager-2.0.0.2 [root@k8s-storage01 kafkamanager]# ll total 58000 -rw-r--r-- 1 root root 353 jan 27 17:42 dockerfile -rw-r--r-- 1 root root 59387703 jan 27 18:13 kafka-manager-2.0.0.2.tar.gz 制作dockerfile镜像 [root@k8s-storage01 kafkamanager]# cat dockerfile from 192.168.10.10/wiseco/jdk1.8.0_192 run rm -f /etc/localtime \ && ln -sv /usr/share/zoneinfo/asia/shanghai /etc/localtime \ && echo "asia/shanghai" > /etc/timezone env lang en_us.utf-8 add kafka-manager-2.0.0.2.tar.gz /opt/ run mv /opt/kafka-manager-2.0.0.2 /opt/kafka-manager expose 9000 cmd ["/opt/kafka-manager/bin/kafka-manager"] 上传到harbor仓库 [root@k8s-storage01 kafkamanager]# docker build -t 192.168.10.10/wiseco/kafka-manager-2.0.0.2:v1 . [root@k8s-storage01 kafkamanager]# docker push 192.168.10.10/wiseco/kafka-manager-2.0.0.2:v1
二、创建kafkamanager的pod
[root@k8s-master01 kafkamanager]# pwd /opt/k8s/k8s-project/kafka_zk/kafkamanager [root@k8s-master01 kafkamanager]# cat kafkamanager.yaml apiversion: v1 kind: service metadata: name: kafkamanager namespace: wiseco labels: app: kafkamanager spec: type: nodeport selector: app: kafkamanager ports: - name: http port: 9000 targetport: 9000 nodeport: 39921 --- apiversion: apps/v1 kind: deployment metadata: name: kafkamanager namespace: wiseco spec: replicas: 1 minreadyseconds: 10 strategy: rollingupdate: maxsurge: 1 maxunavailable: 0 type: rollingupdate selector: matchlabels: app: kafkamanager template: metadata: labels: app: kafkamanager spec: affinity: podantiaffinity: requiredduringschedulingignoredduringexecution: - labelselector: matchexpressions: - key: "app" operator: in values: - kafkamanager topologykey: "kubernetes.io/hostname" terminationgraceperiodseconds: 120 containers: - name: kafkamanager image: 192.168.10.10/wiseco/kafka-manager-2.0.0.2:v1 imagepullpolicy: always ports: - name: cport containerport: 9000 resources: requests: cpu: 100m memory: 100mi limits: cpu: 500m memory: 400mi lifecycle: poststart: exec: command: ["/bin/sh","-c","touch /tmp/health"] livenessprobe: exec: command: ["test","-e","/tmp/health"] initialdelayseconds: 5 timeoutseconds: 5 periodseconds: 10 readinessprobe: tcpsocket: port: cport initialdelayseconds: 15 timeoutseconds: 5 periodseconds: 20
创建并查看
[root@k8s-master01 kafkamanager]# kubectl apply -f kafkamanager.yaml [root@k8s-master01 kafkamanager]# kubectl get pods -n wiseco|grep kafkamanager kafkamanager-6b966689f6-mr9tq 1/1 running 0 2m51s [root@k8s-master01 kafkamanager]# kubectl get svc -n wiseco|grep kafkamanager kafkamanager nodeport 10.254.240.254 <none> 9000:39921/tcp 2m55s
三、kafkamanager访问
使用k8s的nodeport端口访问kafkamanager
登录用户是:admin
登录密码是:admin@123
更多关于k8s技术知识请查看下面的相关链接