All Projects → kow3ns → Kubernetes Zookeeper

kow3ns / Kubernetes Zookeeper

Licence: apache-2.0
This project contains tools to facilitate the deployment of Apache ZooKeeper on Kubernetes.

Programming Languages

shell
77523 projects

Projects that are alternatives of or similar to Kubernetes Zookeeper

Cronner
Cronner 是一个分布式定时任务框架,支持作业依赖、分片、失效转移、集中配置和监控。
Stars: ✭ 51 (-50%)
Mutual labels:  zookeeper
Netty Stroll
RPC基础通信框架
Stars: ✭ 77 (-24.51%)
Mutual labels:  zookeeper
Repository
个人学习知识库涉及到数据仓库建模、实时计算、大数据、Java、算法等。
Stars: ✭ 92 (-9.8%)
Mutual labels:  zookeeper
Commonx
基础框架
Stars: ✭ 57 (-44.12%)
Mutual labels:  zookeeper
Burrowui
This is a NodeJS/Angular 2 frontend UI for Kafka cluster monitoring with Burrow
Stars: ✭ 69 (-32.35%)
Mutual labels:  zookeeper
Zookeeper Cookbook
Chef cookbook for installing and managing Zookeeper.
Stars: ✭ 80 (-21.57%)
Mutual labels:  zookeeper
Dister
dister(Distribution Cluster)是一款轻量级高性能的分布式集群管理软件,实现了分布式软件架构中的常用核心组件,包括:服务配置管理中心、服务注册与发现、服务健康检查、服务负载均衡。dister的灵感来源于ZooKeeper、Consul、Etcd,它们都实现了类似的分布式组件,但是dister更加的轻量级、低成本、易维护、架构清晰、简单实用、性能高效,这也是dister设计的初衷。
Stars: ✭ 41 (-59.8%)
Mutual labels:  zookeeper
Zookeeper
Apache ZooKeeper
Stars: ✭ 10,061 (+9763.73%)
Mutual labels:  zookeeper
Kazoo
Kazoo is a high-level Python library that makes it easier to use Apache Zookeeper.
Stars: ✭ 1,161 (+1038.24%)
Mutual labels:  zookeeper
E3mall
宜立方商城,SOA架构学习项目
Stars: ✭ 91 (-10.78%)
Mutual labels:  zookeeper
Ansible Playbook
Ansible playbook to deploy distributed technologies
Stars: ✭ 61 (-40.2%)
Mutual labels:  zookeeper
Eshop Soa
EShop基于Dubbo实现SOA服务化拆分,并基于RocketMQ解决了分布式事务(新版SpringBootSOASkeleton)
Stars: ✭ 65 (-36.27%)
Mutual labels:  zookeeper
Hadoop cookbook
Cookbook to install Hadoop 2.0+ using Chef
Stars: ✭ 82 (-19.61%)
Mutual labels:  zookeeper
Express Microservice Starter
An express-based Node.js API bootstrapping module for building microservices.
Stars: ✭ 53 (-48.04%)
Mutual labels:  zookeeper
Zookeeper Cpp
A ZooKeeper client for C++.
Stars: ✭ 98 (-3.92%)
Mutual labels:  zookeeper
Zetcd
Serve the Apache Zookeeper API but back it with an etcd cluster
Stars: ✭ 1,025 (+904.9%)
Mutual labels:  zookeeper
Easyrpc
EasyRpc is a simple, high-performance, easy-to-use RPC framework based on Netty, ZooKeeper and ProtoStuff.
Stars: ✭ 79 (-22.55%)
Mutual labels:  zookeeper
Springboot Templates
springboot和dubbo、netty的集成,redis mongodb的nosql模板, kafka rocketmq rabbit的MQ模板, solr solrcloud elasticsearch查询引擎
Stars: ✭ 100 (-1.96%)
Mutual labels:  zookeeper
Bigdata Notes
大数据入门指南 ⭐
Stars: ✭ 10,991 (+10675.49%)
Mutual labels:  zookeeper
Jeeplatform
一款企业信息化开发基础平台,拟集成OA(办公自动化)、CMS(内容管理系统)等企业系统的通用业务功能 JeePlatform项目是一款以SpringBoot为核心框架,集ORM框架Mybatis,Web层框架SpringMVC和多种开源组件框架而成的一款通用基础平台,代码已经捐赠给开源中国社区
Stars: ✭ 1,285 (+1159.8%)
Mutual labels:  zookeeper

Kubernetes ZooKeeper

This project contains tools to facilitate the deployment of Apache ZooKeeper on Kubernetes using StatefulSets. It requires Kubernetes 1.7 or greater.

Limitations

  1. Scaling is not currently supported. An ensemble's membership can not be updated in a safe way in ZooKeeper 3.4.10 (The current stable release).
  2. Observers are currently not supported. Contributions are welcome.
  3. Persistent Volumes must be used. emptyDirs will likely result in a loss of data.

