pulsar

by apecloud

Helm chartv1.2.0-alpha.0App 3.0.2Verified publisher

Apache Pulsar is an open-source, distributed messaging and streaming platform built for the cloud.

About this chart

Pulsar

ApacheĀ® Pulsarā„¢ is an open-source, distributed messaging and streaming platform built for the cloud. Pulsar's architecture is designed to provide scalability, reliability, and flexibility. It consists of several key components:

  • Brokers: These are stateless components responsible for handling incoming messages from producers, dispatching messages to consumers, and managing communication with the configuration store for coordination tasks. They also interface with Bookkeeper instances (bookies) for message storage and rely on a cluster-specific Zookeeper cluster for certain tasks.

  • Apache Bookkeeper (aka bookies): It handles the persistent storage of messages. Bookkeeper is a distributed write-ahead log (WAL) system that provides several advantages, including the ability to handle many independent logs (ledgers), efficient storage for sequential data, and guarantees read consistency even in the presence of system failures.

  • Zookeeper: Pulsar uses Zookeeper clusters for coordination tasks between Pulsar clusters and for cluster-level configuration and coordination.

Optional components include:

  • Pulsar Proxy: It is an optional gateway. It is typically used in scenarios where direct access to brokers is restricted due to network policies or security requirements. The proxy helps in managing client connections and forwarding requests to the appropriate brokers, providing an additional layer of security and simplifying network configurations.

  • Bookies Recovery: It is an optional component that helps in recovering data from failed bookies. It is used in scenarios where a bookie fails and data needs to be recovered from other bookies in the cluster.

Features In KubeBlocks

Lifecycle Management

TopologyHorizontalscalingVertical scalingExpandvolumeRestartStop/StartConfigureExposeSwitchover
Basic/EnhancedYesYesYesYesYesYesYesNo
  • Basic Mode: Includes the basic features of Pulsar, such as brokers, bookies, and Zookeeper.
  • Enhanced Mode: Includes additional components like Pulsar Proxy and Bookies Recovery.

Versions

Major VersionsVersions
2.11.x2.11.2
3.0.x3.0.2

Prerequisites

  • Kubernetes cluster >= v1.21

  • kubectl installed, refer to K8s Install Tools

  • Helm, refer to Installing Helm

  • KubeBlocks installed and running, refer to Install Kubeblocks

  • Pulsar Addon Enabled, refer to Install Addons

  • Create K8s Namespace demo, to keep resources created in this tutorial isolated:

    kubectl create ns demo
    

Examples

Create

Basic Mode

Create a pulsar cluster of Basic mode.

# cat examples/pulsar/cluster-basic.yaml
apiVersion: apps.kubeblocks.io/v1
kind: Cluster
metadata:
  name: pulsar-basic-cluster
  namespace: demo
spec:
  # Specifies the behavior when a Cluster is deleted.
  # Valid options are: [DoNotTerminate, Delete, WipeOut] (`Halt` is deprecated since KB 0.9)
  # - `DoNotTerminate`: Prevents deletion of the Cluster. This policy ensures that all resources remain intact.
  # - `Delete`: Extends the `Halt` policy by also removing PVCs, leading to a thorough cleanup while removing all persistent data.
  # - `WipeOut`: An aggressive policy that deletes all Cluster resources, including volume snapshots and backups in external storage. This results in complete data removal and should be used cautiously, primarily in non-production environments to avoid irreversible data loss.
  terminationPolicy: Delete
  # Specifies the name of the ClusterDefinition to use when creating a Cluster.
  # Note: DO NOT UPDATE THIS FIELD
  # The value must be `pulsar` to create a Pulsar Cluster
  clusterDef: pulsar
  # Specifies the name of the ClusterTopology to be used when creating the
  # Cluster.
  topology: pulsar-basic-cluster
  # Defines a list of additional Services that are exposed by a Cluster.
  services:
    - name: broker-bootstrap
      serviceName: broker-bootstrap
      componentSelector: broker
      spec:
        type: ClusterIP
        ports:
          - name: pulsar
            port: 6650
            targetPort: 6650
          - name: http
            port: 80
            targetPort: 8080
          - name: kafka-client
            port: 9092
            targetPort: 9092
    - name: zookeeper
      serviceName: zookeeper
      componentSelector: zookeeper
      spec:
        type: ClusterIP
        ports:
          - name: client
            port: 2181
            targetPort: 2181
  componentSpecs:
    - name: broker
      # ServiceVersion specifies the version of the Service expected to be
      # provisioned by this Component.
      # Valid options are: [2.11.2,3.0.2]
      serviceVersion: 3.0.2
      replicas: 1
      env:
        - name: KB_PULSAR_BROKER_NODEPORT
          value: "false"
      resources:
        limits:
          cpu: "1"
          memory: "512Mi"
        requests:
          cpu: "200m"
          memory: "512Mi"
    - name: bookies
      serviceVersion: 3.0.2
      replicas: 4
      resources:
        limits:
          cpu: "1"
          memory: "512Mi"
        requests:
          cpu: "200m"
          memory: "512Mi"
      volumeClaimTemplates:
        - name: ledgers
          spec:
            accessModes:
              - ReadWriteOnce
            resources:
              requests:
                storage: 8Gi
        - name: journal
          spec:
            accessModes:
              - ReadWriteOnce
            resources:
              requests:
                storage: 8Gi
    - name: zookeeper
      serviceVersion: 3.0.2
      replicas: 1
      resources:
        limits:
          cpu: "1"
          memory: "512Mi"
        requests:
          cpu: "100m"
          memory: "512Mi"
      volumeClaimTemplates:
        - name: data
          spec:
            accessModes:
              - ReadWriteOnce
            resources:
              requests:
                storage: 8Gi
