VK Cloud logo

Deployment of Apache Kafka

You can deploy an Apache Kafka cluster on dedicated virtual machines in VK Cloud. The cluster uses the modern built-in metadata management system (KRaft) and does not depend on ZooKeeper.

To ensure secure communication and access control in the Kafka cluster, the service uses a comprehensive approach: all data between the client and the broker is transmitted over the encrypted TLS protocol, and user identities are verified using the SCRAM-SHA-512 algorithm. To minimize risk, access rights are separated: the administrator, applications, and monitoring systems each have their own isolated accounts with different privilege levels.

By completing all steps in this guide, you will:

  1. Deploy an Apache Kafka cluster.
  2. Configure and verify client connectivity to the cluster.
  3. Create a topic and send test messages.
  4. Explore the Kafbat UI web console.
  5. Connect to the nodes over SSH and configure monitoring.

By using the Apache Kafka service, you agree to the license agreements of Marketplace VK Cloud and Apache Kafka.

Preparation steps

  1. Register in VK Cloud and go to your account.

  2. Configure the network so that the service is accessible from the Internet:

    1. Create a network with Internet access if you have not already done so.
    2. In the subnet settings where the VMs with the deployed service will be located, disable the Private DNS option.

1. Connect the Apache Kafka service

  1. In your VK Cloud account, go to the Application Store section.

  2. Click the Apache Kafka service card.

    If the Apache Kafka service card is not shown on the page, click All solutions and find the card in the catalog.

  3. In the Tariff plans tab, select the service version from the list.

  4. Choose the required tariff:

    • Single node: the service is deployed on one VM with replication factor 1. Suitable for simple project development, demonstrations, or testing.
    • Cluster: the service is deployed on three, five, or seven nodes with replication factor 3. The first 3 nodes form the KRaft quorum, while the remaining nodes act as brokers. Nodes are distributed across the MS1, ME1, and PA2 availability zones. Suitable for real business workloads where high availability matters.
  5. Specify the parameters of the VMs on which the service will be deployed:

    • Number of nodes: for the Cluster tariff, select 3, 5, or 7 nodes.
    • Machine type: select a VM configuration from the list, from 2-8 to 16-64, where the first number is the number of CPU cores and the second is the RAM size in gigabytes. For production workloads, choose at least 4 vCPU and 16 GB of RAM.
    • Network: select the previously created network with Internet access and a subnet with Private DNS disabled.
  6. Specify the system disk and data disk parameters:

    • Disk size: specify the required VM disk size in gigabytes.
    • Disk type: select one of the disk types: HDD, SSD, or High-IOPS SSD.
  7. Click Next step.

  8. Configure access parameters:

    • Client network: enter subnet to open the brokers only from the selected subnet, or specify the network range where your applications run. Metrics are exposed without a password, so it is better to narrow this range.
    • Internet access: enable this option to access the service from the Internet. In this case, each node gets a public address and a domain name. Port 9094 is used for the connection.
    • Web console: enable browser access to a page for viewing topics, messages, and consumer groups. You can change this setting after deployment.
    • Console management: if Web console is enabled, enable this option to allow topic management from the console. You can change this mode after deployment.
    • Shared console address: for the Cluster tariff, enable this option to access the console through a single address via a load balancer. If the option is disabled, the number of console addresses matches the number of nodes with the console. Each console sees the entire cluster. This parameter can only be set during service deployment and cannot be changed later.
    • Console domain and certificate: enable this option so that the console receives a domain name in the xaas.msk.bizmrg.com zone, a trusted certificate, and a public address. In the Cluster plan, this option is used together with Shared console address. Without a domain, the console is available from the client network and is protected by an internal certificate authority certificate.
  9. Click Next step.

  10. At the Kafka parameters step, configure the required Kafka service parameters or keep the default values. They are suitable for getting started.

  11. Click Next step.

  12. Review the infrastructure cost for deploying the service and click Connect tariff.

    Cloud infrastructure deployment will start, and the service properties page will open. The process status is also displayed in Application Store → My services.

    After successful deployment, messages will be sent to the email address associated with your VK Cloud account:

    • a notification with a link to the service instance in your VK Cloud account;
    • an email with a one-time link to the access data.
  13. Follow the one-time link from the email and save the service access data:

    • bootstrapServers: broker addresses for client connections. The addresses are listed in the parameter separated by commas without spaces.
    • externalBootstrapServers: broker addresses for Internet connections if Internet access is enabled.
    • clusterCA: cluster certificate authority certificate.
    • adminUser, adminPassword: administrator account.
    • appUser, appPassword: application account for reading from and writing to existing topics.
    • monitoringUser, monitoringPassword: monitoring account for read-only access to metadata.
    • sshUser: user for SSH access.
    • sshKey: private SSH key.
    • consoleURL: web console address.
    • consoleUser, consolePassword: web console credentials.