ZooKeeper Docker Image

The docker directory contains the Makefile for a Docker image that runs a ZooKeeper server using some custom scripts.

Manifests

The manifests directory contains server Kubernetes manifests that can be used for demonstration purposes or production deployments. If you primarily deploy manifests directly you can modify any of these to fit your use case.

Helm

The helm directory contains a helm repository that deploys a ZooKeeper ensemble.

Administration and Configuration

Regardless of whether you use manifests or helm to deploy your ZooKeeper ensemble, there are some common administration and configuration items that you should be aware of.

Ensemble Size

As notes in the limitation section, ZooKeeper membership can't be dynamically configured using the latest stable version. You need to select an ensemble size that suites your use case. For demonstration purposes, or if you are willing to tolerate at most one planned or unplanned failure, you should select an ensemble size of 3. This is done by setting the spec.replicas field of the StatefulSet to 3,

apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
  name: zk
spec:
  serviceName: zk-hs
  replicas: 3
  ...

and passing in 3 as --servers parameter to the start-zookeeper script.

apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
  name: zk
spec:
...
        command:
        - sh
        - -c
        - "start-zookeeper \
          --servers=3 \
...

For production use cases, 5 servers may be desirable. This allows you to tolerate one planned and one unplanned failure.

Memory

While ZooKeeper periodically snapshots all of its data to its data directory, the entire working data set must fit on heap. The --heap parameter of the start-zookeeper script controls the heap size of the ZooKeeper servers,

apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
  name: zk
...
        command:
        - sh
        - -c
        - "start-zookeeper \
...
          --heap=512M \
...

and the spec.template.containers[0].resources.requests.memory controls the memory allocated to the JVM process.

apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
  name: zk
spec:
 ...
      containers:
      - name: kubernetes-zookeeper
        imagePullPolicy: Always
        image: "gcr.io/google_containers/kubernetes-zookeeper:1.0-3.4.10"
        resources:
          requests:
            memory: "1Gi"
...

You should probably not use heap sizes larger than 8 GiB. For production deployments you should consider setting the requested memory to the maximum of 2 GiB and 1.5 times the size of the configured JVM heap.

CPUs

ZooKeeper is not a CPU intensive application. For a production deployment you should start with 2 CPUs and adjust as necessary. For a demonstration deployment, you can set the CPUs as low as 0.5. The amount of CPU is configured by setting the StatefulSet's spec.template.containers[0].resources.requests.cpus.

apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
  name: zk
spec:
...
      containers:
      - name: kubernetes-zookeeper
        imagePullPolicy: Always
        image: "gcr.io/google_containers/kubernetes-zookeeper:1.0-3.4.10"
        resources:
          requests:
            memory: "4Gi"
            cpu: "2"
...

Networking

The Headless Service that controls the domain of the ensemble must have two ports. The sever port is used for inter-server communication, and the leader-election port is used to perform leader election.

apiVersion: v1
kind: Service
metadata:
  name: zk-hs
  labels:
    app: zk
spec:
  ports:
  - port: 2888
    name: server
  - port: 3888
    name: leader-election
  clusterIP: None
  selector:
    app: zk

These ports must correspond to the container ports in the StatefulSet's .spec.template and the parameters passed to the start-zookeeper script.

apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
  name: zk
spec:
  serviceName: zk-hs
  replicas: 3
  podManagementPolicy: Parallel
  updateStrategy:
    type: RollingUpdate
  template:
...
        ports:
        - containerPort: 2181
          name: client
        - containerPort: 2888
          name: server
        - containerPort: 3888
          name: leader-election
        command:
        - sh
        - -c
        - "start-zookeeper \
...
          --election_port=3888 \
          --server_port=2888 \
...

The Service used to load balance client connections has one port.

apiVersion: v1
kind: Service
metadata:
  name: zk-cs
  labels:
    app: zk
spec:
  ports:
  - port: 2181
    name: client
  selector:
    app: zk

The client port must correspond to the container port specified in the StatefulSet's .spec.template and the parameter passed to the start-zookeeper script.

