<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Artem Gogin on Medium]]></title>
        <description><![CDATA[Stories by Artem Gogin on Medium]]></description>
        <link>https://medium.com/@artem-gogin?source=rss-4fe4b3e8e073------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ackat5UM6akAXbRpilVahA.png</url>
            <title>Stories by Artem Gogin on Medium</title>
            <link>https://medium.com/@artem-gogin?source=rss-4fe4b3e8e073------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 13:08:41 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@artem-gogin/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to authenticate Kafka using Kerberos (SASL) with terminal, Spark (and Spark Streaming) and…]]></title>
            <link>https://artem-gogin.medium.com/how-to-authenticate-kafka-using-kerberos-sasl-with-terminal-spark-and-spark-streaming-and-962256d0446b?source=rss-4fe4b3e8e073------2</link>
            <guid isPermaLink="false">https://medium.com/p/962256d0446b</guid>
            <category><![CDATA[kerberos]]></category>
            <category><![CDATA[kafka]]></category>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[spark]]></category>
            <category><![CDATA[spark-streaming]]></category>
            <dc:creator><![CDATA[Artem Gogin]]></dc:creator>
            <pubDate>Thu, 12 Nov 2020 10:27:46 GMT</pubDate>
            <atom:updated>2020-11-12T10:27:46.467Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F4A6V_KBCVB0RKmL0xYmFQ.png" /></figure><h3>How to authenticate Kafka using Kerberos (SASL) with terminal, Spark (and Spark Streaming) and Jupyter Notebook.</h3><p>To briefly explain what we are trying to get here: we want to have permission to read and write Kafka topics. Our Kafka is protected by Kerberos. It means, before we start accessing Kafka, we need to obtain a ticket from Kerberos. To get the ticket we have to provide a keytab — authentication file for each user. All there steps have to be done automatically, because when we use commands to access Kafka there won’t be opportunity to show keytab manually. To get things done we need to specify right parameters and configurations in the right place.</p><p>Here is my environment (your tools and versions may vary but the schema still should work):</p><ul><li>Cloudera Hadoop cluster v. 5+</li><li>Kafka v. 2+ ( topic with Kerberos auth already exists)</li><li>Spark v. 2+</li><li>Kerberos v. 5</li><li>Jupyter Notebook with Pyspark</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GJBdopJjDD96oWhTWk0xOg.jpeg" /></figure><p>For the beginning, let’s access protected Kafka topic with <strong>terminal</strong>. The access on topic should only be granted if we obtain a ticket from Kerberos for the right user. For this operation we need to prepare (it will be smoother if all the files will be in the same path):</p><ul><li>User’s keytab file ( for Kerberos )</li><li>File <em>jaas.conf</em>:</li></ul><pre>KafkaClient {</pre><pre>com.sun.security.auth.module.Krb5LoginModule required</pre><pre>useKeyTab=true</pre><pre>keyTab=”${PATH_TO_YOUR_KEYTAB}“</pre><pre>principal=”${USER_NAME}@${REALM}”;</pre><pre>};</pre><ul><li>File <em>kafka_security.properties</em>:</li></ul><pre>security.protocol=SASL_PLAINTEXT</pre><pre>sasl.kerberos.service.name=kafka</pre><pre>sasl.mechanism=GSSAPI</pre><ul><li>File <em>krb5.conf</em> (probably located in <em>/etc/krb5.conf</em> or <em>/etc/kafka/krb5.conf</em>) (see <a href="https://docs.oracle.com/javase/8/docs/technotes/guides/security/jgss/tutorials/KerberosReq.html">JDK’s Kerberos Requirements</a> for more details):</li></ul><p>Then we need to export the variable with <em>jaas.conf</em> and <em>krb5.conf</em>:</p><pre>export KAFKA_OPTS=”-Djava.security.auth.login.config=jaas.conf -Djava.security.krb5.conf=/etc/krb5.conf”</pre><p>Then we can write and read Kafka topic from Terminal:</p><p>For writing:</p><pre>/bin/kafka-console-producer --broker-list ${KAFKA_BROKERS_WITH_PORTS} --topic ${TOPIC_NAME} --producer.config kafka_security.properties</pre><p>For reading:</p><pre>/bin/kafka-console-consumer --bootstrap-server ${KAFKA_BROKERS_WITH_PORTS} --topic ${TOPIC_NAME} --from-beginning --consumer.config kafka_security.properties</pre><p>Hope everything worked!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*8M6EncwcLknOAD0cQVSRIA.jpeg" /></figure><p>Let’s do the same thing using <strong>Spark</strong>.</p><p>The challenge here is that we want Spark to access Kafka not only with application driver, but also with every executor. It means, each executor needs to obtain ticket from Kerberos with our keytab. To make Spark do this, we need to specify right configurations.</p><p>Firstly, we need the same <em>jaas.conf</em>:</p><pre>KafkaClient {</pre><pre>com.sun.security.auth.module.Krb5LoginModule required</pre><pre>useKeyTab=true</pre><pre>keyTab=”${YOUR_KEYTAB_FILE} “</pre><pre>principal=”${USER_NAME}@${REALM}”;</pre><pre>};</pre><p>Before launching Spark, we also need to export the variable:</p><pre>export SPARK_KAFKA_VERSION=0.10</pre><p>In Spark code we will access Kafka with these options (the first 5 is mandatory):</p><pre>kafka.bootstrap.servers=${KAFKA_BROKERS_WITH_PORTS}</pre><pre>kafka.security.protocol=SASL_PLAINTEXT</pre><pre>kafka.sasl.kerberos.service.name=kafka</pre><pre>kafka.sasl.mechanism=GSSAPI</pre><pre>subscribe=${TOPIC_NAME}</pre><pre>startingOffsets=latest</pre><pre>maxOffsetsPerTrigger=1000</pre><p>You can pass these options map to:</p><pre>spark.readStream.<br> format(&quot;kafka&quot;).<br> options(myOptionsMap).<br> load()</pre><p>Before starting Spark we can define shell variable</p><pre>JAVA_OPTIONS=&quot;-Djava.security.auth.login.config=jaas.conf -Djava.security.krb5.conf=/etc/krb5.conf&quot;</pre><p>Also we will need two copies of users Keytab with different name. If we already have one, we can create the second one with command:</p><pre>cp $USER_NAME.keytab ${USER_NAME}_2.keytab</pre><p>And to launch the spark application we should run this command:</p><pre>spark2-submit \</pre><pre>--master yarn \</pre><pre>--conf &quot;spark.yarn.keytab=${USER_NAME}_2.keytab&quot; \</pre><pre>--conf &quot;spark.yarn.principal=$USER_NAME@$REALM&quot; \</pre><pre>--conf &quot;spark.driver.extraJavaOptions=$JAVA_OPTIONS&quot; \</pre><pre>--conf &quot;spark.executor.extraJavaOptions=$JAVA_OPTIONS&quot; \</pre><pre>--class &quot;org.example.MyClass&quot; \</pre><pre>--jars spark-sql-kafka-0-10_2.11-2.4.0.jar \</pre><pre>--files &quot;jaas.conf&quot;,&quot;${USER_NAME}.keytab&quot; \</pre><pre>my_spark.jar</pre><p>Or you can use the same configurations with spark-shell or pyspark.</p><p>Note: to allow Spark access HDFS we specify <em>spark.yarn.keytab</em> and <em>spark.yarn.principal</em>. To allow Spark access Kafka we specify <em>spark.driver.extraJavaOptions</em> and <em>spark.executor.extraJavaOptions</em> and provide files <em>jaas.conf, ${USER_NAME}.keytab</em>, mentioned in <em>JavaOptions</em> so every executor could receive a copy of these files for authentication. And for spark kafka dependency we provide <em>spark-sql-kafka</em> jar suitable for our spark version. We can also use option — package instead of — jars.</p><p>Hope everything worked!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*EobExOanjTpC_HqzGJGPwQ.png" /></figure><p>Let’s do the same trick in PySpark using <strong>Jupyter Notebook.</strong></p><p>To access shell environment from python we will use <em>os.environ</em>.</p><pre>import os<br>import sys</pre><pre>os.environ[‘SPARK_KAFKA_VERSION’] = ‘0.10’</pre><p>Then we should configure Spark session.</p><pre>spark = SparkSession.builder. \</pre><pre>config(‘spark.yarn.keytab’, ‘${USER_NAME}_2.keytab’).\</pre><pre>config(‘spark.yarn.principal’, ‘$USER_NAME@$REALM’).\</pre><pre>config(‘spark.jars’, ‘spark-sql-kafka-0–10_2.11–2.4.0.jar’).\</pre><pre>config(‘spark.driver.extraJavaOptions’, ‘-Djava.security.auth.login.config=jaas.conf -Djava.security.krb5.conf=/etc/krb5.conf’).\</pre><pre>config(‘spark.executor.extraJavaOptions’, ‘-Djava.security.auth.login.config=jaas.conf -Djava.security.krb5.conf=/etc/krb5.conf’).\</pre><pre>config(‘spark.files’, ‘jaas.conf,${KEYTAB}’).\</pre><pre>.appName(“KafkaSpark”).getOrCreate()</pre><p>we can connect to Kafka:</p><pre>kafka_raw = spark.readStream. \</pre><pre>format(‘kafka’). \</pre><pre>option(‘kafka.bootstrap.servers’, ${KAFKA_BROKERS_WITH_PORTS}). \</pre><pre>option(‘kafka.security.protocol’,’SASL_PLAINTEXT’). \</pre><pre>option(‘kafka.sasl.kerberos.service.name’,’kafka’). \</pre><pre>option(‘kafka.sasl.mechanism’,’GSSAPI’). \</pre><pre>option(‘startingOffsets’,’earliest’). \</pre><pre>option(‘maxOffestPerTrigger’,10). \</pre><pre>option(‘subscribe’,${TOPIC_NAME}). \</pre><pre>load()</pre><p>To access the data we can use:</p><pre>query = kafka_raw. \<br>    writeStream. \<br>    format(&quot;console&quot;). \<br>    start()</pre><p>That’s it. I hope you could find all the configurations you need to access Kafka using Kerberos any way you like.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=962256d0446b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How exactly Hadoop stores the data]]></title>
            <link>https://artem-gogin.medium.com/how-exactly-hadoop-stores-the-data-23da0679d173?source=rss-4fe4b3e8e073------2</link>
            <guid isPermaLink="false">https://medium.com/p/23da0679d173</guid>
            <category><![CDATA[distributed-computing]]></category>
            <category><![CDATA[hadoop]]></category>
            <category><![CDATA[hdfs]]></category>
            <category><![CDATA[hdfs-architecture]]></category>
            <category><![CDATA[distributed-systems]]></category>
            <dc:creator><![CDATA[Artem Gogin]]></dc:creator>
            <pubDate>Sat, 03 Oct 2020 16:28:50 GMT</pubDate>
            <atom:updated>2020-11-25T05:51:32.752Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pm4kPeNOMACtfxAihl3R5A.png" /></figure><blockquote>Apache Hadoop is a collection of open-source software utilities that facilitate using a network of many computers to solve problems involving massive amounts of data and computation. It provides a software framework for distributed storage and processing of big data. © Wikipedia</blockquote><p>How about we explore how exactly distributed storage works in Hadoop?</p><p>Envision that we need to store a ton of documents, do some computation on them like counting all the words, and store the measurement of the words close to the source data. To regularly complete this operation with Hadoop, we firstly have to store the data to our hardware.</p><h4>One machine</h4><p>For the beginning, let’s envision storing the data with one machine without Hadoop:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d02LGiDk1SrnKyt6WPnimg.png" /><figcaption>Storing the data with one machine</figcaption></figure><p>Now, imagine a scenario in which we need to handle enormous number of files. Imagine that a file can be even bigger than a single machine’s HDD. For this situation, we can upgrade our machine by adding more HDD. Doing this will result in the following impediments:</p><ul><li>Fitting enormous measures of assets into a single machine is incredibly costly.</li><li>If our machine goes down unexpectedly, we can’t handle any data any longer.</li></ul><h4>Several machines</h4><p>To take care of these issues, we need to move towards splitting calculations into a few machines. To achieve this we add 3 extra machines connected with one another. We want them to be a computing cluster. The objective is to store data, utilizing as many resources of each machine as possible at the same time. We can call these machines as workers or nodes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ojuP4Ptwx8tTnKG8SrLKNA.png" /><figcaption>Few machines to store the data</figcaption></figure><p>Now, we can simply divide all input records by 4 (number of our node) so each machine would accept ¼ of input files. We expect that all documents should be loaded similarly on 4 machines. But then we face considerably more disadvantages:</p><ul><li>Before we begin handling any data, we have to analyze each worker to know whether it has enough capacity to store the data. It can require some time (particularly if the connection isn’t strong enough) if we have multiple workers.</li><li>We need to monitor the processing advancement of every worker to know when the activity is finished.</li><li>If a node breaks down, we have to distinguish it and figure out how to manage the documents, relegated to this machine. For this situation, the processed data ought to be reassigned to alive nodes.</li><li>aWe need a solitary point to access all the stored data. Else, we can never be certain that we asked all of the workers which may contain information we need.</li></ul><h4>Hadoop</h4><p>Now, let’s talk about real Hadoop architecture. Turns out, to beat the troubles mentioned above, we have to characterize an essential node (known as <strong>NameNode</strong> in Hadoop) from one of the workers (or <strong>DataNodes</strong> in Hadoop).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K92xS8xT6lIMCxUYCrAU5A.png" /><figcaption>Hadoop nodes</figcaption></figure><p>If we consider one node as NameNode, it can be liable for allocating input files to workers, monitor the executions and, if necessary, reassign input documents to various workers. If we need our information to be reliable, the NameNode should manage all the replications of the stored data.</p><p>For these purposes all the HDD space of each node becomes divided by <strong>blocks</strong>. The information about each block and data inside is stored in <strong>Metadata </strong>on the NameNode.</p><p>At the point when we have the NameNode, writing the data to Hadoop become to resemble this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RifwZTONZALy16oRa1iPCg.png" /><figcaption>Hadoop writing</figcaption></figure><p>When there is a sign to write the data to the Hadoop cluster, it goes to the NameNode.</p><ol><li>The NameNode checks its metadata about blocks with enough free space. Then, it chooses in what block exactly each part of the data will be stored (and replicas as well). When the choice about target blocks is done, NameNode tells the client which DataNodes should be utilized for each part of data, and in what block precisely it should put each part of the data.</li><li>While the client writes its data, NameNode waits for it to acknowledge the writing or to reset the Metadata.</li><li>The client connects to the objective DataNode, writes the data to the target blocks and waits for the acknowledge.</li><li>After the data is written, before sending the acknowledge, DataNode checks if we need to have replications for just loaded data. If we do, the DataNode replicates new data to another DataNodes, targeted by NameNode at the beginning and so on.</li><li>When the last DataNode completed the replication, it sends acknowledge back to the previous DataNode, until the acknowledge reaches at the client.</li><li>When the client gets the acknowledge, it goes to the NameNode and commits the successful writing.</li><li>The NameNode saves the metadata about each block that was acknowledged. In this moment the writing is done and data is saved and replicated among DataNodes. Now NameNode has the information in what blocks exactly each part of data is stored.</li></ol><h4>Advantages</h4><p>Described Hadoop architecture allows us to get rid of disadvantages mentioned above:</p><ul><li>NameNode always knows about all of the other nodes. No need to check all of the nodes every time we want to write the data.</li><li>NameNode monitor every active writing and resets its metadata when timeout is reached.</li><li>If DataNode goes down, NameNode will redirect the writing to alive DataNode.</li><li>NameNode becomes a solitary point to access all the stored data because it keeps metadata about each block on other nodes.</li><li>Finnaly, If we need more computing resources, we can simply connect more DataNodes to enlarge the cluster’s capacity.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=23da0679d173" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>