2. Configure the client connection

  1. Save the clusterCA certificate to the kafka-ca.pem file.

  2. Add the certificate to the client trust store:

    keytool -import -alias kafka-ca -file kafka-ca.pem \   -keystore kafka-truststore.p12 -storetype PKCS12 \   -storepass <PASSWORD> -noprompt

    Here, <PASSWORD> is the trust store password that you set yourself.

  3. Make sure you use Kafka client library version 2.1 or later.

  4. Create a client.properties file with the client connection settings:

    security.protocol=SASL_SSLsasl.mechanism=SCRAM-SHA-512sasl.jaas.config=org.apache.kafka.common.security.scram.ScramLoginModule required \  username="<APPLICATION_LOGIN>" \  password="<APPLICATION_PASSWORD>";ssl.truststore.location=kafka-truststore.p12ssl.truststore.password=<PASSWORD>ssl.truststore.type=PKCS12

    Here:

    • <APPLICATION_LOGIN>, <APPLICATION_PASSWORD> are the appUser and appPassword application credentials from the email.
    • <PASSWORD> is the trust store password set in the previous step.
  5. Verify the connection you created to the cluster:

    kafka-broker-api-versions.sh --bootstrap-server <BROKER_ADDRESSES> --command-config client.properties

    Here:

    • <BROKER_ADDRESSES> are the values from the bootstrapServers parameter in the email. If there are multiple addresses, list them separated by commas without spaces.
    • client.properties is the file with the client connection settings that you created.

    If the command returns a list of supported API versions, the connection is configured correctly.

3. Create a topic

The appUser account can read and write existing topics, but cannot create them. To create a topic, use the administrator account.

  1. Create an admin.properties file and copy the contents of client.properties into it, replacing the username and password values in sasl.jaas.config with adminUser and adminPassword from the email.

  2. Create a topic:

    kafka-topics.sh --bootstrap-server <BROKER_ADDRESSES> --command-config admin.properties --create --topic <TOPIC_NAME> --partitions 6

    Here:

    • <BROKER_ADDRESSES> are the values from the bootstrapServers parameter in the email. If there are multiple addresses, list them separated by commas without spaces.
    • admin.properties is the file with the administrator connection settings that you created.
    • <TOPIC_NAME> is the name of your topic. The example below uses the name orders.
    • 6 is the number of partitions; specify a value that is a multiple of the number of brokers and includes spare capacity.

4. Send and read test messages

  1. Send test messages to the orders topic:

    kafka-console-producer.sh --bootstrap-server <BROKER_ADDRESSES> --producer.config client.properties --topic orders

    Here:

    • <BROKER_ADDRESSES> are the values from the bootstrapServers parameter in the email. If there are multiple addresses, list them separated by commas without spaces.
    • client.properties is the file with the client connection settings that you created.

    Enter several messages, one per line. Press Ctrl+C to finish.

  2. Read messages from the orders topic:

    kafka-console-consumer.sh --bootstrap-server <BROKER_ADDRESSES> --consumer.config client.properties --topic orders --from-beginning

