helm部署kafka
chart
添加chart仓库:
helm repo add incubator http://storage.googleapis.com/kubernetes-charts-incubator
编辑values.yaml
replicas: 3
## https://github.com/confluentinc/cp-docker-images/
image: "confluentinc/cp-kafka"
imageTag: "5.4.2"
imagePullPolicy: "IfNotPresent"
resources:
limits:
cpu: 4000m
memory: 4500Mi
requests:
cpu: 1000m
memory: 1Gi
kafkaHeapOptions: "-Xmx4G -Xms1G"
priorityClassName: high-priority
persistence:
enabled: true
storageClass: "nfs"
size: "1500Gi"
terminationGracePeriodSeconds: 60
podManagementPolicy: OrderedReady
readinessProbe:
initialDelaySeconds: 30
periodSeconds: 10
timeoutSeconds: 5
successThreshold: 1
failureThreshold: 3
zookeeper:
resources:
limits:
cpu: 1000m
memory: 2Gi
requests:
cpu: 100m
memory: 1Gi
persistence:
enabled: true
storageClass: "nfs"
size: "1500Gi"
helm部署kafka
kubectl create ns video
helm install --name kafka \
-f values.yaml \
incubator/kafka \
--namespace video
如果报错create Pod kafka-0 in StatefulSet kafka failed error: pods "kafka-0" is forbidden: no PriorityClass with name high-priority was found
,找不到high-priority
,则创建个
apiVersion: scheduling.k8s.io/v1
kind: PriorityClass
metadata:
name: high-priority
#value小于一亿的32bit整数,数字越大优先级越高,超过一亿的数字被系统保留,用于指派给系统组件。
value: 100000000
#globalDefault:指示是否应用于全局pod
globalDefault: false
description: "This priority class should be used for test service pods only."
然后将StatefulSet缩放为0再恢复到3
查看kafka
版本:
root@kafka-2:/# ls /usr/share/java/kafka | grep kafka
kafka-clients-5.4.2-ccs.jar
kafka-log4j-appender-5.4.2-ccs.jar
kafka-streams-5.4.2-ccs.jar
kafka-streams-examples-5.4.2-ccs.jar
kafka-streams-scala_2.12-5.4.2-ccs.jar
kafka-streams-test-utils-5.4.2-ccs.jar
kafka-tools-5.4.2-ccs.jar
kafka.jar
kafka_2.12-5.4.2-ccs-javadoc.jar
kafka_2.12-5.4.2-ccs-scaladoc.jar
kafka_2.12-5.4.2-ccs-sources.jar
kafka_2.12-5.4.2-ccs-test-sources.jar
kafka_2.12-5.4.2-ccs-test.jar
kafka_2.12-5.4.2-ccs.jar
Scala编译器的版本2.12
简单操作测试:
创建一个testclient
apiVersion: v1
kind: Pod
metadata:
name: testclient
namespace: video
spec:
containers:
- name: kafka
image: confluentinc/cp-kafka:5.4.2
command:
- sh
- -c
- "exec tail -f /dev/null"
测试:
#list all kafka
kubectl -n video exec testclient -- ./bin/kafka-topics.sh --zookeeper kafka-zookeeper:2181 --list
#create a new topic test1:
kubectl -n video exec testclient -- ./bin/kafka-topics.sh --zookeeper kafka-zookeeper:2181 --topic test1 --create --partitions 1 --replication-fact
#listen for messages on a topic test1:
kubectl -n video exec -ti testclient -- ./bin/kafka-console-consumer.sh --bootstrap-server kafka:9092 --topic test1 --from-beginning
#start an interactive message producer session:
kubectl -n video exec -ti testclient -- ./bin/kafka-console-producer.sh --broker-list kafka-headless:9092 --topic test1