<?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 Vidhyanshu Jain on Medium]]></title>
        <description><![CDATA[Stories by Vidhyanshu Jain on Medium]]></description>
        <link>https://medium.com/@vidhyanshu?source=rss-b14f0fb14fa9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*PnDQWZrcfn9C15wPkjtspQ.jpeg</url>
            <title>Stories by Vidhyanshu Jain on Medium</title>
            <link>https://medium.com/@vidhyanshu?source=rss-b14f0fb14fa9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 15:23:24 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@vidhyanshu/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[Implement Filebeat as SideCar to export logs to Elastic]]></title>
            <link>https://vidhyanshu.medium.com/implement-filebeat-as-sidecar-to-export-logs-to-elastic-ffd2b1d02019?source=rss-b14f0fb14fa9------2</link>
            <guid isPermaLink="false">https://medium.com/p/ffd2b1d02019</guid>
            <category><![CDATA[sidecar]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[filebeat]]></category>
            <dc:creator><![CDATA[Vidhyanshu Jain]]></dc:creator>
            <pubDate>Wed, 28 Jul 2021 16:03:53 GMT</pubDate>
            <atom:updated>2021-07-28T16:03:53.706Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BsKUcgiYEThn7Tztejfecg.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@drew_beamer?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Drew Beamer</a> on <a href="https://unsplash.com/?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Exporting Logs inside a clustered environments is very important. When multiple instances of the same application are running it can be really hard to track down what exactly went down with the application. And Logging can be an unpleasant experience in Kubernetes.</p><p>In this post, I expect that your ELK setup is already in place. I will try to explain how we can implement Filebeat as a sidecar alongside your Kubernetes pods.</p><h3>Why set up Filebeat as SideCar and not inside the same container?</h3><p>While you can set up Filebeat inside the same container, but by doing that you are dishonoring the microservice architecture. Also exporting logs is an infrastructural component, and it is generally a good idea to separate the infrastructural components from your business applications.</p><p>Let&#39;s move on to the implementation</p><p>To keep it simple I will export success and error logs from a simple NGINX container. The image that I will be using for this is nginxdemos/hello . This is a simple hello world app by Nginx.</p><p>You can find all the Kubernetes config objects in this <a href="https://github.com/vidu171/filebeat-sidecar-implementation">git repo.</a></p><h3>Filebeat Config</h3><p><a href="https://www.elastic.co/beats/filebeat">Filebeat</a> is a log shipper it’s one of the many shippers provided by Elastic Stack. Filebeat offers various modules that can allow fast and simple log exporting for popular applications. So we will make use of the Nginx module. In this configuration, we need to provide two things. The path to the log files (inside the container, see: deployment.yml file below) and the ElasticSearch host. Let&#39;s look at the filebeat.yml file</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8cc9d304af46b4419ec79950921956b4/href">https://medium.com/media/8cc9d304af46b4419ec79950921956b4/href</a></iframe><p>Within the module section, we have defined the log file path for the access and error log files.</p><p>You can head on to <a href="https://www.elastic.co/beats/filebeat">Filebeat</a> page it’s well written to find out how to write the filebeat.yml file.</p><h3>Applying configuration with ConfigMap</h3><p>To apply the filebeat.yml inside our SideCar we will make use of the Kubernetes ConfigMap Object. ConfigMap lets you save non-confidential data in your NameSpace. You can read more about what is a ConfigMap <a href="https://kubernetes.io/docs/concepts/configuration/configmap/">here.</a></p><p>We will create a ConfigMap named filebeat-configmap with the content of filebeat.yml file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8a9dbd1d51c0e6483a4038fe647ea86d/href">https://medium.com/media/8a9dbd1d51c0e6483a4038fe647ea86d/href</a></iframe><h3>Deploying Nginx with Sidecar</h3><p>We will write the deployment file for our deployment in a moment. But before that, we need our sidecar to have access to the log files. Since the Nginx logs are generated in a different container we need to share the log files with our Sidecar.</p><p>To do that we can create a Volume Object in Kubernetes and Mount this volume in both our Nginx application and our SideCar. By doing so we will be sharing the log directory between the two containers. Whenever our Nginx container will write inside the log directory it will get written to the volume mount. And our sidecar will be able to read the logs from there.</p><p>We also need to create a Volume Object (filebeat-config) to apply the filebeat-configmap we generated just now.</p><p>Let’s see the deployment.yaml file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/006c048d986d401cc890bbcf0772f084/href">https://medium.com/media/006c048d986d401cc890bbcf0772f084/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FxT5LMHxhOfscxPfIfm%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FxT5LMHxhOfscxPfIfm%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FxT5LMHxhOfscxPfIfm%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="328" frameborder="0" scrolling="no"><a href="https://medium.com/media/56c11e405540b2db965e1b6443f73960/href">https://medium.com/media/56c11e405540b2db965e1b6443f73960/href</a></iframe><h3>Conclusion</h3><p>With this, we have successfully written a deployment for Nginx with a Filebeat sidecar. Here I have chosen a very simple example, but I believe this will give you an idea of how a sidecar is implemented. For more details on how to implement Filebeat for your application please visit the Filebeat page. Please feel free to drop a comment. 🙂</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ffd2b1d02019" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Implementing Clean Architecture in GO]]></title>
            <link>https://vidhyanshu.medium.com/implementing-clean-architecture-in-go-56aca59311b3?source=rss-b14f0fb14fa9------2</link>
            <guid isPermaLink="false">https://medium.com/p/56aca59311b3</guid>
            <category><![CDATA[backend-development]]></category>
            <category><![CDATA[go]]></category>
            <category><![CDATA[clean-code]]></category>
            <category><![CDATA[clean-architecture]]></category>
            <dc:creator><![CDATA[Vidhyanshu Jain]]></dc:creator>
            <pubDate>Fri, 09 Oct 2020 06:30:03 GMT</pubDate>
            <atom:updated>2020-10-09T06:30:03.519Z</atom:updated>
            <content:encoded><![CDATA[<h4>A step by step guide with a real-world example</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mTzs13LI_ENZ5UbHdK3QXw.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@marktwinkle?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Kaiyu Wang</a> on <a href="https://unsplash.com/s/photos/london-architecture?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><h3>Introduction</h3><p>We always seek to make improvements to our software. It is certain that every few years ( sometimes within months) you will be facing the challenge of updating your software. It is impossible to write perfect software that you never need to change. So instead, we focus on writing software that scales, that can easily be modified and doesn&#39;t break when you make changes. To address this problem many programmers came up with code architecture patterns that allow easy modification of code. One such architecture is the “Clean Architecture” — By <a href="https://en.wikipedia.org/wiki/Robert_C._Martin">Robert C Martin</a> popularly know as “Uncle Bob”.</p><p>The clean architecture follows the design principle of <a href="https://en.wikipedia.org/wiki/Separation_of_concerns">separation of concerns</a>. In other words, the architecture encourages people to divide the code into layers and each layer is independent of each other. Each layer addresses a separate concern. When code is segmented in such ways, the code can be reused and can be easily replaced or updated without affecting other parts of the code. So suppose you want to move from your SQL Database to a NoSQL database you can do it without affecting the rest of your code.</p><p>To keep this post concise and more practical I will not be talking about the particulars of Clean Architecture here. I recommend you to read this <a href="https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html">Clean Code blog</a> to get a better understanding of the architecture.</p><p>To follow along with the code you can check out this <a href="https://github.com/vidu171/clean-architecture-go">Github Repo</a></p><h3>The Dependency Rule</h3><p>Uncle Bob speaks about dividing the code into four layers:</p><ul><li><strong>Domain</strong>: Domain is the business logic that is independent of the application. In other words, the domain is common for the whole organization.</li><li><strong>Use Case: </strong>Use Case is business logic that is particular to the application.</li><li><strong>Interface: </strong>Interface consists of controllers, adapters, presenters. Interfaces allow us to connect our code to Infrastructure.</li><li><strong>Infrastructure: </strong>Infrastructure is the layer where all the detail go. Web, Database, third-party libraries, file systems all belong to the interface layer.</li></ul><p>The Dependency rules say that any inner layer should never know anything about the outer layer. That is the code in the inner layer should be independent of the code in the outer layer. And this statement confuses a lot of people, so I add one more line to the Dependency rule — “The inner layer tells the outer layer exactly what it needs and its the responsibility of the outer layer to full fill the inner layers requirement.”</p><p>Don’t worry you will understand this better once we walk through the code.</p><h3>The Book Library Application</h3><p>We will be writing a Book Library App. With the help of this Library app, we will see how to implement the clean architecture in Go.</p><blockquote>This is a bare minimum applicaion to keep the focus on clean architecture concepts. In real life scenarios we will have more values and objects.</blockquote><h4>File Structure</h4><p>This is what the file structure of our project looks like</p><pre>src<br>├── domain<br>│   ├── author.go<br>│   └── book.go<br>├── infrastructure<br>│   ├── db<br>│   │   └── mongodb.go<br>│   └── router<br>│       ├── mux-router.go<br>│       └── router.go<br>├── interface<br>│   ├── controllers<br>│   │   ├── author-controller.go<br>│   │   ├── book-controller.go<br>│   │   └── controller.go<br>│   └── repository<br>│       ├── author-repository.go<br>│       ├── book-repository.go<br>│       └── repository.go<br>├── main.go<br>└── usecases<br>    ├── author-usecases.go<br>    ├── book-usecases.go<br>    └── usecases.go</pre><h3><strong>Domain</strong></h3><p>Our Library Software will be dealing with two entities — authors &amp; books. In the domain layer, we put the piece of code that is core business logic but is independent of the application. So we will write the author and book entity in our domain layer.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/90e739c21ca06a13e0483949d0a97b15/href">https://medium.com/media/90e739c21ca06a13e0483949d0a97b15/href</a></iframe><p>As you can see in the book.go the file we don&#39;t have any imports. Because the domain layer is the innermost layer and according to the dependency rule it should be independent of everything. To implement a book entity we have written a struct Bookthat defines all the parameters of a book type. If there are any Business-specific methods with respect to this entity then it should be implemented in this file.</p><p>One thing worth pointing out is that we have a BookRepository Interface. A repository is a concept of <a href="http://en.wikipedia.org/wiki/Domain-driven_design#Building_blocks_of_DDD">Domain-driven Design</a>, we are specifying that the Book Entity needs functions that enables the books to be fetched from somewhere or to be saved somewhere. We are not specifying where the data will come from or where it will go to — this is a detail, we don&#39;t write details for an outer layer in a lower layer. We are just specifying that we need to have a struct that implements methods to persist the data. Now the implementation of the method, whether its a file or a DB or is it in memory we don&#39;t specify here. It is up to the outer layers to write the implementation and inject it in the form of BookRepo.</p><p>Similarly, We have a author.go domain file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/57fff52714c200f09aebca38e08c8040/href">https://medium.com/media/57fff52714c200f09aebca38e08c8040/href</a></iframe><h3>Use Cases</h3><p>Now we can define the application-specific business logic for our Library app. What we want from the app is to allow users to browse all the books present in our Library. We also want the ability to add books and authors to our Library. So in total, we have three use cases:</p><ul><li>Save Author in our library</li><li>Save Book in our library</li><li>Fetch all books from our library</li></ul><p>Since this is a small application I didn’t find the need to divide each use-case into different files. So I have divided all the book related use-cases in book-usecase.go and similarly, all the author related use-cases will go to author-usecase.go file. In a bigger application, I would have written each use-case in a separate file.</p><p>Let’s study the book-usecase.go file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1c804af483043ae745b331774036239a/href">https://medium.com/media/1c804af483043ae745b331774036239a/href</a></iframe><p>Note, how we are strictly following the dependency rule, imports only come from the inner layers.</p><p>In this file, we have implemented CreateBook() and FindAll() methods. These methods are essentially our use-cases. We have bound our use-case methods with a struct BookInteractor we have done this to allow for dependency injection. BookInteractor takes in the value of BookRepository. And if you remember BookRepository is an interface with SaveBook() and FindAll() methods. So we are essentially telling the outer layers that if you want to make use of CreateBook() and FindAll() use-cases you have to provide me with a struct of type BookRepository.</p><p>Similarly, we have our author-usecase.go file</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6d561e3c213f625094fc5f90525ce627/href">https://medium.com/media/6d561e3c213f625094fc5f90525ce627/href</a></iframe><h3>Interfaces</h3><p>Now our business logic is ready. Business logic is the part of code that isn&#39;t expected to change much hence it forms the inner layers. The beauty of clean architecture is that at this point, you can decide whatever set of infrastructure you want to use. Let’s say you want to create a command-line application and store your data in a file. Then you can implement interfaces for command line and files. Or if you want to write a Java Program to use your application you can also do that.</p><p>In our case, we will be writing a Web interface (APIs) and we will be using Database for persistence. Our aim is to write interfaces for our infrastructure. Our interfaces will be independent of our infrastructure. It will be the responsibility of the infrastructure to implement methods of our interface. So let&#39;s say we want to change our database we will only have to make changes in our infrastructure layer.</p><p>Now Our application requires two interfaces one for APIs and another for databases. You may want to write more interfaces like command-line, logs, etc. But, to keep it simple I will only implement database and API.</p><h4>Repository</h4><p>Following the DDD naming convention, I am using the term repository for our database interface. We have a author-repository.go file for author related database methods and book-repository.go for book related methods. We will also create the file repository.go. This file contains the part of code that is common for both author and book.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3d40fb896c741d68237ff5205055bfc3/href">https://medium.com/media/3d40fb896c741d68237ff5205055bfc3/href</a></iframe><p>Inside the repository.go file, We will implement a DBHandler interface. This interface is a template which the database infrastructure will have to implement. In other words, we are telling the database if you need to connect to our application please provide a struct with the following methods FindAllBooks() , SaveBook() and SaveAuthor() .</p><p>Let’s take a look inside the book-repository.go file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e173502479b9f2f10f0b6783e67c4143/href">https://medium.com/media/e173502479b9f2f10f0b6783e67c4143/href</a></iframe><p>Inside our book-repository.go file we will implement our SaveBook and findAll methods which are bounded by the BookRepo struct. This allows for the DBHandler injection which in-turn allows us to use the dbHandler methods.</p><p>Note that we have not actually implemented the DBHandler methods yet. We will be implementing these methods in the infrastructure layer where we write our database related methods. And then inject them in our bookRepository.</p><p>Similarly, we have our author-repository.go file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9bd46b54ac6c199518c568bd8c995104/href">https://medium.com/media/9bd46b54ac6c199518c568bd8c995104/href</a></iframe><p>With this, we have finished our Database Interface. Notice How we have finished writing the Datavinterface but we never discussed which database we are going to use. What this means is that till this layer we are truly independent of the database we are going to use.</p><h4>Controllers</h4><p>Controllers will be our API interfaces. Controllers will implement all the functions that our endpoints will call to connect to our application. The controller interface allows for the interaction of our application with the API framework that will be implemented in the infrastructure layer.</p><p>Let’s take a look in our book-controller.go file</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/85504c1492dc91dbd0a787fc82f8a9f8/href">https://medium.com/media/85504c1492dc91dbd0a787fc82f8a9f8/href</a></iframe><p>All our API endpoints related to Book are written as functions. ie. methods for our BookController struct. BookController takes in a BookInteractor parameter that allows for the injection of book-usecase methods.</p><p>As you can see that the controller methods are fairly simple because the main business logic is handled by book-usecase with the help of bookInteractor.</p><p>Similarly, we have author-controller.go file</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d8452b9a90353a81a5cb94c7f311c87d/href">https://medium.com/media/d8452b9a90353a81a5cb94c7f311c87d/href</a></iframe><h3>Infrastructure</h3><p>We have finally reached our last and the outermost layer. The Infrastructure layer. We have two infrastructure components — Database and Router. Now we can choose the database and router of our choice. I am choosing the MongoDB database and Mux router.</p><h4>Mongo</h4><p>The file mongodb.go consists of a DBHandler struct which contains all the code related to the database. One thing we need to make sure is that our database handler should match the DBHandler interface defined in our interface layer. This is the perfect example of the statement — “it is the responsibility of the outer layer to fulfill the requirements of the inner layer”</p><p>So our mongodb.go file looks like this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dadc2333cdde453141290d37081c42c0/href">https://medium.com/media/dadc2333cdde453141290d37081c42c0/href</a></iframe><p>Our DBHandler struct implements the FindAllBook SaveBook and SaveAuthor methods that let us persist/fetch data from the database.</p><h4>Router</h4><p>The file mux-router.go consists of a Router Struct Which implements the GET POST and SERVE methods. These methods allow you to call there respective methods from mux</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7c1454cac0154c8bf819085fee5f17f5/href">https://medium.com/media/7c1454cac0154c8bf819085fee5f17f5/href</a></iframe><h3>Putting it together</h3><p>We can finish up by writing our main.go file which will bind all the layers together and create and serve our application.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/17e5f3a97393037e704863644a4b0577/href">https://medium.com/media/17e5f3a97393037e704863644a4b0577/href</a></iframe><p>The first thing that this code does is connect to the database and create a DBHandler.</p><p>Then we have two functions getBookController and getAuthorControlller. Inside these functions, we will see how we have a chain of dependency injection. First, we have injected the DBHandler struct to BookRepo and created an instance of BookRepo. Then we injected that BookRepo into BookInteractor and created a new instance of bookInteractor which was further injected into the bookController to return a controller. And then we can finally call the controller methods with there corresponding endpoints.</p><p>And with this, we have written a Clean Architecture implementation in GO.</p><h3>Conclusion</h3><p>We have created a very simple code that implements Clean Architecture. This is by no means a complete application a lot of improvements can still be made like adding loggers using dotEnvs etc. But I hope that I was able to provide a proper basic idea behind writing software that is scalable and easily manageable.</p><p>Happy Hacking!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=56aca59311b3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A deeper look at Object-oriented-programming in JavaScript]]></title>
            <link>https://levelup.gitconnected.com/a-deeper-look-at-object-oriented-programming-in-javascript-6ab7761131a2?source=rss-b14f0fb14fa9------2</link>
            <guid isPermaLink="false">https://medium.com/p/6ab7761131a2</guid>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[inheritance]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[object-oriented]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Vidhyanshu Jain]]></dc:creator>
            <pubDate>Tue, 02 Jun 2020 14:59:01 GMT</pubDate>
            <atom:updated>2020-06-02T14:59:01.174Z</atom:updated>
            <content:encoded><![CDATA[<h3>A deeper look at object-oriented programming in JavaScript</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*haMEQHfMceoIpoEs30wzuA.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@grakozy?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Greg Rakozy</a> on <a href="https://unsplash.com/s/photos/javascript?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>JavaScript is a class-less programming language. Classes, as you know in other languages like Java, do not exist in JavaScript.</p><p>Even though JavaScript doesn’t provide support for Classes, clever use of existing concepts (constructor function and prototypal inheritance) in JavaScript allowed the developers to emulate this behavior successfully. So the class keyword which you can find in JavaScript after the ES6 update is a syntactical abstraction for the steps required to emulate classes using existing JavaScript concepts. In this post, we will see what are the underlying concepts behind the class keyword.</p><p>But first, let’s see two of the most simple ways to create objects</p><h3>Object Constructor and Object literals</h3><p>JavaScript lets you create objects using the Object() constructor. The Object constructor creates an object wrapper for the given value. And if the value is null it will create and returns an empty object.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c37dd6304c92886f4fe53064170077dc/href">https://medium.com/media/c37dd6304c92886f4fe53064170077dc/href</a></iframe><p>In the above example by calling the Object constructor with empty parameters we have initialized an empty object and assigned it to the variable dog. Then we simply add object properties with the help of the dog variable</p><p>After the initial years of JavaScript, object literals became the preferred way of creating objects. We can rewrite our previous example as:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cdfc2e9fa315225fd6b4b32638c22c70/href">https://medium.com/media/cdfc2e9fa315225fd6b4b32638c22c70/href</a></iframe><p>Though very simple to use Object Constructor and Object literal have some downsides when creating objects. Creating multiple objects with the same interface requires a lot of code duplication.</p><h3>Creating Objects</h3><p>We could just simply use class to create objects and that is the preferred way since the introduction of classes in ES6. But to understand how OOP in Javascript works, we must understand the underlying concepts that are replaced by classes. So we should take a look at some ways to implement Object creation with interfaces.</p><h4><strong>The function constructor pattern</strong></h4><p>JavaScript objects can be created using a constructor. There are some native constructors available right out the box in JavaScript, such as Object and Array. It is possible to define custom constructors using functions that define the properties and methods. So let&#39;s start by creating an object called dog.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/75e27e67f4cd20f9b4e26ff527ef956c/href">https://medium.com/media/75e27e67f4cd20f9b4e26ff527ef956c/href</a></iframe><p>Note that to create an object using the dog function as a constructor we use the new operator in line number 10. When line 10 is executed the following steps take place:</p><ol><li>A new Object is created in the memory</li><li>It sets this new object’s internal, inaccessible, [[prototype]] property to be the constructor function’s external, accessible, <em>prototype</em> object (every function object automatically has a <em>prototype</em> property).</li><li>The this value is assigned to the newly created object.</li><li>It executes the constructor function, using the newly created object whenever this is mentioned.</li><li>the newly created object is returned unless the constructor function returns a non-null object reference. In this case, that object reference is returned instead.</li></ol><p>The only difference between constructor functions and other functions is the way in which they are called. Any function that is called with the new operator acts as a constructor.</p><p>While creating the object using the constructor, one thing worth noticing is that tuffy object had his own copy of the properties present inside the dog constructor. ie. changing the property associated with one object will have no effect in the properties of the constructor function. Let’s take a look at an example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bd58402cceb0afac1e6d9bde71c378e3/href">https://medium.com/media/bd58402cceb0afac1e6d9bde71c378e3/href</a></iframe><p>As you can see from the above example changing the toys property in the tuffy object has not affect on the toys property inside the tyson object. Because both tuffy and tyson have their own copies of constructor properties.</p><p>But due to this nature of objects having their own copy of properties we can face memory related issue. As multiple copies of the same property takes up a lot of space. This is the major drawback of the function constructed pattern.</p><h4><strong>The Prototype pattern</strong></h4><p>Whenever you create a function in JavaScript you will notice that an object name prototype is appended in the definition of the function. Inside the prototype object we can add properties that the resulting object should inherit. The benefit of using a prototype is that the resulting object will not have a copy of the properties but it can still access the properties and methods by searching for them in the prototype object.</p><p>Let’s take an example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/636a512fdfc3f140fd6eb85345e263f3/href">https://medium.com/media/636a512fdfc3f140fd6eb85345e263f3/href</a></iframe><p>The way prototype works is that when a property is accessed a search starts to find the property. The search begins on the object first and if the property is found in the object then it returns the value. Like when we tried to call dog.legs in line 12 it returns the value 4 as the property legs exist in the object. And when the property is not found in the object the search continues up the prototype. And the prototype is searched for the property. If the property is found on the prototype then it returns the value. If not found the search continues up the prototype chain till it encounters the property. Like when we tried to access the property legs on boy the search moves to the prototype because the object boy doesn’t have the property leg. Since the prototype of the object boy has the property legs it returns the value.</p><p>One thing that we need to keep in mind that prototypes are dynamic. So any changes made in the prototype at any point will be reflected on the objects.</p><p>Even the prototype pattern is not perfect. the first downside is that you don’t have the ability to pass the arguments like we could do it in function constructors. But honestly, this is not a very big downside it’s inconvenient but developers can easily overcome it.</p><p>But the real problem arrives with reference properties. Let&#39;s take an example to understand this drawback:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/59ea2174c4389f309d301b31318d66e4/href">https://medium.com/media/59ea2174c4389f309d301b31318d66e4/href</a></iframe><p>As you can see that dog1 and dog2 both have the same property. This happened because in line 6 the push function is actually referencing the property which returns the toys property present inside the prototype and added a new value to the toys array. So properties that can be referenced can cause this inconsistent behavior.</p><p>This behavior of prototypes can be desirable for some and could be a problem for others. Although generally it is desired for the objects to have their own copies of properties. Hence it is rare that prototype pattern is used alone.</p><h3>Inheritance</h3><p>Inheritance in JavaScript is primarily done through prototype chaining. First, we should know what prototype chaining is.</p><h4><strong>Prototype chaining</strong></h4><p>JavaScript has only one construct that is the object. As we have seen that each object has a property called prototype. A prototype is an object which points to the properties and methods of the constructor. But it&#39;s not necessary for the prototype to be constructor, it can be an object also. And that object will also have a prototype of its own and its prototype might have a prototype of its own and this pattern will continue, forming a chain of prototypes called prototype chain.</p><p>Let’s take a look at how prototype chaining is implemented:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f818d88217fd77312de4a34318d994ec/href">https://medium.com/media/f818d88217fd77312de4a34318d994ec/href</a></iframe><p>So as you can see that human inherits animals by pointing its prototype pointer to the animals object. So when we access Jon.canWalk it searches for the canWalk property in its object then inside its prototype: human object and then the search reaches to animals object and finally returning its value.</p><p>The problem with prototype chaining is the same problem that we face with prototypes. When we are using properties that contains reference values these properties are shared among the objects and this is why properties are defined using constructors.</p><blockquote>Properties are typically defined in constructor instead of using prototypes. Because we have seen that properties with reference values can be irritating.</blockquote><h4><strong>Classical Inheritance</strong></h4><p>Classical Inheritance or Constructor Stealing or Masquerading all means the same thing. The idea behind classical inheritance is to call the constructor of an object inside the constructor of another object. We can leverage the apply() and call() methods to execute the constructor on a newly created object. Let’s take a look at the example.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9963f764b497b23289b7e4884571363d/href">https://medium.com/media/9963f764b497b23289b7e4884571363d/href</a></iframe><p>By using the call() or apply() method we are essentially stealing the constructor function from the shapes. The shapes constructor when called inside the square constructor it is running the code initialization of the shapes constructor and because of which every object of square type has a copy of its own colors.</p><p>Constructor stealing (classical inheritance) comes with a benefit over prototype chaining. With classical inheritance we have the ability to pass arguments which was a downside in prototype chaining.</p><p>That being said classical inheritance has its own drawback. Methods must be written inside the constructor so there’s no function reuse. Constructor stealing doesn’t automatically create prototypes hence a sub-type object can’t use the prototype from the super-type.</p><h4>Combined Inheritance</h4><p>Combined Inheritance (also known as pseudo-classical inheritance) is a combination of prototype chaining and classical inheritance. So we can inherit properties and methods from the prototype and use classical inheritance to inherit instance properties.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9faf23154d5962de0a6b351a6cf80c27/href">https://medium.com/media/9faf23154d5962de0a6b351a6cf80c27/href</a></iframe><p>As you can see that we have used constructor stealing(classical inheritance) to inherit properties and we have used prototype chaining to inherit methods. So we have created two instance of object dog which have their own copies of properties and at the same time they are sharing a method.</p><h3>Classes</h3><p>Up until this point we have gone through the in-depth view of how it is possible to emulate classes in JavaScript. But implementing these methods can be tedious task and it increases the probability of creating bugs in your code. So starting from ES6 class was introduced that abstracts the logic behind OOPs in JavaScript. The ES6 classes appear to feature canonical object-oriented- programming, but they still use the prototypes and constructor under the hood.</p><p>We can write a class definition in two ways: class declaration and class expressions</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/558cdd489469808bdc786f45d62a919d/href">https://medium.com/media/558cdd489469808bdc786f45d62a919d/href</a></iframe><p>Note: By default, everything inside the class method executes in strict mode.</p><p>A class can be composed of the constructor, get methods, set methods, methods, and static methods.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b249b191c29cb4e7bab1a19ba7e7f710/href">https://medium.com/media/b249b191c29cb4e7bab1a19ba7e7f710/href</a></iframe><p>To create an object using class we use the new keyword. And the new keyword will follow the same steps that we saw when we created an object using function constructor in our previous sections.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/eab7c86ca6c6f21da22cde1db0fa0890/href">https://medium.com/media/eab7c86ca6c6f21da22cde1db0fa0890/href</a></iframe><p>In JavaScript, classes are first-class citizens. That means that classes can do everything that other things can do. Classes can be passed around like you would pass any other object or function reference. Classes can be used anywhere a function (for example in arrays and function parameters).</p><p>Below are some of the members that we generally see inside a class object:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/43738b066449856ac0204369dfff55ae/href">https://medium.com/media/43738b066449856ac0204369dfff55ae/href</a></iframe><p>Inside a class, all the members and properties defined inside the constructor will not be shared to prototype. Every Instance will have a copy of all the properties and methods inside the constructor. These properties are the same as we saw when we used function constructors while creating objects.</p><p>And everything defined outside the constructor and in the root of the class body is appended to the prototype object.</p><p>Note: Primitive data types and objects can not be added to the root of the class.</p><p>Static methods are methods that can be used even without an instance of the class. As we can see in Line 16 the method sayHello was used without creating an instance of the class because it was a static method.</p><h3>Inheritance</h3><p>One more addition of the ES6 update was inheritance. The syntax is different but under the hood class inheritance still uses prototype chaining to achieve inheritance.</p><p>The extend keyword allows to inherit from anything that has a [[construct]] property and a prototype. It means it is backward compatible so, you can inherit from another class and you can also inherit from function constructors.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9e1506343d0809ce48161a2fdddece75/href">https://medium.com/media/9e1506343d0809ce48161a2fdddece75/href</a></iframe><p>In this example, we are inheriting the properties and method in the Dog class from the Animal class. We have used the super() method to invoke the constructor of the Animal class.</p><p>This concludes OOPs pattern in JavaScript. We have seen that without having any formal concept of class we can still achieve classes and inheritance in JS. It’s important that we know how exactly JavaScript works. Prototypes and function constructors are important in JavaScript and one should invest time to learn about these.</p><p>Happy Coding :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6ab7761131a2" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/a-deeper-look-at-object-oriented-programming-in-javascript-6ab7761131a2">A deeper look at Object-oriented-programming in JavaScript</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kubernetes Deployment: Connect Your Front End to Your Back End With Nginx]]></title>
            <link>https://medium.com/better-programming/kubernetes-deployment-connect-your-front-end-to-your-back-end-with-nginx-7e4e7cfef177?source=rss-b14f0fb14fa9------2</link>
            <guid isPermaLink="false">https://medium.com/p/7e4e7cfef177</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[containers]]></category>
            <dc:creator><![CDATA[Vidhyanshu Jain]]></dc:creator>
            <pubDate>Mon, 04 May 2020 16:30:06 GMT</pubDate>
            <atom:updated>2020-05-04T16:30:06.034Z</atom:updated>
            <content:encoded><![CDATA[<h4>Deploy a full-stack application with Kubernetes</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mnHmbE2N2j-dUxnB5T2Zmg.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@jbcreate_?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Joseph Barrientos</a> on <a href="https://unsplash.com/s/photos/helm?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p><a href="https://kubernetes.io/">Kubernetes</a> is one of the best orchestration tools available. Furthermore, it is backed by Google, so we don’t have any doubts regarding the support and performance that Kubernetes can provide.</p><p>In this article, we will be using <a href="https://kubernetes.io/docs/setup/learning-environment/minikube/">Minikube</a> to understand how to deploy a full-stack application in Kubernetes.</p><p>I remember that while I was working on my first Kubernetes deployment, I realized that deploying a Kubernetes full-stack application and connecting the front end and back end can be a bit tricky. So I decided to write a tutorial that will help you deploy your full-stack application.</p><h3>Prerequisites</h3><p>This tutorial assumes that you have a basic understanding of Kubernetes. To keep this tutorial relevant to the topic, it’s highly recommended that you should at least read these topics.</p><ul><li><a href="https://kubernetes.io/docs/concepts/workloads/controllers/deployment/">Kubernetes deployment</a></li><li><a href="https://kubernetes.io/docs/concepts/services-networking/service/">Kubernetes service</a></li><li><a href="https://docs.docker.com/">Docker</a></li></ul><p>Also, if you are working on your local machine, please install minikube, kubectl, and docker.</p><h3>What Are We Going to Deploy Today?</h3><p>The most common type of full-stack application has at least three components:</p><ul><li>Database</li><li>API server</li><li>Front-end application</li></ul><p>This tutorial aims to help you get familiar with Kubernetes deployment. Once you understand how to deploy the above three components, you’ll be able to deploy any application in Kubernetes.</p><p>We will be using Node.js for the back end and <a href="https://www.mongodb.com/">MongoDB</a> for the database, and to keep it straightforward, we will use a simple HTML file with Ajax for the front end. You can select React or Angular or any front-end framework of your choice. The choice of your framework does not affect any of the steps.</p><p>Step by step, we will visit all three components. You can find all the code related to this article on <a href="https://github.com/vidu171/Kubernetes-deployment">Github</a>.</p><p>Let’s dive straight into it then.</p><h3>Back End</h3><p>For this tutorial, we will keep our back end very simple. We have a simple Node server with <a href="https://expressjs.com/">Express</a> and <a href="https://mongoosejs.com/docs/">Mongoose</a>.</p><p>We are using Mongoose to connect to our MongoDB. And I have chosen the port 3000 for Express.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d0e0a946060435c3345a4accf5076f7f/href">https://medium.com/media/d0e0a946060435c3345a4accf5076f7f/href</a></iframe><p>Note: We have used mongo-service as the hostname for database URL. That’s because Kubernetes provides you with abstractions called <a href="https://kubernetes.io/docs/concepts/services-networking/service/">services</a>. We will create a mongo-service service in the latter part of this tutorial. And you can use the service name as the hostname to connect to your application (mongo-service, in this case).</p><p>TLDR; If you have a Kubernetes service named mongo-service, you can use mongo-service as the DNS name of your application. It’s the responsibility of Kubernetes to forward the request to the corresponding pod. Don’t worry, we will revisit this.</p><p>We should also add a route /api to our back-end application.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a90f29bd1c44bbfdd6f4e82e50830546/href">https://medium.com/media/a90f29bd1c44bbfdd6f4e82e50830546/href</a></iframe><p>That’s it. We are now done with our front-end application. All we have to do now is to containerize the application and write Kubernetes Objects.</p><h4>Containerizing Node app</h4><p>To deploy an application to Kubernetes, we need a Docker image of that application. So in this step, we will containerize our back-end app. Below is a fairly simple Dockerfile for our Node app.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f0585078497d1809d243798013ef7ca0/href">https://medium.com/media/f0585078497d1809d243798013ef7ca0/href</a></iframe><p>I have used node-alpine as my base image. To create the Docker image, run the following command:</p><pre>docker build -t backend .</pre><p>Now we have an image called backend. Next, we will write Kubernetes objects.</p><h4>Kubernetes objects for Node app</h4><p>For any Kubernetes deployment, we need Kubernetes objects. These <a href="https://kubernetes.io/docs/concepts/overview/working-with-objects/kubernetes-objects/">Kubernetes objects</a> represent the state of your container.</p><p>We will create a Kubernetes deployment object. Deployment objects contain information such as the Docker image used, the number of replica sets, resource allocation, etc.</p><p>We will create a deployment called node-deployment. We will use our back-end image and create one replica of the container. Inside the node-deployment.yaml file, write:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4d196e26d3d4c21e8b9268d530bf33b9/href">https://medium.com/media/4d196e26d3d4c21e8b9268d530bf33b9/href</a></iframe><p>With this deployment object, we are telling Kubernetes to create a deployment with name node-deployment which has one replica set of pod named node-pod. node-pod is a container of backend image with the concerned container port 3000.</p><p>To create this deployment, just run the following command:</p><pre>kubectl apply -f node-deployment.yaml</pre><p>We have created a deployment, but we have no way of communicating with it. To solve this problem, we will have to create a <a href="https://kubernetes.io/docs/concepts/services-networking/service/">service</a>. Service is an abstraction in Kubernetes that assigns IP addresses to pods and a single DNS to a set of pods. As we have seen before while connecting to MongoDB, we used mongo-service as the hostname. We will be writing a service called node-service so that we can connect to our back-end app from the front end.</p><p>Our node-service.yaml file looks like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/04ea75b8c2919ef1f6ec54433542a84f/href">https://medium.com/media/04ea75b8c2919ef1f6ec54433542a84f/href</a></iframe><p>We have now created a service of type LoadBalancer. This service is bound to all the replicas of the pod with the name node-pod. And you can now talk to the node server using the hostname node-pod.</p><p>Apply the service using the following command:</p><pre>kubectl apply -f node-service.yaml</pre><p>This concludes our back-end step. We can now start working on our front-end app.</p><h3>Front End</h3><p>For the front end, I am using a simple HTML file with <a href="https://jquery.com/">jQuery</a> just to keep this tutorial straightforward. But you can use any front-end framework of your choice. Whichever framework you use will not affect these steps.</p><p>To serve our front-end application, we will be using the <a href="https://www.nginx.com/">Nginx</a> web server. The reason we are using the Nginx server is that it provides a proxy. And we will be needing Nginx proxy to pass our request to our node deployment.</p><p>We will create a very simple HTML file named index.html. And we will use <a href="https://www.w3schools.com/xml/ajax_intro.asp">Ajax</a> to query our node server.</p><p>From the web browser, if you try to connect to <a href="http://node-server:3000/api">http://node-server:3000/api</a>, you will get the “host not found” error. This is because the DNS node-server is not registered on the internet.</p><p>A workaround for this is to send the request to the front-end application, let’s say to a path /api. And using Nginx, we can forward the query to our back-end application.</p><p>What I mean by that is that we will send all of our back-end calls to the /apipath in our front-end application and configure Nginx such that it will pass the request to <a href="http://node-service/api">http://node-service/api</a>.</p><p>Our index.html file looks like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d8123bed62dbdd41b9b133a117f36ba7/href">https://medium.com/media/d8123bed62dbdd41b9b133a117f36ba7/href</a></iframe><p>See how we have used /api as our URL?</p><pre>const url = &quot;/api/&quot;</pre><p>Now we will write the Nginx conf Nginx.conf file to forward the request from the path /api to <a href="http://node-service/api">http://node-service/api</a>.</p><p>Our Nginx.conf file should look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/69ef9c194399350a495dc50a61893fb6/href">https://medium.com/media/69ef9c194399350a495dc50a61893fb6/href</a></iframe><p>This config file tells Nginx that for all the requests for path /api, send the request to <a href="http://node-service/">http://node-service</a>:3000/api. You can read more about proxy_pass <a href="http://nginx.org/en/docs/http/ngx_http_upstream_module.html">in the documentation</a>.</p><h4>Containerizing the front end</h4><p>Next, we will containerize the application for Kubernetes deployment. In our front-end image, we need to replace the default Nginx conf file with our conf file.</p><p>Our Dockerfile will look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2a87f498ae445f37498b8a6fea23aeae/href">https://medium.com/media/2a87f498ae445f37498b8a6fea23aeae/href</a></iframe><p>Line 4 removes the default Nginx conf file from the image</p><p>Line 5 copies our new config file to Conf.d folder.</p><p>With this, we have now successfully created our Docker image for the front-end app. Let’s move on to the next step and create Kubernetes deployment and service for our front-end app.</p><h4>Kubernetes objects for the front end</h4><p>The deployment object for Nginx will be very similar to the deployment object we created in our back-end app.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a9c6afcd1b70568db1e7f53f8babbb92/href">https://medium.com/media/a9c6afcd1b70568db1e7f53f8babbb92/href</a></iframe><p>After running kubectl apply, we have a deployment named frontend-deployment, which has one replica of a pod named frontend-pod that is made using the frontend image.</p><p>Similarly, our nginx-service.yaml file should look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bc31ca40923b508a3cc912497b04fd7d/href">https://medium.com/media/bc31ca40923b508a3cc912497b04fd7d/href</a></iframe><p>This creates a service with the name frontend-service of the LoadBalancer type, which is bound to all the replicas of the pod with the name frontend-pod.</p><p>This concludes our front-end step. Now we can proceed to our last step, which is the database.</p><h3>Database</h3><p>Deploying our database in Kubernetes is the easiest step because we don’t have to create any Docker image for it. And it’s very easy to configure.</p><p>We don’t need to create a MongoDB image because we can directly use the MongoDB image from <a href="https://hub.docker.com/_/mongo">Docker Hub</a>. We can directly start writing our deployment object.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/11b567befa6992616dccc0e5a2a6ae99/href">https://medium.com/media/11b567befa6992616dccc0e5a2a6ae99/href</a></iframe><p>This creates a simple Mongo deployment. The env key inside the container tells Kubernetes that these are the environment values with which you have to create the image. We are basically telling Kubernetes to create a deployment with one replica set of pod, mongo-pod, which has a Mongo container and the name of the database is database.</p><p>For the final step, we will write our mongo-service.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5d5c904622d378f304e332399181c5d4/href">https://medium.com/media/5d5c904622d378f304e332399181c5d4/href</a></iframe><p>After the kubectl apply command, we should have created a service named mongo-service that’s bound to all the replicas with the name mongo-pad. And you can now talk to MongoDB using the hostname mongo-pod.</p><h3>Conclusion</h3><p>With this, we have deployed our full-stack applications in Kubernetes.</p><p>Using the Nginx proxy_pass derivative, we were able to connect our front-end deployment to our back-end deployment. Most people face issues when they have to connect the front end and back end in Kubernetes.</p><p>Now you can deploy a complete full-stack application by following the above steps.</p><p>Happy coding.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7e4e7cfef177" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/kubernetes-deployment-connect-your-front-end-to-your-back-end-with-nginx-7e4e7cfef177">Kubernetes Deployment: Connect Your Front End to Your Back End With Nginx</a> was originally published in <a href="https://betterprogramming.pub/">Better Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>