kubectl apply -f examples/pulsar/cluster-basic.yaml

A cluster with one brokers, four bookies, and one zookeepers will be created. The Zookeeper component will be created apriori, and the Broker and Bookies components will be created after the Zookeeper component is RUNNING.

Enhanced Mode

Create a pulsar cluster of Enhanced mode.

# cat examples/pulsar/cluster-enhanced.yaml
apiVersion: apps.kubeblocks.io/v1
kind: Cluster
metadata:
  name: pulsar-enhanced-cluster
  namespace: demo
spec:
  # Specifies the behavior when a Cluster is deleted.
  # Valid options are: [DoNotTerminate, Delete, WipeOut] (`Halt` is deprecated since KB 0.9)
  # - `DoNotTerminate`: Prevents deletion of the Cluster. This policy ensures that all resources remain intact.
  # - `Delete`: Extends the `Halt` policy by also removing PVCs, leading to a thorough cleanup while removing all persistent data.
  # - `WipeOut`: An aggressive policy that deletes all Cluster resources, including volume snapshots and backups in external storage. This results in complete data removal and should be used cautiously, primarily in non-production environments to avoid irreversible data loss.
  terminationPolicy: Delete
  # Specifies the name of the ClusterDefinition to use when creating a Cluster.
  # Note: DO NOT UPDATE THIS FIELD
  # The value must be `pulsar` to create a Pulsar Cluster
  clusterDef: pulsar
  # Specifies the name of the ClusterTopology to be used when creating the
  # Cluster.
  topology: pulsar-enhanced-cluster
  # Defines a list of additional Services that are exposed by a Cluster.
  services:
    - name: broker-bootstrap
      serviceName: broker-bootstrap
      componentSelector: broker
      spec:
        type: ClusterIP
        ports:
          - name: pulsar
            port: 6650
            targetPort: 6650
          - name: http
            port: 80
            targetPort: 8080
          - name: kafka-client
            port: 9092
            targetPort: 9092
    - name: zookeeper
      serviceName: zookeeper
      componentSelector: zookeeper
      spec:
        type: ClusterIP
        ports:
          - name: client
            port: 2181
            targetPort: 2181
  componentSpecs:
    - name: proxy
      serviceVersion: 3.0.2
      replicas: 3
      resources:
        limits:
          cpu:
          memory: "512Mi"
        requests:
          cpu: "200m"
          memory: "512Mi"
    - name: bookies-recovery
      serviceVersion: 3.0.2
      replicas: 1
      resources:
        limits:
          cpu:
          memory: "512Mi"
        requests:
          cpu: "200m"
          memory: "512Mi"
    - name: broker
      serviceVersion: 3.0.2
      replicas: 1
      resources:
        limits:
          cpu:
          memory: "512Mi"
        requests:
          cpu: "200m"
          memory: "512Mi"
    - name: bookies
      serviceVersion: 3.0.2
      replicas: 4
      resources:
        limits:
          cpu:
          memory: "512Mi"
        requests:
          cpu: "200m"
          memory: "512Mi"
      volumeClaimTemplates:
        - name: ledgers
          spec:
            accessModes:
              - ReadWriteOnce
            resources:
              requests:
                storage: 8Gi
        - name: journal
          spec:
            accessModes:
              - ReadWriteOnce
            resources:
              requests:
                storage: 8Gi
    - name: zookeeper
      serviceVersion: 3.0.2
      replicas: 1
      resources:
        limits:
          cpu:
          memory: "512Mi"
        requests:
          cpu: "100m"
          memory: "512Mi"
      volumeClaimTemplates:
        - name: data
          spec:
            accessModes:
              - ReadWriteOnce
            resources:
              requests:
                storage: 8Gi

