연재 시리즈

쿠버네티스 오퍼레이터 스터디 3주차 - strimzi operator를 이용한 카프카 클러스터 설치

악분 2022. 6. 11. 21:05
반응형

안녕하세요. 이 글은 Strimzi operator을 이용하여 주키퍼, 카프카 클러스터 구성방법을 설명합니다.

 

1. strimzi operator란?

1.1 개요

Strimzi operator는 쿠버네티스 환경에서 카프카 설치와 운영을 단순화 했습니다. 쿠버네티스 crd를 이용하여 주키퍼, 카프카 클러스터를 설치할 수 있고 토픽 등도 crd로 관리합니다.

 

1.2 아키텍처

clouster operator는 각 컴퍼넌트를 crd로 배포하고 관리합니다.

 

  • cluster operator: kafaka cluster, zookeeper cluster 등 컴퍼넌트를 배포하고 관리
  • entity operator: user operator와 topic operator를 관리
    • topic operator: topic생성, 삭제 등 topic관리
    • user operator: kafaka 유저 관리
  • zookeeper cluster
    • 카프카의 메타데이터 관리 및 브로커의 정상 상태 점검
  • kafka cluster
    • 카프카 클러스터(여러 대 브로커 구성) 구성

출처: https://strimzi.io/docs/operators/latest/quickstart.html#key-features-operators_str

 

2. 설치

카프카, 주키퍼 설치는 cluster operator를 설치하는 것으로 시작합니다.

출처: https://strimzi.io/docs/operators/latest/quickstart.html#key-features-operators_str

 

2.1 Strimzi operator 설치

helm을 이용하여 쉽게 설치할 수 있습니다.

kubectl create namespace kafka
helm repo add strimzi https://strimzi.io/charts/
printf 'tolerations: [{key: node-role.kubernetes.io/master, operator: Exists, effect: NoSchedule}]\n' | \
helm install kafka-operator strimzi/strimzi-kafka-operator --version 0.29.0 --namespace kafka \
  --set nodeSelector."kubernetes\.io/hostname"=k8s-m --values /dev/stdin

 

cluster operator는 deployment로 배포됩니다.

kubectl get deploy,pod -n kafka

 

crd도 다수 설치되었습니다. crd는 카프카, 주피커, 토픽 등을 생성, 수정 등에 사용됩니다.

kubectl get crd

 

2.2 주키퍼 cluster, 카프카 cluster 설치

Strimzi crd로 주키퍼 클러스터와 카프카 클러스터를 설치해보겠습니다. Kafka crd를 이용하여 쉽게 설치할 수 있습니다. 아키텍처를 참고하면 cluster operator가 zookeeper 클러스터와 kafka 클러스터를 관리하는 것을 알 수있습니다.

출처: https://strimzi.io/docs/operators/latest/quickstart.html#key-features-operators_str

 

예제 설치에 사용한 crd 내용은 아래와 같습니다. 카프카 클러스터는 kafka필드로 설정되어 있습니다. 주키퍼 클러스터는 zookeepr필드에 설정되어 있습니다.

kubectl apply -f kafka.yaml -n kafka
apiVersion: kafka.strimzi.io/v1beta2
kind: Kafka
metadata:
  name: my-cluster
spec:
  kafka:
    #version: 3.1.1
    replicas: 3
    listeners:
      - name: plain
        port: 9092
        type: internal
        tls: false
      - name: tls
        port: 9093
        type: internal
        tls: false
      - name: external
        port: 9094
        type: nodeport
        tls: false
    storage:
      type: jbod
      volumes:
      - id: 0
        type: persistent-claim
        size: 10Gi
        deleteClaim: true
    config:
      offsets.topic.replication.factor: 3
      transaction.state.log.replication.factor: 3
      transaction.state.log.min.isr: 2
      default.replication.factor: 3
      min.insync.replicas: 2
      #inter.broker.protocol.version: "3.1.1"
    template:
      pod:
        affinity:
          podAntiAffinity:
            requiredDuringSchedulingIgnoredDuringExecution:
              - labelSelector:
                  matchExpressions:
                    - key: app.kubernetes.io/name
                      operator: In
                      values:
                        - kafka
                topologyKey: "kubernetes.io/hostname"
zookeeper:
  replicas: 3
  storage:
    type: persistent-claim
    size: 10Gi
    deleteClaim: true
  template:
    pod:
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            - labelSelector:
                matchExpressions:
                  - key: app.kubernetes.io/name
                    operator: In
                    values:
                      - zookeeper
              topologyKey: "kubernetes.io/hostname"
  entityOperator:
    topicOperator: {}
    userOperator: {}

 

카프카 클러스터와 주키퍼 클러스터는 statefulset으로 설치됩니다.

kubectl get sts -n kafka -owide

 

라벨필터로 쉽게 배포된 pod를 조회할 수 있습니다.

kubectl get pod -n kafka -l app.kubernetes.io/name=kafka
kubectl get pod -n kafka -l app.kubernetes.io/name=zookeeper

 

카프카 클러스터는 get kafka로 조회할 수 있습니다.

kubectl get kafka -n kafka

 

토픽은 kafkatopics crd로 조회할 수 있습니다.

kubectl get kafkatopics -n kafka

 

외부에서 접속할 수 있는 엔드포인트는 쿠버네티스 서비스로 관리되고 설정은 configmap으로 관리됩니다.

 kubectl get svc,configmap -n kafka

반응형