<?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 Bharat Raj Meriyala on Medium]]></title>
        <description><![CDATA[Stories by Bharat Raj Meriyala on Medium]]></description>
        <link>https://medium.com/@bharatrajmeriyala?source=rss-b2786bb31675------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*CZyCfkZGPopVAD_qwaSTOw.jpeg</url>
            <title>Stories by Bharat Raj Meriyala on Medium</title>
            <link>https://medium.com/@bharatrajmeriyala?source=rss-b2786bb31675------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 00:34:06 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@bharatrajmeriyala/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[Node JS Event loop Craziness you may not know!]]></title>
            <link>https://medium.com/@bharatrajmeriyala/node-js-event-loop-craziness-you-may-not-know-a7ef546d47be?source=rss-b2786bb31675------2</link>
            <guid isPermaLink="false">https://medium.com/p/a7ef546d47be</guid>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Bharat Raj Meriyala]]></dc:creator>
            <pubDate>Sun, 14 Apr 2019 17:35:14 GMT</pubDate>
            <atom:updated>2019-04-16T13:39:37.756Z</atom:updated>
            <content:encoded><![CDATA[<h4>How does NodeJS work?</h4><p>From w3schools website, Node.js is single-threaded, non-blocking &amp; asynchronous programming model.</p><p>Non-blocking and asynchronous are good to have features any given day, but if NodeJS is single threaded aren’t we missing out on fully utilizing the capabilities of most modern processors which are multicore and multithreaded in nature?</p><p>The answer is both yes and no. Node is single threaded by design. That means when we fire up the command like this:</p><blockquote>node server.js</blockquote><p>The task manager on windows will show a single process called node, and inside this process we have a single thread on which our program code is running.</p><p>So, how does NodeJS become efficient this way?</p><p><strong>Event Loop</strong></p><p>The key to make the Entire NodeJS efficient basically is this concept of Event loop. Lot of people have tried to explain Event loop in their own way, but the fact is Event loop doesn’t run in a separate thread of its own. Event loop is like a main program(Or brain for human body) for NodeJS, executing our userland code written in server.js as part of its execution. But the key to understand is, this Event loop is single threaded.</p><p><strong>Phases in Event loop</strong></p><p>For the sake of understanding, we can say, as soon as we fire node command, a single thread of Event loop starts, which picks up the javascript code written in server.js and starts executing it immediately. But during our execution of Event loop detects the presence of callbacks written inside</p><ol><li>setTimeout(), setImmediate() &amp; setInterval(). The are standard javascript functions, that help us execute code at some later point of time.</li><li>OS tasks like waiting on server port for some incoming connection requests.</li><li>Long running tasks like FS modules performing I/0 operations.</li></ol><p>Now this is where the entire crux of Event loops lie. So as previously said, event loop, will first execute entire userland code, and then execute whatever code is inline and at the same time, divides all our callback functions in various phases.</p><p>During First phase, Node looks at pending timers and sees if any callback functions are ready to be called. These timer functions include the setTimeout() and setInterval().</p><p>During second phase, Node looks at pending OS tasks(like server port waiting) and other long running tasks (like FS module file I/O) and calls relevant callbacks if they are finished.</p><p>After the first 2 phases, Node moves on to third phase where it will start polling to check if, and pending OS task is completed OR long running task is completed OR a timer is about to be completed.</p><p>Once the polling finishes and node determines its time for breaking this brief pause, it moves onto execute callback functions set under setImmediate().</p><p>At the end of all 4 phases, in the fifth and final Node will continue try to call any close events. All the above 5 phases run in one single tick.</p><p><strong>Who performs these long running tasks?</strong></p><p>The most important phase in the above 5 steps is phase 2, when Node will look at pending OS tasks and other long running tasks. Usually these are tasks which are most time consuming and resource heavy. So how does Node with its single thread model ensure that these tasks are performed in non-blocking asynchronous fashion?</p><p>This is performed with a help of special library called libuv. <strong>libuv</strong> (Unicorn Velociraptor Library) is a multi-platform C library that provides support for asynchronous I/O based on event loops. A good understanding of libuv is critical in solving the performance behavior problems in event loops. <em>libuv is a library which is used by NodeJS to perform all the operating system related tasks like disk I/O or long running tasks but not Network related tasks. </em>In other words, whenever NodeJS sees any logic which requires OS resource interactions it is assigned to libuv. Libuv is multithreaded in nature and starting a instance of node with command,</p><blockquote>node server.js</blockquote><p>will start by default 4 threads of libuv which are ready to accept the long running requests from Node. So in simple terms even though Node is single threaded the node modules like FS, crypto modules on which it depends make use of libuv library which is multithreaded. It is also possible to increase or decrease the no of threads that libuv creates by default through a single variable like this at the top of our server.js file.</p><blockquote>process.env.UV_THREADPOOL_SIZE = 5;</blockquote><p>The above statement basically creates 5 threads of libuv that are waiting for requests from NodeJS.</p><p><strong>Is this the End?</strong></p><p>So yeah, multi threaded libuv, single high performing Event loop and NodeJS is looking easy. Well, not quite!</p><p>Not everything is handled by libuv threads in NodeJS. For some of the tasks, NodeJS will depend on Operating system async handlers as well. In such cases, it is the responsibility of Operating system to perform the threading as required and provide the results back. But the work of coordinating with Operating system async helpers is still performed with the libuv library and invoked by NodeJS. There is no change to that.</p><p>The next obvious question is what modules are dependent on OS async helpers than thread pool of libuv. We can safely assume that almost everything around networking for all Operating systems, use the OS async helpers. The Event loop would deal with these OS async helpers in the same it waits for the response from the default threads of libuv.</p><p>To take this further, I wrote a simple nodejs program, that performs a simple HTTPS request first, then calls a special Hashing function called as pbkdf2.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/421/1*X3fvIAvA4_CxZyliSxAKWw.png" /></figure><p>In the above example, <strong>we are using pbkdf2 function of crypto module, which is explicitly known to use libuv threads</strong>. For more details on my statement, you can visit the node_crypto.cc file inside the NodeJS github source code.</p><p><a href="https://github.com/nodejs/node/blob/master/src/node_crypto.cc">https://github.com/nodejs/node/blob/master/src/node_crypto.cc</a></p><p>We are doing a network operation and a File operation and a doHash() operation. Lets see the output of this file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/127/1*MrCz5vdpheOY_pI0R9WnAg.png" /></figure><p>The above results state that doReques() which is purely a task that requires network is taking 5455 ms units of time for completion, unlike hash function and FS module which are directly the responsibility of libuv threads. Why is it that doRequest that does not depend on libuv threads taking a time equal to that of tasks that are dependent on libuv threads?</p><p>The reason for that is, even though when it comes to Network I/O libuv passes it on to operating system threads to return the results, the dns.lookup() operation is still performed by libuv threads. For more details see this video:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gN6sMWdye2mP_WP-kH7wFA.png" /></figure><p>The link to the entire amazing video is as below:</p><p><a href="https://www.youtube.com/watch?v=P9csgxBgaZ8&amp;feature=youtu.be&amp;t=17m28s">https://www.youtube.com/watch?v=P9csgxBgaZ8&amp;feature=youtu.be&amp;t=17m28s</a></p><p>So, If I change the above code to this as per the suggestion:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/423/1*_BuLJUhFiuuAmqLiaYdlKw.png" /></figure><p>Basically replacing the google.com with IP address of google servers and voila!!! the output changes as below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/117/1*5-hB1W_UH_LwRAYhHrGY8w.png" /></figure><p>A simple point that, doRequest() has moved onto top of the results because it is rightfully the first function to execute and complete!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a7ef546d47be" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Spring Cloud Security with Netflix Zuul]]></title>
            <link>https://medium.com/@bharatrajmeriyala/spring-cloud-security-with-netflix-zuul-2ef04a1dcfb?source=rss-b2786bb31675------2</link>
            <guid isPermaLink="false">https://medium.com/p/2ef04a1dcfb</guid>
            <category><![CDATA[zuul]]></category>
            <category><![CDATA[microservices]]></category>
            <dc:creator><![CDATA[Bharat Raj Meriyala]]></dc:creator>
            <pubDate>Sun, 02 Dec 2018 09:37:29 GMT</pubDate>
            <atom:updated>2018-12-02T13:55:50.677Z</atom:updated>
            <content:encoded><![CDATA[<p>Microservices and cloud micro-functions are the 2 best things to happen in computer programming history since C programming. Both of these are changing the way we design and architect our systems for high availability, fault tolerance, smaller DevOps cycles and of course for following the basic principles of following KISS(Keep it simple stupid) in computer programming.</p><p>Here I will touch upon, managing the security of a microservice based application using Netflix zuul. The entire code for this article can be found at this Github link:</p><p><a href="https://github.com/BharatRajMeriyala/SpringCloudSecurity">BharatRajMeriyala/SpringCloudSecurity</a></p><p>Any microservices design these days requires us to have multiple individual services, that are designed to a specific task. Among these following are very important:</p><ol><li>A load balancer: This piece of software is generally responsible for distributing the load among multiple endpoints, without we hardcoding the endpoints. For example if we have 2 endpoints as <a href="http://localhost:8080/">http://localhost:8080</a> and <a href="http://localhost:8081,">http://localhost:8081,</a> without a load balancer, we would have to hardcode this list somewhere. With a load balancer in place we wouldn’t have to do that.Ribbon, is one of the famous Spring security solution for load balancing.</li><li>A network discoverer: For a load balancer to automatically route all its requests to endpoints, we would want a network discovery software. The network discoverer would usually register any new instance coming up. The load balancer can then contact the network discoverer to find out the available endpoints and route its requests based on a round robin mechanism. Eureka is the most preferred network discoverer and Ribbon is designed to work with it seamlessly, when used with Feign.</li><li>API Gateway: API Gateway is a critical piece of software required to route requests inside our microservices network. An API Gateway like zuul, sits on top of Eureka, where it registers itself and is available for all the requests.</li></ol><p>A simple illustration of zuul Gateway is as follows:</p><p>Assuming, zuul is running at <a href="http://localhost:8765,">http://localhost:8765,</a> a typical request to zuul gateway url scheme looks like this:</p><p>&lt;Gateway-URL&gt;/&lt;Service-name&gt;/handler-path</p><p>The above scheme can be understood with following example:</p><p>Say we have hosted a microservice(my-microsvc) that works for a following URL:</p><p><a href="http://localhost:8100/currency-converter-feign/from/USD/to/INR/quantity/2">http://localhost:8100/</a>basepath</p><p>Then the same can be called with zuul gateway like this:</p><p><a href="http://localhost:8765/my-microsvc/basepath">http://localhost:8765/my-microsvc/basepath</a></p><p>So we are appending the microservice name in the URL.</p><p>This is amazing because this way we can solve all our inter microservice communication through Gateway, without knowing a lot of details. An API Gateway can also be used for advanced features like Rate-limiting, shared sessions or security as well. In this article we see more of this security that can be possible.</p><p>A beautiful Udemy course is available for those who want more details and see things in action:</p><p><a href="https://www.udemy.com/microservices-with-spring-boot-and-spring-cloud/learn/v4/overview">https://www.udemy.com/microservices-with-spring-boot-and-spring-cloud/learn/v4/overview</a></p><p><strong>Spring Security with Zuul</strong></p><p>A suggested before, I have already placed the code in github repo. I would suggest to clone the repo and run the services one by one before going ahead.</p><p><em>api-gateway service</em></p><p>gateway.Application → We are enabling the zuul proxy configuration here</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/419/1*Kv-qt4Ttf_BsWisY4WuRSw.png" /></figure><p>gateway.SecurityConfig → Following the general principles of spring security, lets have a Spring Security configuration by extending the <a href="/service/eclipse-javadoc:%E2%98%82=api-gateway/%5C/Users%5C/bharat%5C/Documents%5C/apache-maven-3.6.0%5C/repo%5C/org%5C/springframework%5C/security%5C/spring-security-config%5C/4.2.2.RELEASE%5C/spring-security-config-4.2.2.RELEASE.jar%3Corg.springframework.security.config.annotation.web.configuration(EnableWebSecurity.class%E2%98%83EnableWebSecurity%E2%98%82WebSecurityConfigurerAdapter">WebSecurityConfigurerAdapter</a> base class and overriding individual methods. In this case we will override configure mehod.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/716/1*kOTUNduIPA15z27priGGHg.png" /></figure><p>All we are doing here is basically, allowing a passthrough for /login URL and forcing the authentication of other URL. The important thing to note here is presence of addFilterAfter.</p><p>The addFilterAfter will basically, ensure JwtTokenAuthenticationFilter is executed before performing any validation, including the /login we are going to talk about.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/859/1*JnqkW5UahF6vH0xLkN2cMw.png" /></figure><p>The above filter basically does 3 things:</p><ol><li>Parse the JWT present inside the request header. I have used jjwt from Maven Central for JWT tokens.</li><li>Fetch the claims present inside the parsed JWT token.</li><li>Finally set the security context so that it is available for the requests downstream.</li></ol><p>The most important thing to note in the above, configure method is that we are allowing /login to pass through without any authentication. This is logical because we do not want the token authentication to pitch in at this point of time. And performing null checks at the filter level to ensure we do not get exception for case of /login.</p><p>for /login to reach the other service auth-center, we will define the following in application.yml file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/338/1*xl2875rGp7PKiIVxqjz6rg.png" /></figure><p><em>auth-center</em></p><p>This service is designed basically to generate the auth tokens after validating the username and password passed.</p><p>As usual, we will define a security configurer that looks like below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/801/1*Abh4v_y4pg0rhkET6jV3Yw.png" /></figure><p>Here I am using inMemoryAuthentication but we can use any authentication including that of JDBC to determine if the username and password are correct.</p><p>At the same time, we are also performing, JwtUsernamePasswordAuthenticationFilter filter that basically, generates a signed JWT token with all the claims, and places the same inside the body of the response to be used by the subsequent requests. I have used AbstractAuthenticationProcessingFilter for this purpose, which requires us to override 2 methods.</p><ol><li>attemptAuthentication: The one which performs the actual Authentication. Remember a fact that, these username and password are compared against what we configured in the previous configure method.</li><li>successfullAuthentication.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/873/1*NSU7dXtHmicnN-Vl5rILRw.png" /></figure><p><em>backend-service</em></p><p>This is a simple SpringBootapplication with a restcontroller, that returns JSON responses.</p><p>Now we can perform the following requests in the same sequence. Remember, we are running zuul gateway service at 8080 and that will be used by any front end application like angular.</p><pre>curl -i -H &quot;Content-Type: application/json&quot; -X POST -d &#39;{&quot;username&quot;:&quot;raj&quot;,&quot;password&quot;:&quot;raj&quot;}&#39; http://localhost:8080/login</pre><p>This would return a response with JWT token that can be used further like below:</p><pre>curl -i -H &quot;Authorization: Bearer token-recieved-above&quot; http://localhost:8080/backend/user</pre><p>In the above application, we have seen how the zuul gateway is basically performing the authentication and then passing the requests to the backend. The same zuul gateway application can be configured to register to Eureka discovery service. That way we can configure Ribbon to talk to just zuul Gateway to perform the loadbalancing as well. I wish to publish more on my findings. Stay tuned.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2ef04a1dcfb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Clearing 70–532 Exam in Sep 2018]]></title>
            <link>https://medium.com/@bharatrajmeriyala/clearing-70-532-exam-in-sep-2018-2f418df81acc?source=rss-b2786bb31675------2</link>
            <guid isPermaLink="false">https://medium.com/p/2f418df81acc</guid>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[preparation-strategies]]></category>
            <category><![CDATA[70-532]]></category>
            <dc:creator><![CDATA[Bharat Raj Meriyala]]></dc:creator>
            <pubDate>Mon, 24 Sep 2018 06:07:57 GMT</pubDate>
            <atom:updated>2018-10-09T12:04:07.053Z</atom:updated>
            <content:encoded><![CDATA[<p>I decided to finally take up this exam 2 months back since I have worked on Azure platform for nearly 2–3 years and felt pretty confident about many of the PAAS and IAAS offerings there.</p><p>However, easier said than done, the exam’s outline is so vast that Microsoft expects you to know everything starting with Azure Virtual Machines, PowerShell commands to Azure AD and tonnes of SAAS offerings for developing applications on Azure. Luckily, I came across a very good presentation by Microsoft’s Brian Swagger, precisely telling what to concentrate on and what to ignore(for now at least! ). I have attached the screenshots of all the slides in my GitHub link along with other important study material as below:</p><p><a href="https://github.com/BharatRajMeriyala/70532preperation">https://github.com/BharatRajMeriyala/70532preperation</a></p><h3><strong>Tips to Pass the Exam</strong></h3><p>This isn’t just another certification, wherein we can just go through tonnes of material, brain dumps and pass the exam. The exam requires one to have real hands-on on the various offerings on Azure platform. Microsoft loves scenarios and case studies and solving them requires both detailed study of the question and some practical hands-on on the topic.</p><ol><li>Case studies might be long, but you have a total of 180 minutes to complete the exam. that means we have sufficient time to read through and understand every single line of the case study and grasp it completely before going ahead with solving questions based on the case study.</li><li>Sometimes questions can be straight out of case study as well. Microsoft loves to ask code questions in this Exam and twists many parts with fill in the blank styles of questions. Some of the answers in the fill in the blank can be answered if we go through the case study carefully. For instance, there can be a statement like, min requirement is to have 7 instances of the app running at any point in time. And then there will be a code question, requiring us to fill in the blank in a config file, with this value 7. So every single fact and number given in the case study is important.</li><li>On my GitHub link, I have added a PDF containing, important points as well as key things to practice in orange boxes across the screenshots. Please do a google search on those terms and practice relevant MSDN tutorials</li><li>Don’t be afraid to fail in the exam. In my case, luckily, I had a retake policy available with the main exam (Which is still the case if you happen to buy the Exam replay at official site before Sept 2018. Also be sure to keep checking on the official exam page for such offers in future). Often the first attempt in an exam will give you a real exposure to the exam requirements and in my case, it did expose me all the new things(described below in next point) which the exam expects you to know in order to pass the exam.</li><li>Please concentrate on newer topics like Azure Functions, Azure Search and Azure Service Fabric Actors, AKS and Cloud foundries. There were lots of questions on these topics and a good understanding of Azure AD &amp; authentication scenarios, Kubernates, containers and docker swarm is very important for clearing this exam.</li><li>There were questions on PowerShell way of doing things as well. While its impossible to remember every single PowerShell command, it will be beneficial to remember the PowerShell way of working with any Azure offering.</li></ol><h4>Preparation Material &amp; Approach</h4><p>The official Reference material is a valuable guide to start with preparation journey. Microsoft has released the book this January and it is pretty accurate with screenshots of the new portal. However, things are changing very fast on Azure and a book released in January 2018 already has few things outdated. For example, Azure API app description in the book is about the old way of developer portal and publisher portal, which are now part of Azure portal directly.<br><a href="https://www.amazon.ca/70-532-Developing-Microsoft-Azure-Solutions/dp/0735697043">https://www.amazon.ca/70-532-Developing-Microsoft-Azure-Solutions/dp/0735697043</a></p><p>Some of the newer topics like AKS or Cloud Foundries are not available in sufficient depth in the reference book as well. For such material please visit MSDN pages and look for a real end to end code application to get hands on.</p><p>Please follow all the MSDN links in the book and the steps they define to a particular task. It will take quite a while to finish all the tasks in the book on the portal, but be patient to complete it one by one. I advise making study notes of all the takeaways, after finishing a particular offering. I did find a great medium post which compiled the important links,</p><p><a href="https://medium.com/@zaab_it/exam-prep-70-532-developing-microsoft-azure-solutions-f0b5f24a2353">Exam Prep: 70–532 Developing Microsoft Azure Solutions</a></p><p>After a thorough study of the book, the PDF I prepared in the GitHub link above helped me narrow down the concepts to concentrate more on. Also, do not forget to go through the newer concepts, separately, mentioned above in greater detail.</p><p>Good luck!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2f418df81acc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Part 1: CI/CD setup with VSTS, ACR AND ACS of Dotnet Core 2.0 app]]></title>
            <link>https://medium.com/@bharatrajmeriyala/complete-ci-cd-with-vsts-acr-and-acs-c16d905225a1?source=rss-b2786bb31675------2</link>
            <guid isPermaLink="false">https://medium.com/p/c16d905225a1</guid>
            <category><![CDATA[azure-container-service]]></category>
            <category><![CDATA[acr]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[vsts]]></category>
            <dc:creator><![CDATA[Bharat Raj Meriyala]]></dc:creator>
            <pubDate>Sat, 17 Feb 2018 02:17:19 GMT</pubDate>
            <atom:updated>2018-02-17T02:22:08.987Z</atom:updated>
            <content:encoded><![CDATA[<h3>Step 1: Install Azure CLI on the Client machine.</h3><p>This is an important step to avoid the SSH certificate issues while connecting to the ACS swarm. So first download the Azure CLI from this website.</p><p><a href="https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest">https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest</a></p><h3>Step 2: Deploy Docker Swarm</h3><p>After the CLI is installed, execute the following:</p><p>a) Login to the azure CLI</p><p>b) Create a resource Group in West US.</p><p>Only certain regions support the ACS swarm. Here I chose West US.</p><p>C:\Program Files\Microsoft SDKs\Azure\.NET SDK\v2.9&gt;az group create — name simpleSwarmResourceGroup — location westus</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/643/1*pveFodEt0P4EHKB8fXisVQ.png" /></figure><p>c) Create Docker Swarm Cluster with the command below:</p><p>az acs create — name simpleSwarmCluster — orchestrator-type Swarm — agent-count 1 — resource-group simpleSwarmResourceGroup — generate-ssh-keys</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/644/1*pvwF6j3IYrh45BQDpIqehQ.png" /></figure><p>The above command takes a very long time. Nearly 10–15 minutes depending upon the size and count of agents. In the above command, I have defined 1 master and 1 node cluster.</p><p>Orchestrator type defines the type of cluster. This can be Swarm, DC/OS etc.</p><p>d) Note down the IP address of the Swarm Master using the command below:</p><p>az network public-ip list — resource-group simpleSwarmResourceGroup — query “[*].{Name:name,IPAddress:ipAddress}” -o table</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/641/1*K1dN4wBBG6J-LVAnX8LGLg.png" /></figure><h3>Step 3: Create a SSH Tunnel between local machine and Swarm Master.</h3><p>The keys generated by above command are not directly usable, when trying to login to Swarm Master in future steps.</p><p>a) First Open up PuttyGen Software and click on Load.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/481/1*5Ln48ngGcBmD6Lj7LYfXEw.png" /></figure><p>b) After the Load, choose the id_rsa file to successfully import and save, the private file in the same folder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/520/1*_H8W6fY_QslGvEpWK10OYw.png" /></figure><p>c) Next, Open Up putty and enter the public IP of swarm Master in the Hostname.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/455/1*jwadbiVxh_UMkpVEdsVpGw.png" /></figure><p>d) Navigate to Auth and choose the file created:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/447/1*WZmDiPtu5UTI1iouX5CjnQ.png" /></figure><p>e) Click on Tunnels and add the following:</p><p>Source Port: 2375</p><p>Destination: localhost:2375</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*JM6CFb6cBxpZWKyBHFaZbA.png" /></figure><p>f) Finally login to the prompt and execute the following:</p><p>export DOCKER_HOST=:2375</p><p>g) The ssh can be used to debug the commands that we are going to execute in VSTS in future steps. If not required we can close this terminal now.</p><h3>Step 4. Create Azure Container registry</h3><p>This is simple and we are required to perform the following:</p><p>a) Open Azure Container Registry in Azure Portal</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/704/1*FGKQunM4tGQtJ3LNQsX9hg.png" /></figure><p>b) Next click on “Create Container Registry” and give a unique name. Here I chose it as rajregistry.</p><p>c) After the ACR is created, we are required to enable Admin user and note the password as required. This will be used when we are building CI/CD pipeline with VSTS.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3vCgi_CMjoBAEm54Pfvwtg.png" /></figure><h3>Step 5: Build CI/CD in VSTS</h3><p>a) Login to VSTS account and create a sample project.</p><p>b) Connect VSTS project to ACR.</p><p>Click on Settings &gt; Services &gt; +New Service Endpoint and chose “Docker Registry”</p><p>All the details are available in the “Access Keys” in Azure portal. The password is the same as Access Key given in portal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/601/1*wSRSh6_xkl_HawZ3LLWvEQ.png" /></figure><p>c) Connect ACS to the VSTS</p><p>It is always good to upload the SSH private key file. Remember we need to upload the private key file generated from PuttyGen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/617/1*1RtraQ6CnHJ-bQ4aQHu2rQ.png" /></figure><p>d) Connect GitHub to VSTS</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/606/1*Dhf_gA-0wWyeRqy-hcxYjg.png" /></figure><h3>Step 6: Build Pipeline in VSTS</h3><p>After Building all the Steps we are now all set to build our VSTS pipelines. The Built stuff should look like the one below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-sQHVZSW7h-UDmpFb5yD9w.png" /></figure><p>Click on Builds tab and Click on create new, and choose the Git code from the Branch previously connected.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/491/1*C1TjmXeJkrcg9RX5ErRjyA.png" /></figure><p>After this, Choose the Empty Template to start with.</p><p>Next on the process Tab change to Hosted Linux Preview, since we are planning to deploy our Dotnet core images on Linux swarm cluster. At the time of writing the Swarm cluster has Ubuntu 14.04 operating system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/252/1*u1h9bhU4eqFblbkbRBypOw.png" /></figure><p>Next, Click on plus next to Phase 1 tab and choose to add a docker Build task.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/769/1*fs7sIzpQyEbe3LnqWet9TQ.png" /></figure><p>Enter the values for Build task as below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/410/1*pykZzN_GHL626jPzRRkbfQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/249/1*W60V7qo4iNidqeFiaL3Iow.png" /></figure><p>The most important thing here is to set the Docker File path and Build Context. Both can be selected from the dots available in the row.</p><p>We can provide a Build Number for each image, but for simplicity I will leave it at this. I will write a separate article on Appending and pushing with build numbers and options on maintaining the builds with time on repository.</p><p>Next, prepare a similar task for Pushing Code to ACR.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/419/1*G9R4bLZM0koki0Mi3_nEbA.png" /></figure><p>This concludes the Building and pushing the code to Azure Container Repository.</p><p>We can click on Queue the Build and see the Build pushed to our Azure Repo under repository tabs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/444/1*o2phknZOya9n8GfV-E9gnQ.png" /></figure><h3>Step 7: Push the Code ACS cluster</h3><p>Click on Releases, tab and Click on new,</p><p>Choose the Empty Template as before.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/619/1*Uw1p7AlkWIlhA1Kcr056Kg.png" /></figure><p>The release definition looks like below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/646/1*SX9bGa3Bkw1VzYC6VBv9Xw.png" /></figure><p>Click on add artifact. This is where we connect our Build pipeline to the release.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/220/1*Xd2mH0a131mOgOXI2EQuVg.png" /></figure><p>Next click on continuous deployment trigger, if we want the continuous deployment trigger</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/180/1*yOjC8fZoSc7rlpYNyuDpqw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/334/1*yEJqs4tD6GA8NRsUQAoLvQ.png" /></figure><p>Finally, Click on Environment link.</p><h3>Step 8: Implement the Release SSH task</h3><p>On the Agent Phase change to Agent queue to “Hosted Linux Preview”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/223/1*dCx4X1TXfAKexWVMeolL7g.png" /></figure><p>And click on + next to Agent Phase, and chose the SSH task:</p><p>Chose the SSH endpoint previously connected. And the docker commands to pull the code from ACR and deploy it to Cluster.</p><h3>Step 9: Execute the Pipeline.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*Tk0xWvpX6MCLTEkkzxXZtQ.png" /></figure><p>Next, we can, “Queue new Build” and test the whole setup. I will write a separate article on triggers as well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/535/1*Fw1HLnqbokHSR_jOJsJjqw.png" /></figure><h3>Step 10: Finally clicking on the IP address of a swarm agent, we can see the deployed app as below:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*gdm0tYxrgoEwJKpkSBbqCg.png" /></figure><p>There are many things once this is deployed to Agents cluster. We can setup a Azure Gateway to handle Https requests and forward our requests to a Azure Loadbalancer which can forward our requests to agents for example. The possibilities are endless.</p><p>I wish to add more articles to this series:</p><ol><li>Build options with Build number while storing the build in ACR.</li><li>More options for the release script to perform a clean remove of existing docker image and run the preseh new build on deployment trigger.</li></ol><p>Happy Coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c16d905225a1" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>