5. Use the web console

If you enabled the Web console option when deploying the service, you can access the service through the Kafbat UI web console. Test it:

  1. Open the web console at consoleURL from the email.
  2. Sign in using consoleUser and consolePassword from the email.

6. Optional: increase the data disk size

You cannot change the data disk size through the tariff configuration wizard, but after deployment you can increase it manually.

To do this, select the disk named <id>-kafka-data-N, where <id> is the instance identifier and N is the node number. After the change, the VM must be rebooted. In a cluster, reboot the nodes one at a time.

7. Optional: configure monitoring

The web console displays current broker performance metrics for your Kafka cluster as charts. To preserve metric history and configure alerts, connect your own monitoring system to the Apache Kafka service.

Broker and node metrics are exposed in Prometheus format on ports 9404 and 9100 and are available from the client network.

To configure metric collection:

  1. Configure SSH access to a node and a broker:

    1. Save the SSH key from the email to the ~/.ssh/kafka.pem file.

    2. Set file permissions:

      chmod 600 ~/.ssh/kafka.pem
    3. Connect to a node of the deployed Apache Kafka service:

      ssh -i ~/.ssh/kafka.pem almalinux@<NODE_ADDRESS>

      Here, <NODE_ADDRESS> is the IP address of the required node from the bootstrapServers parameter in the email.

    After you sign in, all Kafka management utilities are located in the /opt/kafka/bin directory. They may be useful, for example, for collecting information about free space on the data disk.

  2. Configure your monitoring system to collect data from the node. For example:

    curl -s http://<NODE_ADDRESS>:9100/metrics | grep 'node_filesystem_avail_bytes.*/var/lib/kafka'

    Here:

    • <NODE_ADDRESS> is the IP address of the required node from the bootstrapServers parameter in the email.
    • 9100 is the port number for collecting node metrics.
    • node_filesystem_avail_bytes is the metric that shows the amount of free space on the data disk.
    • /var/lib/kafka is the path to the directory whose file system is located on the node.

    The output shows the amount of free space on the data disk.

    You can also collect other Prometheus metrics from the node, for example:

    • kafka_controller_kafkacontroller_activecontrollercount;
    • kafka_controller_kafkacontroller_offlinepartitionscount;
    • kafka_server_replicamanager_underreplicatedpartitions;
    • kafka_cluster_partition_underminisr.

    For more information, see the official Apache Kafka documentation.

  3. Configure your monitoring system to collect data from the broker:

    1. Create a monitoring.properties file and copy the contents of client.properties into it, replacing the username and password values in sasl.jaas.config with monitoringUser and monitoringPassword from the email.

    2. Use the kafka-consumer-groups.sh utility to get information about all consumer groups:

      kafka-consumer-groups.sh --bootstrap-server <BROKER_ADDRESSES> --command-config monitoring.properties --describe --all-groups

      Here:

      • <BROKER_ADDRESSES> are the values from the bootstrapServers parameter in the email. If there are multiple addresses, list them separated by commas without spaces.
      • monitoring.properties is the file with the monitoring connection settings that you created.
      • --describe displays detailed information.
      • --all-groups outputs information for all consumer groups.
    3. Review the output. It usually includes the following columns:

      • GROUP: consumer group name.
      • TOPIC: topic name read by the group.
      • PARTITION: partition number within the topic.
      • CURRENT-OFFSET: current offset, which is the number of the last message read for each partition.
      • LOG-END-OFFSET: the offset of the last message written to this partition, which is the current end of the data.
      • LAG: the difference between LOG-END-OFFSET and CURRENT-OFFSET. This is the most important number. It shows how many messages have not yet been read. If LAG grows, consumers are not keeping up with the data stream. If LAG is 0, all messages have been read and the group is processing in real time.
      • OWNER: the name of the process, or consumer, that is currently the leader for this partition.
      • HOST: the IP address or host name where this consumer is running.
Was this article helpful?