Skip to content

Commit 0a38d4f

Browse files
Merge pull request #226808 from sreekzz/patch-132
New Page Connecting Kafka cluster with VM in different VNet
2 parents 681c721 + 939ba9b commit 0a38d4f

File tree

8 files changed

+132
-0
lines changed

8 files changed

+132
-0
lines changed

articles/hdinsight/TOC.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,8 @@ items:
661661
href: ./kafka/apache-kafka-streams-api.md
662662
- name: Use Apache Spark structured streaming
663663
href: ./hdinsight-apache-kafka-spark-structured-streaming.md
664+
- name: Connect Kafka cluster with VM in different VNet
665+
href: ./kafka/connect-kafka-cluster-with-vm-in-different-vnet.md
664666
- name: Concepts
665667
items:
666668
- name: Migrate Kafka workloads to 4.0
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
---
2+
title: Connect Apache Kafka cluster with VM in different VNet on Azure HDInsight - Azure HDInsight
3+
description: Learn how to connect Apache Kafka cluster with VM in different VNet on Azure HDInsight
4+
ms.service: hdinsight
5+
ms.topic: how-to
6+
ms.custom: hdinsightactive
7+
ms.date: 02/16/2023
8+
---
9+
10+
# How to connect Kafka cluster with VM in different VNet
11+
12+
This Document lists steps that must be followed to set up connectivity between VM and HDI Kafka residing in two different VNet.
13+
14+
1. Create two different VNets where HDInsight Kafka cluster and VM will be hosted respectively. For more information, see [Create a virtual network using the Azure portal](https://learn.microsoft.com/azure/virtual-network/quick-create-portal)
15+
16+
> [!Note]
17+
> These two VNets must be peered, so that IP addresses of their subnets must not overlap with each other. For more information, see [Create a virtual network using the Azure portal](https://learn.microsoft.com/azure/virtual-network/tutorial-connect-virtual-networks-portal)
18+
19+
1. Make sure that the peering status shows as connected.
20+
21+
:::image type="content" source="./media/connect-kafka-cluster-with-different-vnet/kakfa-event-peering-window.png" alt-text="Screenshot showing Kafka event peering." border="true":::
22+
23+
1. After the above steps are completed, we can create HDInsight Kafka cluster in one VNet. For more information, see [Create an Apache Kafka cluster](./apache-kafka-get-started.md#create-an-apache-kafka-cluster)
24+
25+
1. Create a Virtual Machine in the second 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](https://learn.microsoft.com/azure/virtual-machines/linux/quick-create-portal)
26+
27+
1. After this step, we can copy the entries of the file /etc/host from Kafka headnode to VM.
28+
29+
:::image type="content" source="./media/connect-kafka-cluster-with-different-vnet/etc-host-output.png" alt-text="Screenshot showing host file output." border="true":::
30+
31+
1. Remove the `headnodehost` string entries from the file. For example, the above image has `headnodehost` entry for the ip 10.0.0.16. After removal, it will be as
32+
33+
:::image type="content" source="./media/connect-kafka-cluster-with-different-vnet/modified-etc-hosts-output.png" alt-text="Screenshot showing modified host file output." border="true":::
34+
35+
1. After these entries are made, try to reach the Kafka Ambari dashboard using the curl command using the hn0 or hn1 FQDN as
36+
37+
From Linux VM
38+
39+
```
40+
curl hn0-vnetka.glarbkztnoqubmzjylls33qnse.bx.internal.cloudapp.net:8080
41+
```
42+
43+
Output:
44+
45+
```
46+
“<!--
47+
* Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
48+
49+
-->
50+
51+
<!DOCTYPE html>
52+
<html lang="en">
53+
54+
<head>
55+
56+
<meta charset="utf-8">
57+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
58+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
59+
<link rel="stylesheet" href="stylesheets/vendor.css">
60+
<link rel="stylesheet" href="stylesheets/app.css">
61+
<script src="javascripts/vendor.js"></script>
62+
<script src="javascripts/app.js"></script>
63+
64+
<script>
65+
$(document).ready(function() {
66+
require('initialize');
67+
// make favicon work in firefox
68+
$('link[type*=icon]').detach().appendTo('head');
69+
$('#loading').remove();
70+
});
71+
72+
</script>
73+
74+
<title>Ambari</title>
75+
<link rel="shortcut icon" href="/img/logo.png" type="image/x-icon">
76+
</head>
77+
<body>
78+
<div id="loading">...Loading...</div>
79+
<div id="wrapper">
80+
<!-- ApplicationView -->
81+
</div>
82+
<footer>
83+
84+
<div class="container footer-links">
85+
86+
<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>. <br>
87+
88+
<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>
89+
90+
</div>
91+
92+
</footer>
93+
94+
</body>
95+
96+
</html>”
97+
```
98+
From Windows VM
99+
100+
:::image type="content" source="./media/connect-kafka-cluster-with-different-vnet/windows-vm.png" alt-text="Screenshot showing windows VM output." border="true":::
101+
102+
> [!Note]
103+
> 1. In Windows VM , static hostnames are added in the file hosts present in the path `C:\Windows\System32\drivers\etc\`
104+
> 1. This document assumes that the Ambari server is active on hn0. If the Ambari server is active on hn1 use the FQDN of hn1 to access the Ambari UI.
105+
106+
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, https://github.com/Azure-Samples/hdinsight-kafka-java-get-started
107+
108+
Make sure to create the topic inside the Kafka cluster using the command
109+
110+
```
111+
java -jar kafka-producer-consumer.jar create <topic_name> $KAFKABROKERS
112+
```
113+
114+
1. After creating the topic, we can use the below commands to produce and consume. The $KAFKABROKERS must be replaced appropriately with the broker worker node FQDN and port as mentioned in the documentation.
115+
116+
```
117+
java -jar kafka-producer-consumer.jar producer test $KAFKABROKERS `
118+
java -jar kafka-producer-consumer.jar consumer test $KAFKABROKERS
119+
```
120+
121+
1. After this step you get an output as
122+
123+
**Producer output:**
124+
125+
:::image type="content" source="./media/connect-kafka-cluster-with-different-vnet/kafka-producer-output.png" alt-text="Screenshot showing Kafka producer output VM." border="true":::
126+
127+
**Consumer output:**
128+
129+
:::image type="content" source="./media/connect-kafka-cluster-with-different-vnet/kafka-consumer-output.png" alt-text="Screenshot showing Kafka producer output." border="true":::
130+
899 KB
Loading
1.56 MB
Loading
1.64 MB
Loading
91 KB
Loading
115 KB
Loading
86.6 KB
Loading

0 commit comments

Comments
 (0)