broker设置指定播发侦听器,并以其他方式公开集群?

pn9klfpd  于 2021-06-08  发布在  Kafka
关注(0)|答案(1)|浏览(301)

我正在尝试在azure中托管的kubernetes群集上设置多代理kafka。我有一个单一的经纪人设置工作。对于multi-broker设置,目前我有一个管理kafka服务的zookeeper节点集合(3)。我将kafka集群部署为复制因子为3的复制控制器。那是3个经纪人。如何向zookeeper注册这三个代理,以便它们向zookeeper注册不同的ip地址?
部署服务后,我调出复制控制器,并使用复制控制器yaml文件中的集群ip指定两个advanced.listener,一个用于ssl,另一个用于纯文本。但是,在这种情况下,所有代理都使用相同的ip注册并写入副本失败。我不想将每个代理部署为单独的复制控制器/pod和服务,因为扩展成为一个问题。如果您对此有任何想法/想法,我将不胜感激。
编辑1:
另外,我正在尝试将集群暴露给云中的另一个专有网络。我必须为客户端公开ssl和纯文本端口,我正在使用adverted.listeners。如果我使用复制因子为3的statefulset,并让kubernetes将pods的规范主机名公开为主机名,则无法从外部客户机解析这些主机名。我实现这一点的唯一方法是使用/公开与每个代理对应的外部服务。然而,这并不具有伸缩性。

w41d8nur

w41d8nur1#

Kubernetes有 Statefulsets 解决这些问题。statefulset的每个示例都有自己的dns名称,因此您可以通过dns名称引用每个示例。
这里更详细地描述了这个概念。您还可以看看这个完整的示例:

apiVersion: v1
kind: Service
metadata:
  name: zk-headless
  labels:
    app: zk-headless
spec:
  ports:
  - port: 2888
    name: server
  - port: 3888
    name: leader-election
  clusterIP: None
  selector:
    app: zk
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: zk-config
data:
  ensemble: "zk-0;zk-1;zk-2"
  jvm.heap: "2G"
  tick: "2000"
  init: "10"
  sync: "5"
  client.cnxns: "60"
  snap.retain: "3"
  purge.interval: "1"
---
apiVersion: policy/v1beta1
kind: PodDisruptionBudget
metadata:
  name: zk-budget
spec:
  selector:
    matchLabels:
      app: zk
  minAvailable: 2
---
apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
  name: zk
spec:
  serviceName: zk-headless
  replicas: 3
  template:
    metadata:
      labels:
        app: zk
      annotations:
        pod.alpha.kubernetes.io/initialized: "true"

    spec:
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            - labelSelector:
                matchExpressions:
                  - key: "app"
                    operator: In
                    values: 
                    - zk-headless
              topologyKey: "kubernetes.io/hostname"
      containers:
      - name: k8szk
        imagePullPolicy: Always
        image: gcr.io/google_samples/k8szk:v1
        resources:
          requests:
            memory: "4Gi"
            cpu: "1"
        ports:
        - containerPort: 2181
          name: client
        - containerPort: 2888
          name: server
        - containerPort: 3888
          name: leader-election
        env:
        - name : ZK_ENSEMBLE
          valueFrom:
            configMapKeyRef:
              name: zk-config
              key: ensemble
        - name : ZK_HEAP_SIZE
          valueFrom:
            configMapKeyRef:
                name: zk-config
                key: jvm.heap
        - name : ZK_TICK_TIME
          valueFrom:
            configMapKeyRef:
                name: zk-config
                key: tick
        - name : ZK_INIT_LIMIT
          valueFrom:
            configMapKeyRef:
                name: zk-config
                key: init
        - name : ZK_SYNC_LIMIT
          valueFrom:
            configMapKeyRef:
                name: zk-config
                key: tick
        - name : ZK_MAX_CLIENT_CNXNS
          valueFrom:
            configMapKeyRef:
                name: zk-config
                key: client.cnxns
        - name: ZK_SNAP_RETAIN_COUNT
          valueFrom:
            configMapKeyRef:
                name: zk-config
                key: snap.retain
        - name: ZK_PURGE_INTERVAL
          valueFrom:
            configMapKeyRef:
                name: zk-config
                key: purge.interval
        - name: ZK_CLIENT_PORT
          value: "2181"
        - name: ZK_SERVER_PORT
          value: "2888"
        - name: ZK_ELECTION_PORT
          value: "3888"
        command:
        - sh
        - -c
        - zkGenConfig.sh && zkServer.sh start-foreground
        readinessProbe:
          exec:
            command:
            - "zkOk.sh"
          initialDelaySeconds: 15
          timeoutSeconds: 5
        livenessProbe:
          exec:
            command:
            - "zkOk.sh"
          initialDelaySeconds: 15
          timeoutSeconds: 5
        volumeMounts:
        - name: datadir
          mountPath: /var/lib/zookeeper
      securityContext:
        runAsUser: 1000
        fsGroup: 1000
  volumeClaimTemplates:
  - metadata:
      name: datadir
    spec:
      accessModes: [ "ReadWriteOnce" ]
      resources:
        requests:
          storage: 20Gi

相关问题