部署单节点的zookeeper kafka,生产环境需分布式集群部署,本文仅开发测试使用

部署zookeeper

[root@k8s01 tools]# vim zookeeper.yaml 
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: zookeeper-data
  namespace: test-env
  labels:
    app: zookeeper
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 10Gi
  storageClassName: managed-nfs-storage
---
apiVersion: v1
kind: Service
metadata:
  name: zookeeper
  namespace: test-env
  labels:
    app: zookeeper
spec:
  selector:
    k8s-app: zookeeper
  ports:
  - port: 2181
    protocol: TCP
    targetPort: 2181
---
kind: Deployment
apiVersion: apps/v1
metadata:
  labels:
    k8s-app: zookeeper
  name: zookeeper
  namespace: test-env
spec:
  replicas: 1
  selector:
    matchLabels:
      k8s-app: zookeeper
  template:
    metadata:
      labels:
        k8s-app: zookeeper
    spec:
      containers:
      - name: zookeeper
        image: zookeeper:3.4.13
        imagePullPolicy: IfNotPresent
        ports:
          - containerPort: 2181
            protocol: TCP
        livenessProbe:
          tcpSocket:
            port: 2181
        volumeMounts:
        - name: data
          mountPath: /data
      volumes:
      - name: data
        persistentVolumeClaim:
          claimName: zookeeper-data               
      restartPolicy: Always

部署kafka

[root@k8s01 tools]# vim kafka.yaml 
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: kafka-data
  namespace: test-env
  labels:
    app: kafka
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 10Gi
  storageClassName: managed-nfs-storage
---
apiVersion: v1
kind: Service
metadata:
  name: kafka-cluster
  namespace: test-env
  labels:
    app: kafka
spec:
  selector:
    k8s-app: kafka
  ports:
  - port: 9092
    protocol: TCP
    targetPort: 9092
---
kind: Deployment
apiVersion: apps/v1
metadata:
  labels:
    k8s-app: kafka
  name: kafka
  namespace: test-env
spec:
  replicas: 1
  selector:
    matchLabels:
      k8s-app: kafka
  template:
    metadata:
      labels:
        k8s-app: kafka
    spec:
      containers:
      - name: kafka
        image: wurstmeister/kafka:latest
        imagePullPolicy: IfNotPresent
        ports:
          - containerPort: 9092
            protocol: TCP
        livenessProbe:
          tcpSocket:
            port: 9092
        volumeMounts:
        - name: localtime
          mountPath: /etc/localtime
        - name: kafka-data
          mountPath: /kafka
        env:
        - name: KAFKA_BROKER_ID
          value: "0"
        - name: KAFKA_PORT
          value: "9092" 
        - name: KAFKA_ZOOKEEPER_CONNECT
          value: "zookeeper.test-env.svc.cluster.local:2181/kafka"
        - name: KAFKA_ADVERTISED_LISTENERS
          value: "PLAINTEXT://kafka-cluster.test-env.svc.cluster.local:9092"
        - name: KAFKA_LISTENERS
          value: "PLAINTEXT://0.0.0.0:9092"
      volumes:
      - name: localtime
        hostPath:
          path: /etc/localtime
      - name: kafka-data
        persistentVolumeClaim:
          claimName: kafka-data               
      restartPolicy: Always               
文章作者: 鲜花的主人
版权声明: 本站所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 爱吃可爱多
Kafka Kubernetes Kubernetes Kafka
喜欢就支持一下吧
打赏
微信 微信
支付宝 支付宝