Get started in Kubernetes

This section guides you through every step of installing and running Apache Pulsar with Helm on Kubernetes quickly, including the following sections:

  • Install the Apache Pulsar on Kubernetes using Helm
  • Start and stop Apache Pulsar
  • Create topics using pulsar-admin
  • Produce and consume messages using Pulsar clients
  • Monitor Apache Pulsar status with Prometheus and Grafana

For deploying a Pulsar cluster for production usage, read the documentation on how to configure and install a Pulsar Helm chart.

Prerequisite

  • Kubernetes server 1.14.0+
  • kubectl 1.14.0+
  • Helm 3.0+
tip

For the following steps, step 2 and step 3 are for developers and step 4 and step 5 are for administrators.

Step 0: Prepare a Kubernetes cluster

Before installing a Pulsar Helm chart, you have to create a Kubernetes cluster. You can follow the instructions to prepare a Kubernetes cluster.

We use Minikube in this quick start guide. To prepare a Kubernetes cluster, follow these steps:

  1. Create a Kubernetes cluster on Minikube.

    1. minikube start --memory=8192 --cpus=4 --kubernetes-version=<k8s-version>
  1. The `<k8s-version>` can be any [Kubernetes version supported by your Minikube installation](https://minikube.sigs.k8s.io/docs/reference/configuration/kubernetes/), such as `v1.16.1`.
  1. Set kubectl to use Minikube.

    1. kubectl config use-context minikube
  1. To use the Kubernetes Dashboard with the local Kubernetes cluster on Minikube, enter the command below:

    1. minikube dashboard
  1. The command automatically triggers opening a webpage in your browser.

Step 1: Install Pulsar Helm chart

  1. Add Pulsar charts repo.

    1. helm repo add apache https://pulsar.apache.org/charts
  1. ```
  2. helm repo update
  3. ```
  1. Clone the Pulsar Helm chart repository.

    1. git clone https://github.com/apache/pulsar-helm-chart
    2. cd pulsar-helm-chart
  1. Run the script prepare_helm_release.sh to create secrets required for installing the Apache Pulsar Helm chart. The username pulsar and password pulsar are used for logging into the Grafana dashboard and Pulsar Manager.

    1. ./scripts/pulsar/prepare_helm_release.sh \
    2. -n pulsar \
    3. -k pulsar-mini \
    4. -c
  1. Use the Pulsar Helm chart to install a Pulsar cluster to Kubernetes.

    note

    You need to specify --set initialize=true when installing Pulsar the first time. This command installs and starts Apache Pulsar.

    1. helm install \
    2. --values examples/values-minikube.yaml \
    3. --set initialize=true \
    4. --namespace pulsar \
    5. pulsar-mini apache/pulsar
  1. Check the status of all pods.

    1. kubectl get pods -n pulsar
  1. If all pods start up successfully, you can see that the `STATUS` is changed to `Running` or `Completed`.
  2. **Output**
  3. ```
  4. NAME READY STATUS RESTARTS AGE
  5. pulsar-mini-bookie-0 1/1 Running 0 9m27s
  6. pulsar-mini-bookie-init-5gphs 0/1 Completed 0 9m27s
  7. pulsar-mini-broker-0 1/1 Running 0 9m27s
  8. pulsar-mini-grafana-6b7bcc64c7-4tkxd 1/1 Running 0 9m27s
  9. pulsar-mini-prometheus-5fcf5dd84c-w8mgz 1/1 Running 0 9m27s
  10. pulsar-mini-proxy-0 1/1 Running 0 9m27s
  11. pulsar-mini-pulsar-init-t7cqt 0/1 Completed 0 9m27s
  12. pulsar-mini-pulsar-manager-9bcbb4d9f-htpcs 1/1 Running 0 9m27s
  13. pulsar-mini-toolset-0 1/1 Running 0 9m27s
  14. pulsar-mini-zookeeper-0 1/1 Running 0 9m27s
  15. ```
  1. Check the status of all services in the namespace pulsar.

    1. kubectl get services -n pulsar
  1. **Output**
  2. ```
  3. NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
  4. pulsar-mini-bookie ClusterIP None <none> 3181/TCP,8000/TCP 11m
  5. pulsar-mini-broker ClusterIP None <none> 8080/TCP,6650/TCP 11m
  6. pulsar-mini-grafana LoadBalancer 10.106.141.246 <pending> 3000:31905/TCP 11m
  7. pulsar-mini-prometheus ClusterIP None <none> 9090/TCP 11m
  8. pulsar-mini-proxy LoadBalancer 10.97.240.109 <pending> 80:32305/TCP,6650:31816/TCP 11m
  9. pulsar-mini-pulsar-manager LoadBalancer 10.103.192.175 <pending> 9527:30190/TCP 11m
  10. pulsar-mini-toolset ClusterIP None <none> <none> 11m
  11. pulsar-mini-zookeeper ClusterIP None <none> 2888/TCP,3888/TCP,2181/TCP 11m
  12. ```

Step 2: Use pulsar-admin to create Pulsar tenants/namespaces/topics

pulsar-admin is the CLI (command-Line Interface) tool for Pulsar. In this step, you can use pulsar-admin to create resources, including tenants, namespaces, and topics.

  1. Enter the toolset container.

    1. kubectl exec -it -n pulsar pulsar-mini-toolset-0 -- /bin/bash
  1. In the toolset container, create a tenant named apache.

    1. bin/pulsar-admin tenants create apache
  1. Then you can list the tenants to see if the tenant is created successfully.
  2. ```
  3. bin/pulsar-admin tenants list
  4. ```
  5. You should see a similar output as below. The tenant `apache` has been successfully created.
  6. ```
  7. "apache"
  8. "public"
  9. "pulsar"
  10. ```
  1. In the toolset container, create a namespace named pulsar in the tenant apache.

    1. bin/pulsar-admin namespaces create apache/pulsar
  1. Then you can list the namespaces of tenant `apache` to see if the namespace is created successfully.
  2. ```
  3. bin/pulsar-admin namespaces list apache
  4. ```
  5. You should see a similar output as below. The namespace `apache/pulsar` has been successfully created.
  6. ```
  7. "apache/pulsar"
  8. ```
  1. In the toolset container, create a topic test-topic with 4 partitions in the namespace apache/pulsar.

    1. bin/pulsar-admin topics create-partitioned-topic apache/pulsar/test-topic -p 4
  1. In the toolset container, list all the partitioned topics in the namespace apache/pulsar.

    1. bin/pulsar-admin topics list-partitioned-topics apache/pulsar
  1. Then you can see all the partitioned topics in the namespace `apache/pulsar`.
  2. ```
  3. "persistent://apache/pulsar/test-topic"
  4. ```

Step 3: Use Pulsar client to produce and consume messages

You can use the Pulsar client to create producers and consumers to produce and consume messages.

By default, the Pulsar Helm chart exposes the Pulsar cluster through a Kubernetes LoadBalancer. In Minikube, you can use the following command to check the proxy service.

  1. kubectl get services -n pulsar | grep pulsar-mini-proxy

You will see a similar output as below.

  1. pulsar-mini-proxy LoadBalancer 10.97.240.109 <pending> 80:32305/TCP,6650:31816/TCP 28m

This output tells what are the node ports that Pulsar cluster’s binary port and HTTP port are mapped to. The port after 80: is the HTTP port while the port after 6650: is the binary port.

Then you can find the IP address and exposed ports of your Minikube server by running the following command.

  1. minikube service pulsar-mini-proxy -n pulsar

Output

  1. |-----------|-------------------|-------------|-------------------------|
  2. | NAMESPACE | NAME | TARGET PORT | URL |
  3. |-----------|-------------------|-------------|-------------------------|
  4. | pulsar | pulsar-mini-proxy | http/80 | http://172.17.0.4:32305 |
  5. | | | pulsar/6650 | http://172.17.0.4:31816 |
  6. |-----------|-------------------|-------------|-------------------------|
  7. 🏃 Starting tunnel for service pulsar-mini-proxy.
  8. |-----------|-------------------|-------------|------------------------|
  9. | NAMESPACE | NAME | TARGET PORT | URL |
  10. |-----------|-------------------|-------------|------------------------|
  11. | pulsar | pulsar-mini-proxy | | http://127.0.0.1:61853 |
  12. | | | | http://127.0.0.1:61854 |
  13. |-----------|-------------------|-------------|------------------------|

At this point, you can get the service URLs to connect to your Pulsar client. Here are URL examples:

  1. webServiceUrl=http://127.0.0.1:61853/
  2. brokerServiceUrl=pulsar://127.0.0.1:61854/

Then you can proceed with the following steps:

  1. Download the Apache Pulsar tarball from the downloads page.

  2. Decompress the tarball based on your download file.

    1. tar -xf <file-name>.tar.gz
  1. Expose PULSAR_HOME.

    (1) Enter the directory of the decompressed download file.

    (2) Expose PULSAR_HOME as the environment variable.

    1. export PULSAR_HOME=$(pwd)
  1. Configure the Pulsar client.

    In the ${PULSAR_HOME}/conf/client.conf file, replace webServiceUrl and brokerServiceUrl with the service URLs you get from the above steps.

  2. Create a subscription to consume messages from apache/pulsar/test-topic.

    1. bin/pulsar-client consume -s sub apache/pulsar/test-topic -n 0
  1. Open a new terminal. In the new terminal, create a producer and send 10 messages to the test-topic topic.

    1. bin/pulsar-client produce apache/pulsar/test-topic -m "---------hello apache pulsar-------" -n 10
  1. Verify the results.

    • From the producer side

      Output

      The messages have been produced successfully.

      1. 18:15:15.489 [main] INFO org.apache.pulsar.client.cli.PulsarClientTool - 10 messages successfully produced
  1. - From the consumer side
  2. **Output**
  3. At the same time, you can receive the messages as below.
  4. ```
  5. ----- got message -----
  6. ---------hello apache pulsar-------
  7. ----- got message -----
  8. ---------hello apache pulsar-------
  9. ----- got message -----
  10. ---------hello apache pulsar-------
  11. ----- got message -----
  12. ---------hello apache pulsar-------
  13. ----- got message -----
  14. ---------hello apache pulsar-------
  15. ----- got message -----
  16. ---------hello apache pulsar-------
  17. ----- got message -----
  18. ---------hello apache pulsar-------
  19. ----- got message -----
  20. ---------hello apache pulsar-------
  21. ----- got message -----
  22. ---------hello apache pulsar-------
  23. ----- got message -----
  24. ---------hello apache pulsar-------
  25. ```

Step 4: Use Pulsar Manager to manage the cluster

Pulsar Manager is a web-based GUI management tool for managing and monitoring Pulsar.

  1. By default, the Pulsar Manager is exposed as a separate LoadBalancer. You can open the Pulsar Manager UI using the following command:

    1. minikube service -n pulsar pulsar-mini-pulsar-manager
  1. The Pulsar Manager UI will be open in your browser. You can use the username pulsar and password pulsar to log into Pulsar Manager.

  2. In Pulsar Manager UI, you can create an environment.

    • Click New Environment button in the top-left corner.
    • Type pulsar-mini for the field Environment Name in the popup window.
    • Type http://pulsar-mini-broker:8080 for the field Service URL in the popup window.
    • Click Confirm button in the popup window.
  3. After successfully created an environment, you are redirected to the tenants page of that environment. Then you can create tenants, namespaces and topics using the Pulsar Manager.

Step 5: Use Prometheus and Grafana to monitor cluster

Grafana is an open-source visualization tool, which can be used for visualizing time series data into dashboards.

  1. By default, the Grafana is exposed as a separate LoadBalancer. You can open the Grafana UI using the following command:

    1. minikube service pulsar-mini-grafana -n pulsar
  1. The Grafana UI is open in your browser. You can use the username pulsar and password pulsar to log into the Grafana Dashboard.

  2. You can view dashboards for different components of a Pulsar cluster.