Skip to content

Commit 106a523

Browse files
authored
Merge pull request #247871 from sreekzz/sreekzz-patch-1
New page Create connect-kafka-with-vnet.md
2 parents b82823f + 63181cd commit 106a523

File tree

13 files changed

+216
-1
lines changed

13 files changed

+216
-1
lines changed

articles/hdinsight/TOC.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,9 @@ items:
714714
- name: SSL Encryption and Authentication for ESP Kafka cluster
715715
href: ./kafka/apache-esp-kafka-ssl-encryption-authentication.md
716716
- name: Kafka MirrorMaker 2.0 guide
717-
href: ./kafka/kafka-mirrormaker-2-0-guide.md
717+
href: ./kafka/kafka-mirrormaker-2-0-guide.md
718+
- name: Connect HDInsight Kafka cluster with client VM in different VNet
719+
href: ./kafka/connect-kafka-with-vnet.md
718720
- name: Troubleshoot
719721
items:
720722
- name: Insufficient fault domains
Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
---
2+
title: Connect HDInsight Kafka cluster with client VM in different VNet on Azure HDInsight
3+
description: Learn how to connect HDInsight Kafka cluster with Client VM in different VNet on Azure HDInsight
4+
ms.service: hdinsight
5+
ms.topic: tutorial
6+
ms.date: 08/10/2023
7+
---
8+
9+
# Connect HDInsight Kafka cluster with client VM in different VNet
10+
11+
This article describes the steps to set up the connectivity between a virtual machine (VM) and HDInsight Kafka cluster residing in two different virtual networks (VNet).
12+
13+
## Connect HDInsight Kafka cluster with client VM in different VNet
14+
15+
1. Create two different virtual networks where HDInsight Kafka cluster and VM are hosted respectively. For more information, see [Create a virtual network using Azure portal](/azure/virtual-network/quick-create-portal).
16+
17+
1. Peer these two virtual networks, so that IP addresses of their subnets must not overlap with each other. For more information, see [Connect virtual networks with virtual network peering using the Azure portal](/azure/virtual-network/tutorial-connect-virtual-networks-portal).
18+
19+
1. Ensure that the peering status shows as connected.
20+
21+
:::image type="content" source="./media/connect-kafka-with-vnet/vnet-peering.png" alt-text="Screenshot showing VNet peering." border="true" lightbox="./media/connect-kafka-with-vnet/vnet-peering.png":::
22+
23+
1. Create HDInsight Kafka cluster in first VNet `hdi-primary-vnet`. For more information, see [Create an HDInsight Kafka cluster](./apache-kafka-get-started.md#create-an-apache-kafka-cluster).
24+
25+
1. Create a virtual machine (VM) in the second VNet `hilo-secondary-vnet`. While creating the VM, specify the second VNet name where this virtual machine must be deployed. For more information, see [Create a Linux virtual machine in the Azure portal](/azure/virtual-machines/linux/quick-create-portal?tabs=ubuntu).
26+
27+
> [!NOTE]
28+
> IPs of Kafka VMs never change if VM is present in cluster. Only when you manually replace VM from the cluster then, that IP changes. You can check the latest IPs from Ambari portal.
29+
30+
## Methods to connect to HDInsight Kafka cluster from client VM
31+
32+
1. Configure Kafka for IP advertising: Use `Kafka IP advertising` to populate Kafka worker node private IPs in different vnet. Once IP advertising is done, use private DNS setup for DNS resolution of worker nodes FQDN.
33+
1. Update /etc/hosts file in client machine: Update `/etc/hosts` file in client machine with `/etc/hosts` file of Kafka Head/Worker node.
34+
35+
> [!NOTE]
36+
> * Private DNS setup is optional after IP advertising. This is required only when you want to use FQDN of Kafka worker nodes with private DNS domain name instead of private IPs.
37+
> * IPs of Kafka VMs never change if VM is present in cluster. Only when you manually replace VM from the cluster then, that IP changes. You can check the latest IPs from Ambari portal.
38+
39+
### Configure Kafka for IP advertising
40+
This configuration allows the client to connect using broker IP addresses instead of domain names. By default, Apache Zookeeper returns the domain name of the Kafka brokers to clients.
41+
42+
This configuration doesn't work with the VPN software client, as it can't use name resolution for entities in the virtual network.
43+
44+
Use the following steps to configure HDInsight Kafka to advertise IP addresses instead of domain names:
45+
46+
1. Using a web browser, go to `https://CLUSTERNAME.azurehdinsight.net`. Replace `CLUSTERNAME` with the HDInsight Kafka cluster name.
47+
1. When prompted, use the HTTPS `username` and `password` for the cluster. The Ambari Web UI for the cluster is displayed.
48+
1. To view information on Kafka, select `Kafka` from the left panel and then select configs.
49+
50+
:::image type="content" source="./media/connect-kafka-with-vnet/kafka-config.png" alt-text="Screenshot showing Kafka VNet configurations." border="true" lightbox="./media/connect-kafka-with-vnet/kafka-config.png":::
51+
52+
1. To access `kafka-env` configuration on the Ambari dashboard, just type `kafka-env` in the top right filter field in Ambari UI.
53+
54+
:::image type="content" source="./media/connect-kafka-with-vnet/kafka-env.png" alt-text="Screenshot showing Kafka environment." border="true" lightbox="./media/connect-kafka-with-vnet/kafka-env.png":::
55+
56+
1. To configure Kafka to advertise IP addresses, add the following text to the bottom of the `kafka-env-template` field:
57+
58+
```shell
59+
# Configure Kafka to advertise IP addresses instead of FQDN
60+
IP_ADDRESS=$(hostname -i)
61+
echo advertised.listeners=$IP_ADDRESS
62+
sed -i.bak -e '/advertised/{/advertised@/!d;}' /usr/hdp/current/kafka-broker/conf/server.properties
63+
echo "advertised.listeners=PLAINTEXT://$IP_ADDRESS:9092" >> /usr/hdp/current/kafka-broker/conf/server.properties
64+
```
65+
1. To configure the interface that Kafka listens on, enter `listeners` in the filter field on the top right.
66+
67+
1. To configure Kafka to listen on all network interfaces, change the value in the `listeners` field to `PLAINTEXT://0.0.0.0:9092`.
68+
1. To save the configuration changes, use the `Save` button. Enter a text message describing the changes. Select `OK` once the changes have been saved.
69+
70+
:::image type="content" source="./media/connect-kafka-with-vnet/save-kafka-broker.png" alt-text="Screenshot showing the save button." border="true" lightbox="./media/connect-kafka-with-vnet/save-kafka-broker.png":::
71+
72+
1. To prevent errors when restarting Kafka, use the `Actions` button and select `Turn On Maintenance Mode`. Select `OK` to complete this operation.
73+
74+
:::image type="content" source="./media/connect-kafka-with-vnet/action-button.png" alt-text="Screenshot showing action button." border="true" lightbox="./media/connect-kafka-with-vnet/action-button.png":::
75+
76+
1. To restart Kafka, use the `Restart` button and select `Restart All Affected`. Confirm the restart, and then use the `OK` button after the operation has completed.
77+
78+
:::image type="content" source="./media/connect-kafka-with-vnet/restart-button.png" alt-text="Screenshot showing how to restart." border="true" lightbox="./media/connect-kafka-with-vnet/restart-button.png":::
79+
80+
1. To disable maintenance mode, use the `Actions` button and select `Turn Off Maintenance Mode`. Select `OK` to complete this operation.
81+
1. Now you can execute your jobs from client VM with Kafka IP address. To check IP address of worker nodes from Ambari Portal click on `Hosts` on left panel.
82+
83+
:::image type="content" source="./media/connect-kafka-with-vnet/ambari-hosts.png" alt-text="Screenshot showing the worker node IP for Ambari." border="true" lightbox="./media/connect-kafka-with-vnet/ambari-hosts.png":::
84+
85+
1. Use Sample git repository to create Kafka topics](https://github.com/Azure-Samples/hdinsight-kafka-java-get-started), to produce and consume data from that topic.
86+
87+
```shell
88+
# In previous example IP of worker node 0 is `broker1-ip` and worker node 1 is `broker2-ip`
89+
# Create Kafka Topic
90+
java -jar kafka-producer-consumer.jar create <topic_name> $KAFKABROKERS
91+
java -jar kafka-producer-consumer.jar create test broker1-ip:9092,broker1-ip:9092
92+
```
93+
:::image type="content" source="./media/connect-kafka-with-vnet/create-topic.png" alt-text="Screenshot showing how to create Kafka topic." border="true" lightbox="./media/connect-kafka-with-vnet/create-topic.png":::
94+
95+
```shell
96+
# Produce Data in Topic
97+
java -jar kafka-producer-consumer.jar producer <topic_name> $KAFKABROKERS
98+
java -jar kafka-producer-consumer.jar producer test broker1-ip:9092, broker2-ip:9092
99+
```
100+
:::image type="content" source="./media/connect-kafka-with-vnet/producer.png" alt-text="Screenshot showing how to view Kafka producer." border="true" lightbox="./media/connect-kafka-with-vnet/producer.png":::
101+
102+
```shell
103+
# Consume Data from Topic
104+
java -jar kafka-producer-consumer.jar consumer <topic_name> $KAFKABROKERS
105+
java -jar kafka-producer-consumer.jar consumer test broker1-ip:9092,broker2-ip:9092
106+
```
107+
:::image type="content" source="./media/connect-kafka-with-vnet/consumer.png" alt-text="Screenshot showing Kafka consumer section." border="true" lightbox="./media/connect-kafka-with-vnet/consumer.png":::
108+
109+
> [!NOTE]
110+
> It is recommended to add all the brokers IP in **$KAFKABROKERS** for fault tolerance.
111+
112+
### Update /etc/hosts file in client machine
113+
114+
1. Copy the highlighted worker nodes entries of the file `/etc/host` from Kafka headnode to Client VM.
115+
116+
1. After these entries are made, try to reach the Kafka Ambari dashboard using the web browser or curl command using the hn0 or hn1 FQDN as:
117+
118+
#### If Client VM is using Linux OS
119+
120+
```
121+
# Execute curl command
122+
curl hn0-hdi-ka.mvml5coqo4xuzc1nckq1sltcxf.bx.internal.cloudapp.net:8080
123+
124+
# Output
125+
<!--
126+
* Licensed to the Apache Software Foundation (ASF) under one
127+
* or more contributor license agreements. See the NOTICE file
128+
* distributed with this work for additional information
129+
* regarding copyright ownership. The ASF licenses this file
130+
* to you under the Apache License, Version 2.0 (the
131+
* "License"); you may not use this file except in compliance
132+
* with the License. You may obtain a copy of the License at
133+
*
134+
* http://www.apache.org/licenses/LICENSE-2.0
135+
*
136+
* Unless required by applicable law or agreed to in writing, software
137+
* distributed under the License is distributed on an "AS IS" BASIS,
138+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
139+
* See the License for the specific language governing permissions and
140+
* limitations under the License.
141+
-->
142+
<!DOCTYPE html>
143+
<html lang="en">
144+
<head>
145+
<meta charset="utf-8">
146+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
147+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
148+
<link rel="stylesheet" href="stylesheets/vendor.css">
149+
<link rel="stylesheet" href="stylesheets/app.css">
150+
<script src="javascripts/vendor.js"></script>
151+
<script src="javascripts/app.js"></script>
152+
<script>
153+
$(document).ready(function() {
154+
require('initialize');
155+
// make favicon work in firefox
156+
$('link[type*=icon]').detach().appendTo('head');
157+
$('#loading').remove();
158+
});
159+
</script>
160+
<title>Ambari</title>
161+
<link rel="shortcut icon" href="/img/logo.png" type="image/x-icon">
162+
</head>
163+
<body>
164+
<div id="loading">...Loading...</div>
165+
<div id="wrapper">
166+
<!-- ApplicationView -->
167+
</div>
168+
<footer>
169+
<div class="container footer-links">
170+
<a data-qa="license-link" href="http://www.apache.org/licenses/LICENSE-2.0" target="_blank">Licensed under the Apache License, Version 2.0</a>.
171+
<a data-qa="third-party-link" href="/licenses/NOTICE.txt" target="_blank">See third-party tools/resources that Ambari uses and their respective authors</a>
172+
</div>
173+
</footer>
174+
</body>
175+
</html>
176+
```
177+
178+
### If Client VM is using Windows OS
179+
180+
1. Go to overview page of `hdi-kafka` and click on Ambari view to get the URL.
181+
182+
1. Put the login credential as username `admin` and password `YOUR_PASSWORD`, which you have set while creating cluster.
183+
184+
> [!NOTE]
185+
> 1. In Windows VM, static hostnames need to be added in the host file which present in the path `C:\Windows\System32\drivers\etc\`.
186+
> 1. This article assumes that the Ambari server is active on `Head Node 0`. If the Ambari server is active on `Head Node 1` use the FQDN of hn1 to access the Ambari UI.
187+
188+
:::image type="content" source="./media/connect-kafka-with-vnet/dashboard.png" alt-text="Screenshot showing the dashboard." border="true" lightbox="./media/connect-kafka-with-vnet/dashboard.png":::
189+
190+
1. You can also send messages to kafka topic and read the topics from the VM. For that you can try to use this sample java application.
191+
192+
1. Use sample git repository to create Kafka topics, produce and consume data from that topic. For more information, see [hdinsight-kafka-java-getting-started](https://github.com/Azure-Samples/hdinsight-kafka-java-get-started).
193+
194+
1. You can use FQDN, IP or short name(first six letters of cluster name) of brokers to pass as `KAFKABROKERS` in the following commands.
195+
196+
```
197+
# In the previous example # IP of worker node 0 is `broker1-ip` and worker node 1 is `broker2-ip`
198+
# Short Name of worker node 0 is `wn0-hdi-ka` and worker node 1 is `wn1-hdi-ka` # FQDN of worker node 0 is `wn0-hdi-ka.mvml5coqo4xuzc1nckq1sltcxf.bx.internal.cloudapp.net` and worker node 1 is `wn1-hdi-ka.mvml5coqo4xuzc1nckq1sltcxf.bx.internal.cloudapp.net`
199+
200+
# Create Kafka Topic
201+
java -jar kafka-producer-consumer.jar create <topic_name> $KAFKABROKERS
202+
java -jar kafka-producer-consumer.jar create test broker1-ip:9092,broker2-ip:9092
203+
204+
# Produce Data in Topic
205+
java -jar kafka-producer-consumer.jar producer <topic_name> $KAFKABROKERS
206+
java -jar kafka-producer-consumer.jar producer test wn0-hdi-ka:9092,wn1-hdi-ka:9092
207+
208+
# Consume Data from Topic
209+
java -jar kafka-producer-consumer.jar consumer <topic_name> $KAFKABROKERS
210+
java -jar kafka-producer-consumer.jar consumer test wn0-hdi-ka.mvml5coqo4xuzc1nckq1sltcxf.bx.internal.cloudapp.net:9092,wn1-hdi-ka.mvml5coqo4xuzc1nckq1sltcxf.bx.internal.cloudapp.net:9092
211+
```
212+
> [!NOTE]
213+
> It is recommended to add all the brokers IP, FQDN or short name in $KAFKABROKERS for fault tolerance.
97.7 KB
Loading
242 KB
Loading
277 KB
Loading
46.2 KB
Loading
48.9 KB
Loading
64.3 KB
Loading
96.9 KB
Loading
50 KB
Loading

0 commit comments

Comments
 (0)