kubectl apply -f examples/pulsar/cluster-enhanced.yaml

A cluster with one brokers, four bookies, one bookies recovery, three proxy, and one zookeepers will be created.

And these components will be created in the following order: Zookeeper and Bookies Recovery, Bookies and Broker, finally Proxy.

Horizontal scaling

[!IMPORTANT] Please check how many replicas are allowed for each component in the cluster before scaling out/in.

A Pulsar cluster can scale to handle hundreds of brokers, depending on the workload and the resources available. Suggested practices are:

  • Start with a smaller number (3-5 brokers) for most deployments
  • Scale horizontally as needed based on metrics
  • Monitor performance and resource utilization

Here is an example of scale-out and scale-in operations for the Broker component.

Scale-out

Horizontal scaling out by adding ONE more replica for Broker component:

# cat examples/pulsar/scale-out.yaml
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
  name: pulsar-broker-scale-out
  namespace: demo
spec:
  # Specifies the name of the Cluster resource that this operation is targeting.
  clusterName: pulsar-basic-cluster
  type: HorizontalScaling
  # Lists HorizontalScaling objects, each specifying scaling requirements for a Component, including desired total replica counts, configurations for new instances, modifications for existing instances, and instance downscaling options
  horizontalScaling:
    # Specifies the name of the Component.
    # - proxy
    # - bookies-recovery
    # - broker
    # - bookies
    # - zookeeper
  - componentName: broker
    # Specifies the replica changes for scaling in components
    scaleOut:
      # Specifies the replica changes for the component.
      # add one more replica to current component
      replicaChanges: 1

kubectl apply -f examples/pulsar/scale-out.yaml

Scale-in

Horizontal scaling in PostgreSQL cluster by deleting ONE replica:

# cat examples/pulsar/scale-in.yaml
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
  name: pulsar-broker-scale-in
  namespace: demo
spec:
  # Specifies the name of the Cluster resource that this operation is targeting.
  clusterName: pulsar-basic-cluster
  type: HorizontalScaling
  # Lists HorizontalScaling objects, each specifying scaling requirements for a Component, including desired total replica counts, configurations for new instances, modifications for existing instances, and instance downscaling options
  horizontalScaling:
    # Specifies the name of the Component.
    # - proxy
    # - bookies-recovery
    # - broker
    # - bookies
    # - zookeeper
  - componentName: broker
    # Specifies the replica changes for scaling in components
    scaleIn:
      # Specifies the replica changes for the component.
      # add one more replica to current component
      replicaChanges: 1

kubectl apply -f examples/pulsar/scale-in.yaml

Scale-in/out using Cluster API

Alternatively, you can update the replicas field in the spec.componentSpecs.replicas section to your desired non-zero number.

# snippet of cluster.yaml
apiVersion: apps.kubeblocks.io/v1
kind: Cluster
spec:
  terminationPolicy: Delete
  componentSpecs:
    - name: broker
      componentDef: pulsar-broker
      serviceVersion: 3.0.2
      replicas: 1 # update to your desired number
      ...

Vertical scaling

Vertical scaling up or down specified components requests and limits cpu or memory resource in the cluster

# cat examples/pulsar/verticalscale.yaml
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
  name: pulsar-verticalscaling
  namespace: demo
spec:
  # Specifies the name

Deploy pulsar with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has pulsar on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.

  1. Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
  2. Place the chartpulsar is pinned at v1.2.0-alpha.0 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
  3. ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below
opentenant validate opentenant.yaml
terraform init && terraform apply