woonizzooni

kubernetes - zookeeper 구성 본문

Kubernetes

kubernetes - zookeeper 구성

woonizzooni 2020. 11. 5. 15:40

 

이전글 'redis'의 경우처럼 구동 및 연동 자체에 의미를 두고,

연동 목적에 따른 볼륨크기 조정이나, StatefulSet의 크기 등은 이 곳에 의미를 두지 않음.

 

 

Namespace : zoo-ns

Service : zk-hs, zk-cs

PodDisruptionBudget : zk-pdb

StatefulSet(3) : my-zoo

apiVersion: v1
kind: Namespace
metadata:
  name: zoo-ns
---
apiVersion: v1
kind: Service
metadata:
  namespace: zoo-ns
  name: zk-hs
  labels:
    app: zoo
spec:
  ports:
  - port: 2888
    name: server
  - port: 3888
    name: leader-election
  clusterIP: None
  selector:
    app: zoo
---
apiVersion: v1
kind: Service
metadata:
  namespace: zoo-ns
  name: zk-cs
  labels:
    app: zoo
spec:
  ports:
  - port: 2181
    name: client
  selector:
    app: zoo
---
apiVersion: policy/v1beta1
kind: PodDisruptionBudget
metadata:
  name: zk-pdb
spec:
  selector:
    matchLabels:
      app: zoo
  maxUnavailable: 1
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: my-zoo
  namespace: zoo-ns
spec:
  selector:
    matchLabels:
      app: zoo
  serviceName: zk-hs
  replicas: 3
  updateStrategy:
    type: RollingUpdate
  podManagementPolicy: Parallel
  template:
    metadata:
      labels:
        app: zoo
    spec:
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            - labelSelector:
                matchExpressions:
                  - key: app
                    operator: In
                    values:
                    - my-zoo
              topologyKey: "kubernetes.io/hostname"
      containers:
      - name: my-zoo
        imagePullPolicy: Always
        image: "k8s.gcr.io/kubernetes-zookeeper:1.0-3.4.10"
        resources:
          limits:
            cpu: "100m"
            memory: "512Mi"
          requests:
            cpu: "100m"
            memory: "512Mi"
        ports:
        - containerPort: 2181
          name: client
        - containerPort: 2888
          name: server
        - containerPort: 3888
          name: leader-election
        command:
        - sh
        - -c
        - "start-zookeeper \
          --servers=3 \
          --data_dir=/var/lib/zookeeper/data \
          --data_log_dir=/var/lib/zookeeper/data/log \
          --conf_dir=/opt/zookeeper/conf \
          --client_port=2181 \
          --election_port=3888 \
          --server_port=2888 \
          --tick_time=2000 \
          --init_limit=10 \
          --sync_limit=5 \
          --heap=512M \
          --max_client_cnxns=60 \
          --snap_retain_count=3 \
          --purge_interval=12 \
          --max_session_timeout=40000 \
          --min_session_timeout=4000 \
          --log_level=INFO"
        readinessProbe:
          exec:
            command:
            - sh
            - -c
            - "zookeeper-ready 2181"
          initialDelaySeconds: 10
          timeoutSeconds: 5
        livenessProbe:
          exec:
            command:
            - sh
            - -c
            - "zookeeper-ready 2181"
          initialDelaySeconds: 10
          timeoutSeconds: 5
        volumeMounts:
        - name: datadir
          mountPath: /var/lib/zookeeper
        - name: timezone
          mountPath: /etc/localtime
      volumes:
      - hostPath:
          path: /usr/share/zoneinfo/Asia/Seoul
        name: timezone
      securityContext:
        runAsUser: 1000
        fsGroup: 1000
  volumeClaimTemplates:
  - metadata:
      name: datadir
      namespace: zoo-ns
    spec:
      accessModes: [ "ReadWriteOnce" ]
      resources:
        requests:
          storage: 1G

 

$ kubectl apply -f ./zoo.yaml

$ kubectl get pod -n zoo-ns

  NAME   READY   STATUS   RESTARTS AGE

  zoo-0    1/1       Running   0 ..

  zoo-1    1/1       Running   0 ..

  zoo-2    1/1       Running   0 ..

 

> 주키퍼 접속 주소 : zk-cs.zoo-ns:2181

 

 

[참고]

kubernetes.io/ko/docs/tutorials/stateful-application/zookeeper/

 

Comments