```yaml
apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
  name: zk
spec:
  serviceName: zk-hs
  replicas: 3
  podManagementPolicy: Parallel
  updateStrategy:
    type: RollingUpdate
  template:
...
        ports:
        - containerPort: 2181
          name: client
        - containerPort: 2888
          name: server
        - containerPort: 3888
          name: leader-election
        command:
        - sh
        - -c
        - "start-zookeeper \
...
          --client_port=2181 \
...

Storage

Currently, the use of Persistent Volumes to provide durable, network attached storage is mandatory. If you use the provided image with emptyDirs, you will likely suffer a data loss. The storage field of the StatefulSet's spec.volumeClaimTemplates controls the storage the amount of storage allocated.

  volumeClaimTemplates:
    - metadata:
      name: datadir
    spec:
      accessModes: [ "ReadWriteOnce" ]
      resources:
        requests:
          storage: 20Gi

The volumeMounts in the StatefulSet's spec.template control the mount point of the PersistentVolumes requested by the PersistentVolumeClaims,

  volumeMounts:
  - name: datadir
    mountPath: /var/lib/zookeeper

and the parameters passed to the start-zookeeper script instruct the ZooKeeper server to use the PersistentVolume backed directory for its snapshots and write ahead log.

--data_dir          The directory where the ZooKeeper process will store its
                    snapshots. The default is /var/lib/zookeeper/data. This 
                    directory must be backed by a persistent volume.

--data_log_dir      The directory where the ZooKeeper process will store its 
                    write ahead log. The default is 
                    /var/lib/zookeeper/data/log. This directory must be 
                    backed by a persistent volume.

Note that, because we use network attached storage there is no benefit to using multiple PersistentVolumes to segregate the snapshot and write ahead log to separate storage media.

ZooKeeper Time

ZooKeeper does not use wall clock time. Rather, it uses internal ticks that are based on an elapsed number of milliseconds. The various timeouts for the ZooKeeper ensemble can be controlled by the parameters passed to the start-zookeeper script.

--tick_time         The length of a ZooKeeper tick in ms. The default is 
                    2000.

--init_limit        The number of Ticks that an ensemble member is allowed 
                    to perform leader election. The default is 10.

--sync_limit        The maximum session timeout that the ensemble will 
                    allows a client to request. The default is 5.

--max_session_timeout The maximum time in milliseconds for a client session 
                    timeout. The default value is 2 * tick time.

--min_session_timeout The minimum time in milliseconds for a client session 
                    timeout. The default value is 20 * tick time.

If you notice an excessive number of client timeouts or leader elections, you can tune these knobs as appropriate to increase stability, at the cost of slower failure detection.

Snapshot Retention

By default, ZooKeeper will never delete its own snapshots, though it will compact its write ahead log. You must either implement your own mechanism for retaining and removing snapshots, or configure the snapshot retention via the start-zookeeper script.

--snap_retain_count The maximum number of snapshots the ZooKeeper process 
                    will retain if purge_interval is greater than 0. The 
                    default is 3.

--purge_interval    The number of hours the ZooKeeper process will wait 
                    between purging its old snapshots. If set to 0 old 
                    snapshots will never be purged. The default is 0.

Pod Management Policy

ZooKeeper is not sensitive to the order in which Pods are started. All Pods in the StatefulSet may be launched and terminated in parallel. This is accomplished by setting the spec.podManagementPolicy to Parallel.

apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
  name: zk
spec:
...
  podManagementPolicy: Parallel
...

Update Strategy

The Update Strategy for the StatefulSet is set to RollingUpdate. This enables the rolling update feature for StatefulSets in Kubernetes 1.7, and it allows for modifications to the StatefulSet to be propagated to its Pods.

apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
  name: zk
spec:
  ...
  updateStrategy: 
    type: RollingUpdate
  ...

Liveness and Readiness

The zookeeper-ready script can be used to check the liveness and readiness of ZooKeeper process. The example below demonstrates how to configure liveness and readiness probes for the Pods in the StatefulSet.

  readinessProbe:
    exec:
      command:
      - sh
      - -c
      - "zookeeper-ready 2181"
    initialDelaySeconds: 15 
    timeoutSeconds: 5
  livenessProbe:
    exec:
      command:
      - sh
      - -c
      - "zookeeper-ready 2181"
    initialDelaySeconds: 15
    timeoutSeconds: 5

Spreading

An anti-affinity rule is specified to ensure that the ZooKeeper servers are spread across nodes in the Kubernetes cluster. This makes the ensemble resilient to node failures.

affinity:
    podAntiAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
        - labelSelector:
            matchExpressions:
              - key: "app"
                operator: In
                values: 
                - zk
          topologyKey: "kubernetes.io/hostname"

Logging

The Log Level configuration may be modified via the log_level flag supplied to the start-zookeeper script. However, the location of the log output is not modifiable. The ZooKeeper process must be run in the foreground, and the log information will be shipped to stdout. This is considered to be a best practice for containerized applications, and it allows users to make use of the log rotation and retention infrastructure that already exists for K8s.

Metrics

The zookeeper-metrics script can be used to retrieve metrics from the ZooKeeper process and print them to stdout. A recurring Kubernetes job can be used to collect these metrics and provide them to a collector.

bash$ kubectl exec zk-0 zookeeper-metrics
zk_version	3.4.10-1757313, built on 08/23/2016 06:50 GMT
zk_avg_latency	0
zk_max_latency	0
zk_min_latency	0
zk_packets_received	21
zk_packets_sent	20
zk_num_alive_connections	1
zk_outstanding_requests	0
zk_server_state	follower
zk_znode_count	4
zk_watch_count	0
zk_ephemerals_count	0
zk_approximate_data_size	27
zk_open_file_descriptor_count	39
zk_max_file_descriptor_count	1048576

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].