<?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 Pavel Tuzov on Medium]]></title>
        <description><![CDATA[Stories by Pavel Tuzov on Medium]]></description>
        <link>https://medium.com/@paveltuzov?source=rss-33d29fa205c4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*WQ5J1F_P1uYzdE_fAMEpIA@2x.jpeg</url>
            <title>Stories by Pavel Tuzov on Medium</title>
            <link>https://medium.com/@paveltuzov?source=rss-33d29fa205c4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 13:01:18 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@paveltuzov/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[Goodbye, Hamburg!]]></title>
            <link>https://medium.com/@paveltuzov/goodbye-hamburg-7e5ae7472d3f?source=rss-33d29fa205c4------2</link>
            <guid isPermaLink="false">https://medium.com/p/7e5ae7472d3f</guid>
            <category><![CDATA[germany]]></category>
            <category><![CDATA[cities]]></category>
            <category><![CDATA[hamburg]]></category>
            <category><![CDATA[goodbye]]></category>
            <category><![CDATA[alster]]></category>
            <dc:creator><![CDATA[Pavel Tuzov]]></dc:creator>
            <pubDate>Mon, 03 Jan 2022 05:58:02 GMT</pubDate>
            <atom:updated>2022-01-03T05:58:24.785Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kyiA1ST8DLFFCK49" /><figcaption>Photo by <a href="https://unsplash.com/@julie_soul?utm_source=medium&amp;utm_medium=referral">Julia Solonina</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>I remember very well the day we met. I didn’t have many expectations. I didn’t really have time to find out things about you. Our meeting was spontaneous.</p><p>I was kind of lost. Didn’t really know how to talk to you, where to start. So I went along with what came to my mind. And suddenly I discovered a part of you — that pearl that today is one of the things I love most in you. But on that day I couldn’t grasp it yet. Nevertheless, I knew we’ll be good friends.</p><p>That first meeting was too short. I had to leave you as spontaneously as I met you. But I didn’t say “goodbye”. It was a “see you later”. And when I met you next time, our beautiful relationship started for good.</p><p>I also remember very well the day I fell in love with you. I loved your smell, your freshness. I enjoyed our walk. I quickly understood that you are not a “simple” one. You were the popular one. You were the one everyone knows and talks about. You were not the first of your kind I met, but the first I held hands with. The first I had a chance to spend intimate time with. There was no rush. All the time was ours.</p><p>First you played it safe. You showed only the popular parts of you — those I would surely like. But little by little I got to know your hidden corners. And there is so much beauty in you!</p><p>There were so many topics I could discuss with you. But we started preferring some topics over the others. So I could also feel stability with you.</p><p>I also started discovering your bad parts, that people call dirty. But that’s one of the things that attract me to you. You are not boring. You are not like the others.</p><p>I can’t thank you enough for what you did to my character. You educated me.</p><p>I often think that moving to Germany changed my personality. But if I think better, it was actually you. You showed me that there is a better life than I had ambitions for and you made me understand that I can have it. You were indeed my gateway to the world.</p><p>You introduced me to your friends and I’m so grateful for this. I’ve learned so much from them!</p><p>And after all, it’s so strange to tell you this, but I’m leaving you. My life suddenly changed a lot and I need some things you can’t give me. But to be honest, the thought of leaving you was planted a while back. In the beginning I would dismiss it right away, but the more I thought about it, the more I noticed that I’m growing out of our relationship. I remember I bought an accessory — a bracelet with an anchor. That was one of the rare spontaneous purchases I made. It meant to remind me about you and I understood that that was it. Mysubconsciousness was already trying to get hold of symbols of you, knowing very well that we will separate sooner or later.</p><p>I embrace you and thank you for all what you did to me these past eight years. You will always be deep in my heart. I love you and I promise that we will see each other again.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7e5ae7472d3f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The City]]></title>
            <link>https://medium.com/@paveltuzov/the-city-405c084a0367?source=rss-33d29fa205c4------2</link>
            <guid isPermaLink="false">https://medium.com/p/405c084a0367</guid>
            <category><![CDATA[manhattan]]></category>
            <category><![CDATA[nyc]]></category>
            <category><![CDATA[journal]]></category>
            <category><![CDATA[travel]]></category>
            <dc:creator><![CDATA[Pavel Tuzov]]></dc:creator>
            <pubDate>Sun, 05 Sep 2021 19:23:08 GMT</pubDate>
            <atom:updated>2021-09-05T19:23:08.141Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*uCUorWHLXA6hs8iP" /><figcaption>Photo by <a href="https://unsplash.com/@anikinearthwalker?utm_source=medium&amp;utm_medium=referral">Dimitry Anikin</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>As I started to look rarely at Google Maps, as I know about how much it takes to walk from Midtown to Chelsea, as I started confidently crossing the street at red light, as the useless taxi horns on the crossroads stopped wondering me, as my neck doesn’t hurt anymore from watching the skyscrapers, as the never ending sirens stopped taking my attention, as I got used to the famous humid summer heat, as I started walking in restaurants based on my feeling and not Google Maps review, as I started to quickly decide what I want in my bagel, as I started to walk more often without my backpack, now I have to leave The City.</p><p>It was so nice to me…</p><p>The weather forecast showed rain for the whole week, I was hiding in the building shadows from the sun. They said it is dirty — not dirtier than any big city. They said Time Square is a giant tourist trap, “don’t go there” — I was using every opportunity to walk through it — those bright lights in the night! They also said there will be huge lines to the towers — I staid longer in the line to get a fresh, hand rolled bagel. They said New Yorkers are rude — New Yorkers were the ones to ask how is our stay and give us more tips.</p><p>It’s not my first visit to the US, but NYC is all those things I only “saw in movies”. I feel very confident that I will recognize now “on TV” the different parts of Manhattan, because they are each special in their own way. I will know immediately if it is Grand Central Station or Penn Station, I believe I will tell apart the Madison from 5th Avenue and surely I’ll know it’s Park Avenue when I see the trees and bushes in the middle of it. I understood why Broadway is special, what SOHO, NOHO and TriBeCa mean, I saw that Hell’s Kitchen is actually a very nice and peaceful region, I know why the Yellow Cab is so special and, after being in the place where the twins stood, I still can’t imagine what chaos was happening downtown on September 11th.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=405c084a0367" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Terraform: don’t use kubernetes provider with your cluster resource!]]></title>
            <link>https://itnext.io/terraform-dont-use-kubernetes-provider-with-your-cluster-resource-d8ec5319d14a?source=rss-33d29fa205c4------2</link>
            <guid isPermaLink="false">https://medium.com/p/d8ec5319d14a</guid>
            <category><![CDATA[azure-kubernetes-service]]></category>
            <category><![CDATA[infrastructure-as-code]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[azure]]></category>
            <dc:creator><![CDATA[Pavel Tuzov]]></dc:creator>
            <pubDate>Tue, 02 Feb 2021 21:05:54 GMT</pubDate>
            <atom:updated>2021-02-03T20:01:41.360Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*uTu054LBzLIGCVg8" /><figcaption>Photo by <a href="https://unsplash.com/@officestock?utm_source=medium&amp;utm_medium=referral">Sebastian Herrmann</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Don’t worry, you can still deploy your namespaces in the cluster, but you have to be careful.</p><p>So you use terraform to create a kubernetes cluster. This is not at all uncommon to create some resources in the cluster as well. Like some namespaces, RBAC, network policies and maybe even deploy an ingress controller. You decided that it all belongs to the infrastructure and terraform is your IaC tool.</p><p>Thankfully, terraform has kubernetes provider that can do exactly this.</p><p>Let’s take the following minimalistic example. It creates an Azure Kubernetes Service Cluster and a namespace in it:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ca5c7b60ac312944b4647b1f30652d0f/href">https://medium.com/media/ca5c7b60ac312944b4647b1f30652d0f/href</a></iframe><p>If you apply this script, the 3 resources will be created in the correct order and you will see the <em>green result </em>from terraform. So far so good.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/712/1*HJpZcbROQld39xVBkl7IPw.png" /></figure><p>And at this point you will probably continue adding infrastructure to the project and never look back.</p><p>But as soon as you make a change in the cluster configuration that leads to cluster recreate, you will be surprised what happens when you run terraform refresh.</p><p>You will start getting <em>strange</em> errors.</p><p>It can be something like this:</p><pre>Error: Get “<a href="http://localhost/api/v1/namespaces/demo">http://localhost/api/v1/namespaces/demo</a>&quot;: dial tcp 127.0.0.1:80: connect: connection refused</pre><p>Or I also saw something like this:</p><pre>Error: Kubernetes cluster unreachable: invalid configuration: no configuration has been provided, try setting KUBERNETES_MASTER environment variable</pre><p>Seems like the kubernetes provider configuration is somehow reset? But why at refresh?</p><p>And no, it doesn’t help setting explicit dependency between the resources. The graph looks pretty good:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/824/1*cd_CwakpubxiZ8YAYdt7JA.png" /></figure><p>As usually, only after playing around, scratching your had, searching the internet, you will finally read carefully through the <a href="https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs">official kubernetes provider documentation</a>:</p><blockquote>WARNING</blockquote><blockquote>When using interpolation to pass credentials to the Kubernetes provider from other resources, <strong>these resources SHOULD NOT be created in the same Terraform module where Kubernetes provider resources are also used</strong>. <strong>This will lead to intermittent and unpredictable errors which are hard to debug and diagnose.</strong> The root issue lies with the order in which Terraform itself evaluates the provider blocks vs. actual resources. Please refer to <a href="https://www.terraform.io/docs/configuration/providers.html#provider-configuration">this section of Terraform docs</a> for further explanation.</blockquote><p><em>Bold text is marked by me.</em></p><p>Hence the title of this post. You need to split cluster creation and creating resources in it into two different scripts. And preferably use <a href="https://www.terraform.io/docs/language/state/remote-state-data.html">terraform remote state</a> data source to get required cluster information for the kubernetes provider.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d8ec5319d14a" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/terraform-dont-use-kubernetes-provider-with-your-cluster-resource-d8ec5319d14a">Terraform: don’t use kubernetes provider with your cluster resource!</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Reactive Angular]]></title>
            <link>https://itnext.io/reactive-angular-b7914b0190f5?source=rss-33d29fa205c4------2</link>
            <guid isPermaLink="false">https://medium.com/p/b7914b0190f5</guid>
            <category><![CDATA[azure-cognitive-service]]></category>
            <category><![CDATA[rxjs]]></category>
            <category><![CDATA[reactive-programming]]></category>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Pavel Tuzov]]></dc:creator>
            <pubDate>Mon, 11 Jan 2021 20:23:28 GMT</pubDate>
            <atom:updated>2021-01-11T20:23:28.725Z</atom:updated>
            <content:encoded><![CDATA[<p>This post is about reactive programming in Angular. On a practical example, we will discuss how to implement maintainable business logic using RxJs.</p><p>It is expected that you have experience with Angular and minimal experience with RxJs (subscribing to Observables).</p><p>The demo will show top 20 HackerNews stories with the corresponding links to the articles, HN comments and a <em>sentiment</em> analysis of the title.</p><p>We will first see how you can use Observables and wrongly believe you are <em>doing</em> reactive programming. Then we’ll surely see how to actually be reactive.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FWt4Kgl8okUdAdYpPEbTdw.png" /></figure><p>The source code is surely in GitHub: <a href="https://github.com/patuzov/reactive-angular">reactive-angular</a></p><h3>Reactive programming</h3><p>Without transforming it into a theoretical article on reactive programming, here are shortly two notions describing it:</p><ul><li>Asynchronous data streams</li><li>Propagation of change</li></ul><p>We will treat everything (data) as <strong>streams</strong>, be it mouse clicks, http calls or even string values. We will be defining these streams and busying ourselves describing how we will <strong>react</strong> when the data comes in the future — how the <strong>change</strong> will be <strong>propagated</strong> through those streams.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/422/1*j-SOtxql-Sqmvj0i0TWqMg.jpeg" /><figcaption>source: <a href="https://gist.github.com/staltz/868e7e9bc2a7b8c1f754">https://gist.github.com/staltz/868e7e9bc2a7b8c1f754</a></figcaption></figure><p>In Object Oriented Programming, for example, we have objects and their corresponding state. The whole logic is written around manipulating this state of the objects.</p><p>In Reactive Programming, we have streams of data instead. We are writing the logic that transforms the data that <strong>flows</strong> through streams, until it reaches its final desired state. The state is not being stored until then.</p><h3>Using RxJs the wrong way</h3><p>You know that Angular’s HTTP client, for example, is using RxJs (Observable), so, whether you want it or not, you are already, at least, touching the reactive programming paradigm.</p><p>Let’s see how we can make bad use of it.</p><p>A <em>bad</em> thing you could do is make the http call in your component code. You shouldn’t. You write the technical stuff (http) in services. Component should contain only the presentation logic. But you know it already and you are creating services that implement HTTP APIs. So let’s create our service that implements the <a href="https://github.com/HackerNews/API">Hacker News API</a>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/534351320bac725a1ce841021706f05b/href">https://medium.com/media/534351320bac725a1ce841021706f05b/href</a></iframe><p>In order to get details about the top stories, we’ll have to make two HTTP requests: get the ids of the stories and get the details for each id.</p><p>Here is how you could do it in your component:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c9944bbfdfe1543690a55db626fb1946/href">https://medium.com/media/c9944bbfdfe1543690a55db626fb1946/href</a></iframe><p><em>topNewsIds</em> returns the Observable that will obtain the ids of top 20 news, when they <em>come</em>. And when they <em>come</em>, we will iterate through them and, for each, get another Observable, which will obtain the details of the news (when they <em>come</em>).</p><p>Although you are using RxJs here, you are not <em>reactive</em>. You are implementing something similar to callbacks. Moreover, in this very simple example, you already have nesting (and we’ve just started).</p><p>Now, what do you do if you decide that you want to show only stories (no job, ask or show)? You simply filter:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8e3631b234e82e8d1ded97ae6a0b8ebb/href">https://medium.com/media/8e3631b234e82e8d1ded97ae6a0b8ebb/href</a></iframe><p>Are you reactive yet? No. You’re actually now on a track that leads to dark places. You are developing business logic in your component class. Because, you know, next comes the request to display the <em>sentiment</em> of the title — is it positive, negative or neutral news. How will you implement it? More nesting, more business logic in component? Will you still be able to keep track of what is going on there? What if you have a transient HTTP error when, say, getting story details? Will you be able to retry the request and continue?</p><h3>Reacting</h3><p>Using Observable (and Subjects), RxJs implements the observer pattern. Observable is our stream of data. But this is nothing new to you, right? Where RxJs gets cool, though, is its operators. That’s the <em>propagation of change</em> part of reactive programming.</p><p>Using RxJs operators you are describing your business logic. In a readable, maintainable way. You are building a <em>recipe</em> for what to do with data, when it <em>comes</em>, how to manipulate it until we get the desired form, the desired state of data.</p><p>Let’s, first of all, start building our business logic in a separate service, where it belongs. To make it simple in the beginning, we’ll refactor the getting story details part first:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8376dc0b6404a11d99524999836e4d87/href">https://medium.com/media/8376dc0b6404a11d99524999836e4d87/href</a></iframe><p>In this minimalistic example, beautiful things are already happening. First of all, notice the <em>pipe()</em>. The pipe will describe the flow of data. You will define your business logic inside the pipe. The <em>change</em> will be propagated through this pipe and, using RxJs operators, you will describe how the data will be changed.</p><p>Inside the pipe you can see the first RxJs operator — <em>filter</em>. When the data enters the pipe, here is how it will be changed — only news with type <em>story</em> will go down the pipe. All the rest will be filtered out, i.e. no values will be emited.</p><p>Notice that the filter operator gets the story as input, not an Observable. Again, it will be called <em>when the data comes</em>, so the story will be available. For now it’s just a <em>recipe</em>. Also, notice that the result of filter (whatever gets returned by the <em>story</em> method) is an Observable. The return value of operators is always wrapped in an observable.</p><p>By the way, you usually want to have filter up in the pipe, s.t. irrelevant data is not unnecessary manipulated before it gets filtered out.</p><p>If it helps you to visualize what the operators do, there are marble diagrams for this. For example for <a href="http://reactivex.io/documentation/operators/filter.html">filter</a>.</p><p>And back in component:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/542228b7ca582071f729adbbd0d70d68/href">https://medium.com/media/542228b7ca582071f729adbbd0d70d68/href</a></iframe><p>What we obtained is, again, extracted the business logic out of the component. Not much is happening here yet, but now we’re ready for the future. Like, for example, let’s create a Data Transfer Object for the story:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4c9458acf4cb68f4fd04106d0fe7cda8/href">https://medium.com/media/4c9458acf4cb68f4fd04106d0fe7cda8/href</a></iframe><p>And let’s transform whatever we get from the API to the model our application understands:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2a853fc12eb3829f658381d28fbf32f2/href">https://medium.com/media/2a853fc12eb3829f658381d28fbf32f2/href</a></iframe><p>And here is the second one — <a href="http://reactivex.io/documentation/operators/map.html"><em>map</em></a>. Map can transform the structure of data. In this case we get the story object and transform it to News object. And an Observable&lt;News&gt; flows down the pipe. Since there are no more <em>changes</em> to be done, this is what gets out of the pipe and this is what the <em>story</em> method returns.</p><p>Now you’re familiar with the two very popular operators. How do you like the pipe? Is it readable? Did you notice how easy we implemented a new feature request (the News DTO)? It was pretty clear where the logic for this belongs. And you can continue to manipulate the data down the pipe, when next feature request comes, like getting the <em>sentiment</em> of the title…</p><p><em>I’m using </em><a href="https://azure.microsoft.com/en-us/services/cognitive-services/"><em>Azure Cognitive Services</em></a><em> to get the sentiment of a text. This is out of the scope of this post. The code is to be found in the </em><a href="https://github.com/patuzov/reactive-angular/blob/master/src/app/cognitive.service.ts"><em>cognitive.service.ts</em></a><em>. You’ll have to add a cognitive.environment.ts file in the environments folder, that will contain the key and url. I surely didn’t include it in the repository. In the </em><a href="https://github.com/patuzov/reactive-angular/blob/master/src/environments/environment.ts"><em>environment.ts</em></a><em> you will see the structure of the cognitiveenv constant.</em></p><p>Having the <a href="https://github.com/patuzov/reactive-angular/blob/master/src/app/cognitive.service.ts"><em>CognitiveService</em></a><em>, </em>we can call its <em>sentiment</em> method (which, by the way, uses a pipe of its own) and get the sentiment as an Observable&lt;string&gt;. We could use again <em>map</em> to manipulate the structure of our data:</p><pre>map(story =&gt; this.cognitiveSvc.sentiment(story.title))</pre><p>But… The result of the <em>sentiment</em> method is an Observable&lt;string&gt;. And, remember, whatever gets out of the operator is wrapped in an Observable, so, in the end, we will obtain an Observable&lt;Observable&lt;string&gt;&gt;.</p><p>We have two problems here: outer Observable and the <em>string</em>. Let’s deal with Observable first.</p><p>There are, surely, flattening operators, that will <em>flatten</em> this structure into an Observable — exactly what we need. We will use mergeMap (or you will often find it by its alias — flatMap). There is an alternative — switchMap which has a small but important difference. Let’s leave understanding the difference as homework.</p><pre>mergeMap(story =&gt; this.cognitiveSvc.sentiment(story.title))</pre><p>Now, what will get out of the pipe will be an Observable&lt;string&gt;. String? What we need instead is update the story with the sentiment and send it down the pipe.</p><p>There are a couple of ways to solve this. One of them is defining a separate pipe for the <em>sentiment</em> stream, transform the story object using <em>map</em> and return the story object from that pipe (instead of simply the sentiment):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/604fb1b12349e61a7b6bb6d5e10561eb/href">https://medium.com/media/604fb1b12349e61a7b6bb6d5e10561eb/href</a></iframe><p>Easy to implement, we are already familiar with all the operators. The only thing I don’t like here is the nesting. But luckily, it’s still readable/maintainable at this point.</p><p>In order to avoid pipe nesting, we could use <a href="https://www.learnrxjs.io/learn-rxjs/operators/combination/forkjoin">forkJoin</a> to send both — sentiment and story down the pipe and then use a <em>map</em> to do that what we did in the nested pipe above. But, in my opinion, we would lose from <em>understandability</em> in such a pipe.</p><p>Wonderful! We keep adding features, by describing how we’ll <strong>react</strong> when the data goes through the pipe. The code keeps being readable and maintainable. The component has no idea about it and simply displays whatever stories it gets.</p><p>Now, what about those ids? Why does the component need to know how to get the ids and what to do about them? All it needs is to show top stories. That’s the logic it needs to implement.</p><p>We need to <em>incorporate</em> getting the ids in the business logic from the service — where it belongs. Here we have two very different options. The stream will either emit an array with 20 stories or it will emit each story one by one. I like the later approach for two reasons: we will not wait until we have the data for all stories and it fits well with the code that we already have (reacting to each id).</p><p>So, the idea is, when we get the array with ids, we will start sending them down the pipe one by one. Remember the mantra — <strong>everything is a stream</strong>?An array can also be a stream. <a href="http://reactivex.io/documentation/operators/from.html"><em>from</em></a><em> </em>is one operator that can transform an array to stream. It will then emit the values one by one. Not to confuse with <em>of</em> operator, which will emit the entire array as single value.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a7433f8e4a3562d0e95bc864ef300e97/href">https://medium.com/media/a7433f8e4a3562d0e95bc864ef300e97/href</a></iframe><p>Now our pipe begins with the ids and looks the same further down. This is the component’s code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/983ae99851d771c32f536eb77282b6e1/href">https://medium.com/media/983ae99851d771c32f536eb77282b6e1/href</a></iframe><p>Look at this code. It does only that what it has to do — deal with the presentation logic. It gets data from the service and displays it. No business logic, no technical stuff (except disposing of subscription when the component is being destroyed).</p><p>Take a moment to understand what this <em>news</em> object is. This is that sought for <em>final desired state</em>. <strong>It’s our only state</strong>. The entire business logic is stateless.</p><p>Business logic is described in the pipe. This is where, in our example, reactive programming happens. Reactive programming ends when you call <em>subscribe,</em> when you get the <em>desired</em> state of the data.</p><p>Let’s push it further. Yet another feature request comes. We want a filter that will show only positive news. It already answers which RxJs operator you will use for this. Easy, right? You know exactly where this change belongs. This is a sign of a maintainable code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xdJ8jsiwBZ6qK_AKKXFQzA.png" /></figure><h3>Conclusion</h3><p>There is a lot left to cover in terms of what RxJs can offer, like error handling, retrying (you’ve got it — there are operators for this that fit in the same programming style), merging streams and cold vs hot observables. But the main point of this post is to focus on how you can write maintainable code using RxJs.</p><p>RxJs fits nicely with Angular, as some of its modules are based on RxJs. Like, for example, the ActivatedRoute. Look at the <a href="https://github.com/patuzov/reactive-angular/blob/master/src/app/reactive/reactive.component.ts">component code</a> which implements the positive news filter. The url fragment <strong>is</strong> also <strong>a stream</strong>. We don’t subscribe right away to it in order to get the state of the url fragment and then do something with it. Instead we <strong>describe</strong> how we will <strong>react</strong> when it changes. We will manipulate the fragment based on our needs, we will create some side effects (tap operator) by reseting the stories array and we will get the stories based on our filter. It all starts with the url fragment being changed and ends with the final news object. No state inbetween.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/12a13228af18c1d814bff4bc6a97bcf0/href">https://medium.com/media/12a13228af18c1d814bff4bc6a97bcf0/href</a></iframe><p>I wish, though, that Angular gets more <strong>reactive</strong> at its core (since they decided to go this path anyway). For example, when the filter checkbox value is changed, we are handling this event in a callback. Wouldn’t it be nice if we got the checkbox values as a stream? There are actually tricks to do it (using the <a href="https://www.learnrxjs.io/learn-rxjs/operators/creation/fromevent">fromEvent</a> operator), but, in terms of Angular, it’s more of a workaround.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b7914b0190f5" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/reactive-angular-b7914b0190f5">Reactive Angular</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[So how do Kubernetes Services work?]]></title>
            <link>https://medium.com/@paveltuzov/so-how-do-kubernetes-services-work-1594f4b71b89?source=rss-33d29fa205c4------2</link>
            <guid isPermaLink="false">https://medium.com/p/1594f4b71b89</guid>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[networking]]></category>
            <dc:creator><![CDATA[Pavel Tuzov]]></dc:creator>
            <pubDate>Wed, 09 Dec 2020 08:40:54 GMT</pubDate>
            <atom:updated>2020-12-09T08:40:54.729Z</atom:updated>
            <content:encoded><![CDATA[<p>I mean those Kubernetes objects, not the <a href="https://azure.microsoft.com/en-us/services/kubernetes-service/">Azure Kubernetes Service</a>.</p><p>This is what we’ll go through:</p><ul><li>Why do you even need Services?</li><li>Service types (ClusterIP, NodePort, LoadBalancer)</li><li>What does a LoadBalancer service <em>loadbalance</em>?</li><li>iptables: Aha!</li></ul><h3>Addressing pods or why do you even need services</h3><p>So your application is running in kubernetes. It’a s pod. The pod has an IP Address. Like 10.244.1.3. There is another pod. It has to make an HTTP request to the initial pod, so it has to know its IP. Like <a href="http://ip1./"><em>http://10.244.1.3</em>.</a> But it’s a bad idea…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/984/1*7kAOqcPsrgTMpco4t9xTtA.png" /></figure><p>You know, pods are <em>mortal</em>. You might have heard that pods are cattle. You won’t take care of each one in part. Pods will die and they will be replaced.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y2RjPxjyOcPofmhUR-KlHA.png" /></figure><p>When a pod dies, it does it for good. It never comes back. If you deployed your application correctly and the pod was managed by a ReplicaSet, a <strong>brand</strong> <strong>new</strong> pod will come up with a new IP address. So your <a href="http://10.244.1.3/"><em>http://10.244.1.3</em></a> will not work now.</p><p>Moreover, what if you scaled your application and now you have two pods with two IP addresses — 10.244.1.3 and 10.244.0.9? Well, what’s even the point, if you only make a request to <a href="http://ip1./"><em>http://10.244.1.3</em></a>? Or did you have a plan how to distribute the traffic?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/978/1*j8zFEbMOJ2O5ZMlPoxy7iQ.png" /></figure><p>Services will cover you. Services will track the IPs of the pods and services will split the traffic. That’s why you need them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/574/1*igy2ZLw1iZ6t4kqd0jplSg.png" /></figure><p>While pods are <em>cattle</em>, services are <em>pets</em>. You take extra care of each of them. They get a <em>static</em> IP, that is, it doesn’t change. Moreover, they get a DNS name. Say you have a service named <em>the-service</em> for your application. Your http request will be<em> </em><a href="http://the-service/"><em>http://the-service</em></a><em> </em>(inside the same namespace).</p><p>You connect services with pods via labels. On one side you have pods with labels, on the other you have services with <em>label selectors.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/930/1*Nb44m_GB96mDjoJ2GCHG8A.png" /></figure><p>Now the <em>the-service</em> will redirect the traffic to all pods that have label <em>app=app.</em> Be careful how you define your label selectors! They have to uniquely identify exactly the application (pods) you intend to.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W3BrCKaQVOfxefNvDRWXRw.png" /></figure><p>But here is a thing: services don’t know about pods. Services know about <em>endpoints</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/682/1*zhD1_eFaJ34NkK_EpOnT_Q.png" /></figure><p>If you scale your pods, the endpoints will be automatically updated. If your pod, for example, is failing the readiness probe, it’s IP will be automatically removed from the endpoints. All taken care of by kubernetes! You simply define your label selectors, relax and enjoy.</p><h3>Service types</h3><p>In previous section we saw a <em>ClusterIP</em> service. It gets an IP address internal to cluster. You can’t access it from outside. You use it only for <em>internal</em> communication between pods.</p><p>If you need to access your pods from the <em>outside</em>, you define a <em>NodePort</em> service.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nFIFlBGFpo_5iu-RnHwG3Q.png" /></figure><p>It opens a port on the node and you can now access the application by making a request on <em>10.240.0.4:31380 or 10.240.0.5:31380.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2E6XxwjhvSgZPloPGpw6gQ.png" /></figure><p>But you need to know those Node IPs.</p><p>Instead, you could use a service of type <em>LoadBalancer. </em>It will create a load balancer (if you’re in cloud), that will distribute the traffic among those nodes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JUFlT-45v8YE1_YDuvx1wA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Agikf2Q-x_asMJ2VVHaiwg.png" /></figure><p>Azure, for example, will automatically create a public IP address (unless you want an internal one) and now your application is available to the public.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A9UgsTpKKzPTyx-3CSfAtg.png" /></figure><p>Notice how the node port (31380) and the cluster IP (10.0.151.145) are still there? They all build upon each other.</p><p>So now you know why it’s called <em>LoadBalancer</em> service. Has nothing to do with <em>balancing</em> <em>load </em>between multiple replicas of pods.</p><p>Speaking about distributing traffic among pods — how it actually works? And how come you can access the service on both nodes?</p><h3>iptables</h3><p>Here is the thing: services don’t run on nodes. Moreover, services don’t run. It’s not an application. It’s just a configuration. What happens on the nodes though, is linux iptables being updated. For each service’s endpoint there will be an entry <em>ServiceIp — EndpointIp</em>. On all nodes!</p><p>When a request comes to <em>ServiceIp</em>, it will be redirected to one <strong>random</strong> <em>EndpointIp</em> (using iptables), regardless to which node the load balancer sent the request. This is why iptables on all nodes will have the same content. When load balancer has to choose between two nodes, it will do it simply in round-robin fashion. The load balancer surely has no idea where the pod is running. Any node will be able to take care of it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tYejWQlK_2CdfIFW7C-0MQ.png" /></figure><p>This means that the traffic might land on the node that doesn’t have the pod and it will be then redirected to the correct node. You’ll have that extra <em>hop</em> and it will actually be often the case. And that’s intended design.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u5bLlFW7U66ae9sI7twF7g.png" /></figure><p>In a nutshell, this is what you need to know about kubernetes services:</p><ul><li>You don’t address pods directly. You do it via services.</li><li>There are different types of services (for internal and external access)</li><li>Services track a list of Endpoints</li><li>Service is not an application — it’s just a configuration</li><li>Redirecting traffic to a specific pod is done on OS level using iptables</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1594f4b71b89" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Create a “Fully private” AKS infrastructure with Terraform]]></title>
            <link>https://itnext.io/create-a-fully-private-aks-infrastructure-with-terraform-e92358f0bf65?source=rss-33d29fa205c4------2</link>
            <guid isPermaLink="false">https://medium.com/p/e92358f0bf65</guid>
            <category><![CDATA[azure-kubernetes-service]]></category>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[terraform]]></category>
            <dc:creator><![CDATA[Pavel Tuzov]]></dc:creator>
            <pubDate>Wed, 24 Jun 2020 15:37:00 GMT</pubDate>
            <atom:updated>2020-06-24T18:55:25.257Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7QavgNbE9if9GqlZ8Y0dJg.png" /><figcaption>Infrastructure from https://medium.com/@denniszielke/fully-private-aks-clusters-without-any-public-ips-finally-7f5688411184</figcaption></figure><p>In Azure you can <a href="https://docs.microsoft.com/en-us/azure/aks/private-clusters">create a <strong>private </strong>AKS cluster</a>, in which the traffic between the node pools and the API server does not leave the private network. But often, making only the communication between nodes and the control plane private is not enough for your security needs. In a <em>fully</em> private cluster you also want to not expose and use public IPs.</p><p>Such an architecture is described in details in this article:</p><p><a href="https://denniszielke.medium.com/fully-private-aks-clusters-without-any-public-ips-finally-7f5688411184">Fully private AKS clusters — without any public ips — finally!</a></p><p>Here I will describe the Terraform script which will manage the exact infrastructure as in the above post. I will explain only occasionally why we need the different Azure resources, so you probably want to read Dennis’s article first.</p><p>I find this project also a very good example to practice different Terraform features:</p><ul><li>organizing the project into modules</li><li>defining terraform and provider versions</li><li>type constraints</li><li>each and for_each expressions</li><li>functions</li><li>defining explicit dependency</li><li>and even using provisioners!</li></ul><p>The sources can be found in this repository: <a href="https://github.com/patuzov/terraform-private-aks">https://github.com/patuzov/terraform-private-aks</a></p><h3>Resource groups</h3><p>There will be two separate resource groups for the hub and spoke networks. So, here they are in the <em>main.tf, </em>along with the<em> terraform </em>and <em>provider </em>blocks.</p><p><em>Note, we will need azurerm provider starting with version 2.5, as this is when the </em><strong><em>outbound_type </em></strong><em>argument was introduced for AKS cluster resource.</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/602b03305e7b4cd67913d518541a6c66/href">https://medium.com/media/602b03305e7b4cd67913d518541a6c66/href</a></iframe><pre>terraform init<br>terraform apply</pre><p>…and we can see our two resource groups in the Azure Portal.</p><h3>Networking</h3><h4>VNETs, Subnets</h4><p>As for the networks, we will need a VNET and one or more SUBNETs for both: hub and spoke. This is a great opportunity to use <strong>Terraform Modules</strong>. Using modules, you can hide complexity and, most importantly, reuse code in Terraform.</p><p>We will create a <em>modules </em>folder and a <em>vnet </em>folder inside it, with all the usual files for a module: <em>main.tf, variables.tf, outputs.tf.</em></p><p>There is nothing fancy for the virtual network resource. Just set the values provided via the input variables:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3b8995ba2211f86e549b0c55473f72d3/href">https://medium.com/media/3b8995ba2211f86e549b0c55473f72d3/href</a></iframe><p>Now we might want to create a list of subnets in this vnet and we need to receive following input values for each subnet: name and the IP address range. We could receive as input a list of objects containing this information:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1e5fc53ee76c86b655f0b5397fd72f5e/href">https://medium.com/media/1e5fc53ee76c86b655f0b5397fd72f5e/href</a></iframe><p>…which, in my opinion, makes sense for the <em>interface </em>of this module.</p><p>For each such object a subnet resource can be created, using the <a href="https://www.terraform.io/docs/configuration/resources.html#for_each-multiple-resource-instances-defined-by-a-map-or-set-of-strings"><em>for_each</em></a> expression. But this expression expects either a list of strings or a map. So we’ll have to transform our list of objects to a map. <em>for </em>expression comes to the rescue:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2899383091ab68d3169ce1628b661f31/href">https://medium.com/media/2899383091ab68d3169ce1628b661f31/href</a></iframe><p>The <em>for </em>expression will create a map with <em>subnet.name</em> as keys and <em>subnet.address_prefixes</em> as corresponding values. For each such key/value pair, an <em>azurerm_subnet </em>resource will be created.</p><p>From this module, we will need vnet and subnet IDs. We define this in the <em>outputs.tf</em>. The same <em>technique</em> with the <em>for</em> expression is used to get back the subnet IDs as a map:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/63ed9be197c87c6af91fb5e30a712809/href">https://medium.com/media/63ed9be197c87c6af91fb5e30a712809/href</a></iframe><p>Finally, we make use of this module in our <em>main.tf</em>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1b63eda65ba43d164ba26696d760378b/href">https://medium.com/media/1b63eda65ba43d164ba26696d760378b/href</a></iframe><p>You need to run terraform init again to initialize the new module. After that you can <em>apply</em> and the VNETs are in the portal as well, under the corresponding resource groups.</p><h4>Peering</h4><p>Now we need to peer the VNETs. The <em>azurerm </em>provider has the <em>azurerm_virtual_network_peering</em> resource. But, as the peering will have to be done both ways, it’s better to abstract this in a new module.</p><p>Here is the very simple module’s <em>main.tf </em>code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b99ae5275412729ed832645ed7f53a52/href">https://medium.com/media/b99ae5275412729ed832645ed7f53a52/href</a></iframe><p>And this is how we use it:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c6b1da02ad694d12aad8083e5b58e68b/href">https://medium.com/media/c6b1da02ad694d12aad8083e5b58e68b/href</a></iframe><p><em>Note how we use outputs of one module as inputs for the other.</em></p><p>Don’t forget to terraform init, in order to initialize the new module.</p><p>If you apply this configuration, you will see the <em>Peerings </em>settings under both VNETs.</p><h4>Firewall</h4><p>An Azure Firewall will need a public IP and we’ll also configure the exceptions for all the <em>external access</em> AKS needs in order to function properly (like pulling images or OS updates). So why not hide it all into yet another module?</p><p>Here is the code for the public IP, firewall itself and an example of a network rule for the <em>aks basics</em> (there are more rule collections defined — see the <a href="https://github.com/patuzov/terraform-private-aks/blob/master/modules/firewall/main.tf">git repo</a>)<em>:</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7cd93e040b61014493de8feeb0d8eb40/href">https://medium.com/media/7cd93e040b61014493de8feeb0d8eb40/href</a></iframe><p>Now we can use the module:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/234dd966742d70834fdfed6be2741fac/href">https://medium.com/media/234dd966742d70834fdfed6be2741fac/href</a></iframe><p><em>Note how we get the Azure Firewall Subnet ID from the network module’s output.</em></p><h4>Route Table</h4><p>Finally, we’ll create a user defined route to force all traffic (0.0.0.0/0) from the AKS subnet to the firewall (specifically, to its private IP). For this, we need to create the route table with the corresponding route and associate it to the AKS subnet. And, yes, we’ll create a new module for this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d195d621d85299d05eb500fa4c362702/href">https://medium.com/media/d195d621d85299d05eb500fa4c362702/href</a></iframe><p>And use the module:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bb151b8ceaea6a42d6c974f2c173887a/href">https://medium.com/media/bb151b8ceaea6a42d6c974f2c173887a/href</a></iframe><h3>AKS</h3><p>We are finally ready to define the AKS cluster!</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/11f7d5b1e6f0ab5882bd17b327f759c8/href">https://medium.com/media/11f7d5b1e6f0ab5882bd17b327f759c8/href</a></iframe><p>There are 2 important things to mention here:</p><ul><li>Enabling the actual private AKS cluster feature: private_cluster_enabled = true. This will also create a <em>Private DNS Zone </em>resource, which will have an <em>A Record</em> pointing to the <strong>private </strong>IP address of the API, allowing <em>everyone</em> from the AKS VNET (Spoke) to resolve the control plane’s address.</li><li>Setting <em>outbound type</em> to <em>userDefinedRouting</em>, which will prevent creating a public IP for the cluster’s egress traffic and make use of the “user defined” Route Table: outbound_type = &quot;userDefinedRouting&quot; .</li></ul><p>Also, did you notice the depends_on argument? Terraform can identify if a resource depends on another. For example, in order to deploy this AKS cluster in the “aks-subnet” subnet, Terraform knows it has to create the vnet and subnet first. These are the <em>implicit</em> dependencies. If Terraform doesn’t <em>see</em> dependencies between resources, it will [luckily] create them in parallel.</p><p>But in our case, as we set the <em>userDefinedRouting </em>outbound type, AKS will expect to have a route table associated with its subnet, so it actually depends on the route table resource. We can let Terraform know about this dependency by <em>explicitly</em> defining it with the depends_on argument.</p><p>Also, because of the still <a href="https://github.com/Azure/AKS/issues/1557">unresolved issue</a>, we need to allow the created Service Prcinipal (by the managed identity) to edit the user defined routes in the route table from the <em>vnet</em> resource group, by defining the <em>azure role assignment.</em></p><p>And we’re done! We now have an AKS cluster, in which the API doesn’t have a public endpoint and communicates with the nodes only through the Azure Backbone. The cluster also doesn’t expose and doesn’t use any public IPs (except those that we allowed it to).</p><h3>Jumpbox</h3><p>The problem is, since the control plane doesn’t expose any public endpoint, you will not be able to manage your cluster, say, with kubectl from your local machine, or even <a href="https://docs.microsoft.com/en-us/azure/aks/private-clusters#limitations">from the Azure DevOps pipelines</a> (if you’re using Microsoft-hosted agents).</p><p>Remember the <em>Private DNS Zone</em> from the previous step? Only the Spoke VNET can resolve the API. But we can link other VNETs too. So, let’s create a (Linux) Virtual Machine in the Hub VNET, install kubectl on it and link the VNET in the Private DNS Zone.</p><p>No surprises here: I’ll <em>hide </em>it all in a separate module.</p><p>I’ll skip all the declarations for public IP, network security group, etc. You can find them in the <a href="https://github.com/patuzov/terraform-private-aks/tree/master/modules/jumpbox">github repo under <em>jumpbox </em>module</a>. Here are the most important things:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/540eb8ff9ab99a5b96efed3226bc2a63/href">https://medium.com/media/540eb8ff9ab99a5b96efed3226bc2a63/href</a></iframe><p>For this demo I’ll create a random password for the VM admin (using Terraform’s <em>random_string </em>resource) and show it in the terraform output, so that I can later ssh to the VM.</p><p>Probably you noticed a block in the VM resource which is a <em>taboo </em>in Terraform: <a href="https://www.terraform.io/docs/provisioners/index.html"><strong>remote-exec provisioner</strong></a>. Terraform provides them and kindly asks you not to use them. But, in this case, it fits perfectly! We’re spinning up this VM just to test that we can connect to the control plane with kubectl from our private network. And, being lazy to do it manually, I’ll let the provisioner automatically install kubectl and azure cli when it creates the VM.</p><p>As mentioned previously, we also need to link the hub VNET to the Private DNS Zone (which is automatically created with the AKS cluster). We can easily achieve this with the <em>azurerm_private_dns_zone_virtual_network_link </em>resource.</p><p>From this module, we will need the following information:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/24c6be01b294e3686cbac95a64d31bd1/href">https://medium.com/media/24c6be01b294e3686cbac95a64d31bd1/href</a></iframe><p>To use this module, we have a challenge: getting the Private DNS Zone’s name. It is generated automatically by Azure when the private AKS cluster is created (it’s not directly maintained by Terraform) and it even contains a GUID in it:</p><p><em>9c3df69f-b281–42ef-9996–89941b484906.privatelink.westeurope.azmk8s.io</em></p><p>Fortunately, it’s not that random. If you look at the private FQDN of the API, you will see this:</p><p><em>private-aks-7b099028.</em><strong><em>9c3df69f-b281–42ef-9996–89941b484906.privatelink.westeurope.azmk8s.io</em></strong></p><p>And this information is known by Terraform. We just need to extract the private DNS Zone’s name from it, using various Terraform functions: <em>join, slice, split </em>and <em>length:</em></p><pre><strong>join</strong>(“.”, <strong>slice</strong>(<strong>split</strong>(“.”, azurerm_kubernetes_cluster.privateaks.private_fqdn), 1, <strong>length</strong>(split(“.”, azurerm_kubernetes_cluster.privateaks.private_fqdn))))</pre><p>This is how the module is used:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b30bf230d9cedda45e9c02894b7cb332/href">https://medium.com/media/b30bf230d9cedda45e9c02894b7cb332/href</a></iframe><p>Lastly, we want to define our outputs:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e5fac2880fba0736c2e83df1233c645d/href">https://medium.com/media/e5fac2880fba0736c2e83df1233c645d/href</a></iframe><p>After applying the entire configuration, we get an output like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/788/1*B2SxN7LEpc7XJbfSDQe-qA.png" /><figcaption>Terraform output</figcaption></figure><p>Now we can ssh into the Linux VM with kubectl and azure cli already installed. All what’s left is <a href="https://docs.microsoft.com/en-us/cli/azure/authenticate-azure-cli?view=azure-cli-latest#sign-in-interactively">authenticating with Azure</a>, <a href="https://docs.microsoft.com/en-us/cli/azure/aks?view=azure-cli-latest#az-aks-get-credentials">getting the configuration for kubectl</a> and we can connect to the API:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/971/1*AW6zSyYj4vHC87if_GdY5A.png" /><figcaption>Using kubectl with a private AKS cluster</figcaption></figure><p>The traffic from the pods will be redirected to Azure Firewall and corresponding rules will be applied. Let’s check it.</p><p>In the <em>firewall </em>module, a <em>test</em> rule is defined, which will allow traffic to <em>bing.com</em>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a499d6b3b58fea9706fb909c692d6954/href">https://medium.com/media/a499d6b3b58fea9706fb909c692d6954/href</a></iframe><p>Let’s create a pod and try to make a couple of requests from its container:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7AbwOCEaquKJ_yrCa3ODzg.png" /><figcaption>Making external http requests from a container</figcaption></figure><p>Exactly what we wanted to achieve: external traffic is blocked, unless we have explicit rules to allow it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e92358f0bf65" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/create-a-fully-private-aks-infrastructure-with-terraform-e92358f0bf65">Create a “Fully private” AKS infrastructure with Terraform</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>