<?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"><channel><title><![CDATA[Sarthak Agarwal]]></title><description><![CDATA[Highly Motivated, skilled individual with a driving passion for programming and innovation. Grounded and a solution oriented, love to work in challenging enviro]]></description><link>https://blog.sarthakag.dev</link><generator>RSS for Node</generator><lastBuildDate>Fri, 22 May 2026 17:59:10 GMT</lastBuildDate><atom:link href="https://blog.sarthakag.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Kubernetes: The Overview]]></title><description><![CDATA[In this article, we will be understanding Kubernetes. We will understand some important aspects of Kubernetes, What is Kubernetes? Why do we need them? What problem arises with the management of Containers? How Kubernetes solves a major container man...]]></description><link>https://blog.sarthakag.dev/kubernetes-the-overview</link><guid isPermaLink="true">https://blog.sarthakag.dev/kubernetes-the-overview</guid><category><![CDATA[Docker]]></category><category><![CDATA[Kubernetes]]></category><category><![CDATA[Devops]]></category><category><![CDATA[Cloud]]></category><dc:creator><![CDATA[Sarthak Agarwal]]></dc:creator><pubDate>Thu, 12 Jan 2023 11:46:26 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1673524388648/c0b80569-cc56-4488-96c0-c63b075eb9f3.webp" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In this article, we will be understanding Kubernetes. We will understand some important aspects of Kubernetes, What is Kubernetes? Why do we need them? What problem arises with the management of Containers? How Kubernetes solves a major container managing problem?</p>
<p>Before we start, you must know about Dockers and Containers, working of containers and images, volumes, networking in containers, and multi-container apps.</p>
<h2 id="heading-problem-with-containers">Problem with Containers</h2>
<p>Managing Docker containers can be challenging, especially in large-scale environments where you might have hundreds or thousands of containers running across multiple hosts and servers, which eventually are serving an application with millions of users. Some of the major challenges of managing Docker containers include:</p>
<ol>
<li><p><strong>Deployment</strong>: Deploying and updating Docker containers can be time-consuming, especially when you need to update multiple containers at once. Although we have Docker Compose to rescue us from this problem, we are talking about a large number of Containers.</p>
</li>
<li><p><strong>Scaling</strong>: Scaling Docker containers can be difficult, especially if you need to scale up or down quickly in response to changes in demand. Scaling Docker containers can be challenging because it requires balancing the resources available on the host machine with the resource needs of the containers. Additionally, it can be difficult to determine the optimal number of containers to run in a production environment, as it depends on factors such as the resource requirements of the application, and the number of users accessing the application.</p>
</li>
<li><p><strong>Load balancing</strong>: Distributing traffic across multiple Docker containers can be challenging, especially if you need to do it in a way that is both efficient and fault-tolerant. In addition, load balancing refers to the distribution of incoming traffic to multiple containers running on a single host or across multiple hosts. Load across all the containers should be distributed equally, which is a very rigorous task.</p>
</li>
<li><p><strong>Monitoring</strong>: Monitoring the health and performance of Docker containers can be difficult, especially in large-scale environments where you might have hundreds or thousands of containers running. In case of an app crash, that particular needs to be replaced with a new container, which in turn is a challenging task.</p>
<p> Although, we have cloud service providers like AWS which provides services like AWS ECS, which solves all these problems you are then limited to what these services provide. You have to follow the rules of these services, you will have to configure everything as defined by these services, which might not be a solution.</p>
<p> In addition, if we have to switch to another cloud service provider, then we again have to rewrite the entire configuration for our apps that meet the rules of the new cloud service provider. So, these are the problems that Kubernetes solves and make the management of these containers much simpler.</p>
<p> In case, if you are comfortable with these services, and your requirements meet with what these services provide, then it's okay to go with them.</p>
<h2 id="heading-what-is-kubernetes">What is Kubernetes?</h2>
<p> Kubernetes is an open-source container orchestration system for automating the deployment, scaling, and management of containerized applications. I hope this <strong>official definition</strong> of Kubernetes, is now very easy to understand. It helps us in automatic deployment, scaling, load balancing and management of containers.</p>
<p> In addition, Kubernetes is not a cloud service provider, not a service provided by a cloud service provider, it's not restricted to any service provider, not the software you run on some machine, not an alternative to Docker, and not a paid service.</p>
<p> Kubernetes is an open-source project, it's a collection of objects and tools, that can be used with any cloud service provider, and work together with Dockers(Containers).</p>
</li>
</ol>
<h2 id="heading-architecture-of-kubernetes">Architecture of Kubernetes</h2>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1673519945519/769c3116-e36c-467a-93fa-bd833646a6a5.png" alt class="image--center mx-auto" /></p>
<p>Before going further, we need to be very clear about What Kubernetes will do and don't. Following are the actions that as a user you need to do -</p>
<ol>
<li><p>Create the cluster and the Node instances(Worker + Master Nodes).</p>
</li>
<li><p>Set up API Server, kubelet and other Kubernetes services or software on Nodes.</p>
</li>
<li><p>Create other cloud provider resources that might be needed (e.g Load Balancer and File Systems.)</p>
</li>
</ol>
<p>The following are the actions that Kubernetes will perform -</p>
<ol>
<li><p>Create your objects (e.g Pods and Deployments) and manage them.</p>
</li>
<li><p>Monitor Pods and re-create them, scale pods, destroy them etc</p>
</li>
<li><p>Kubernetes utilizes the provided cloud resources to apply your configuration and goals.</p>
</li>
</ol>
<p>We can also think of Kubernetes is like Docker Compose for multiple machines, it's a simple analogy! But not just it.</p>
<h3 id="heading-core-components-of-kubernetes-ecosystem">Core Components of Kubernetes Ecosystem</h3>
<ol>
<li><p><strong>Cluster</strong> - A set of Node machines that are running the Containerized Applications(in Worker Nodes) or other Nodes(Master Node).</p>
</li>
<li><p><strong>Nodes -</strong> It is a physical or virtual machine with a certain hardware capacity that hosts one or multiple Pods and communicates with other cluster resources.</p>
</li>
<li><p><strong>Master Node</strong> - It contains Cluster Control Plane, managing the Pods across the Worker Nodes.</p>
</li>
<li><p><strong>Worker Node</strong> - It hosts Pods, running App Containers and their required resources.</p>
</li>
<li><p><strong>Pods</strong> - Pods hold the actual running App Containers and their required resources (e.g Volumes)</p>
</li>
<li><p><strong>Containers</strong> - These are normal Docker Containers.</p>
</li>
<li><p><strong>Services</strong> - A logical set of Pods with a unique, Pod and Container independent IP Address.</p>
</li>
</ol>
<h1 id="heading-conclusion">Conclusion</h1>
<p>Kubernetes is an open-source container orchestration system for automating the deployment, scaling, and management of containerized applications. We understood what problems arise with Containers, What Kubernetes solves, and How it solves them. Problems like auto-scaling, load balancing and monitoring are solved by Kubernetes. Kubernetes is an open-source project, it's a collection of objects and tools, that can be used with any cloud service provider.</p>
<p>I hope from this article, you are very clear about the core concepts of Kubernetes, its terminologies and the architecture of Kubernetes. In the future articles, we will understand this by creating a cluster and running them on local machines then, all these concepts will be more clear.</p>
<p>Thank You!</p>
]]></content:encoded></item><item><title><![CDATA[Learning Routes in Flutter]]></title><description><![CDATA[Flutter is an open source framework by Google for building beautiful, natively compiled, multi-platform applications from a single codebase.
In this article, we are going to learn about routing in Flutter, how we can navigate from one screen to anoth...]]></description><link>https://blog.sarthakag.dev/learning-routes-in-flutter</link><guid isPermaLink="true">https://blog.sarthakag.dev/learning-routes-in-flutter</guid><category><![CDATA[Flutter]]></category><category><![CDATA[Developer]]></category><category><![CDATA[Dart]]></category><category><![CDATA[navigation]]></category><category><![CDATA[routes]]></category><dc:creator><![CDATA[Sarthak Agarwal]]></dc:creator><pubDate>Sun, 28 Aug 2022 14:39:42 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/unsplash/Gll-v69L8iA/upload/v1661697319941/MGusCUwMp.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Flutter is an open source framework by Google for building beautiful, natively compiled, multi-platform applications from a single codebase.</p>
<p>In this article, we are going to learn about routing in Flutter, how we can navigate from one screen to another, with custom arguments, simple clean and reusable code, in structured format</p>
<p><strong>I am assuming you already know basics of Flutter (create simple widgets, functions and classes.)</strong>. We are specifically going to see how to use named routes, and learn how to use them in managing routes easily!</p>
<p> Below is the GitHub link, you can follow each step using this repository.</p>
<p>https://github.com/Sarthak-ONS/simple-routing.git</p>
<p>After removing the initial written code by Flutter, lets start.</p>
<pre><code><span class="hljs-keyword">import</span> <span class="hljs-symbol">'package</span>:flutter/material.dart';

void main() {
  runApp(const <span class="hljs-type">MyApp</span>());
}

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyApp</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">StatelessWidget</span> </span>{
  const <span class="hljs-type">MyApp</span>({<span class="hljs-type">Key</span>? key}) : <span class="hljs-keyword">super</span>(key: key);

  <span class="hljs-comment">// This widget is the root of your application.</span>
  <span class="hljs-meta">@override</span>
  <span class="hljs-type">Widget</span> build(<span class="hljs-type">BuildContext</span> context) {
    <span class="hljs-keyword">return</span> const <span class="hljs-type">MaterialApp</span>(
      debugShowCheckedModeBanner: <span class="hljs-literal">false</span>,
      title: <span class="hljs-symbol">'Flutter</span> <span class="hljs-type">Demo</span>',
      home: <span class="hljs-type">Text</span>(<span class="hljs-string">"Learn Routing"</span>),
    );
  }
}
</code></pre><p>Lets us make three simple different screen and learn routing from them. Create a new Folder and add three separate files for three screens respectively.</p>
<p>Note: you can name these files as per your choice</p>
<p> We are going to make a button widget and put it in a separate file, this button widget is used for navigating to different screens.</p>
<p>This button widget takes two parameters- 1. Title of Button 2. On tap Callback.</p>
<p>Lets make this button widget</p>
<pre><code><span class="hljs-keyword">import</span> <span class="hljs-string">'package:flutter/material.dart'</span>;

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyCustomButton</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">StatelessWidget</span> </span>{
  <span class="hljs-keyword">const</span> MyCustomButton({
    Key? key,
    <span class="hljs-keyword">required</span> <span class="hljs-keyword">this</span>.title,
    <span class="hljs-keyword">required</span> <span class="hljs-keyword">this</span>.onTapFunction,
  }) : <span class="hljs-keyword">super</span>(key: key);

  <span class="hljs-keyword">final</span> <span class="hljs-built_in">String</span> title;
  <span class="hljs-keyword">final</span> <span class="hljs-built_in">Function</span> onTapFunction;

  <span class="hljs-meta">@override</span>
  Widget build(BuildContext context) {
    <span class="hljs-keyword">return</span> GestureDetector(
      onTap: () {
        onTapFunction();
      },
      child: Center(
        child: Container(
          margin: <span class="hljs-keyword">const</span> EdgeInsets.symmetric(vertical: <span class="hljs-number">10</span>, horizontal: <span class="hljs-number">20.0</span>),
          padding: <span class="hljs-keyword">const</span> EdgeInsets.symmetric(vertical: <span class="hljs-number">10</span>, horizontal: <span class="hljs-number">20.0</span>),
          decoration: <span class="hljs-keyword">const</span> BoxDecoration(
            color: Color(<span class="hljs-number">0xff263F59</span>),
            borderRadius: BorderRadius.all(
              Radius.circular(<span class="hljs-number">15.0</span>),
            ),
          ),
          child: Text(
            title,
            style: <span class="hljs-keyword">const</span> TextStyle(
              color: Colors.white,
              fontSize: <span class="hljs-number">20</span>,
            ),
          ),
        ),
      ),
    );
  }
}
</code></pre><p>Lets now make our first screen with basic widgets like App Bar and two custom built button at the center of the screens.</p>
<pre><code><span class="hljs-keyword">import</span> <span class="hljs-symbol">'package</span>:flutter/material.dart';

<span class="hljs-keyword">import</span> '../custom_button_widget.dart';

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Screen1</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">StatelessWidget</span> </span>{
  const <span class="hljs-type">Screen1</span>({<span class="hljs-type">Key</span>? key}) : <span class="hljs-keyword">super</span>(key: key);

  <span class="hljs-meta">@override</span>
  <span class="hljs-type">Widget</span> build(<span class="hljs-type">BuildContext</span> context) {
    <span class="hljs-keyword">return</span> <span class="hljs-type">Scaffold</span>(
      appBar: <span class="hljs-type">AppBar</span>(
        centerTitle: <span class="hljs-literal">true</span>,
        backgroundColor: const <span class="hljs-type">Color</span>(<span class="hljs-number">0xff263F59</span>),
        title: const <span class="hljs-type">Text</span>(<span class="hljs-symbol">'First</span> <span class="hljs-type">Screen</span>'),
      ),
      body: <span class="hljs-type">Column</span>(
        mainAxisAlignment: <span class="hljs-type">MainAxisAlignment</span>.center,
        children: [
          <span class="hljs-type">MyCustomButton</span>(
            onTapFunction: () {
              print(<span class="hljs-string">"Navigate to Screen 2"</span>);
            },
            title: <span class="hljs-string">"Screen 2"</span>,
          ),
          <span class="hljs-type">MyCustomButton</span>(
            onTapFunction: () {
             print(<span class="hljs-string">"Navigate to Screen 3"</span>);
            },
            title: <span class="hljs-string">"Screen 3"</span>,
          ),
        ],
      ),
    );
  }
}
</code></pre><p>Now, our first Screen looks like this - </p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1661696229325/gYl62P8Gd.jpeg" alt="Screen1.jpeg" /></p>
<p>Similarly we will make our second and third screen.</p>
<p>Note : Please change title of App Bar and Custom Buttons accordingly to avoid any errors.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1661696372835/wn9EsA8Gt.jpeg" alt="Screen2.jpeg" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1661696377372/eTSq1Q2Tw.jpeg" alt="Screen3.jpeg" /></p>
<p><strong>Please, check the source code on GitHub for any kinds of errors and problems.</strong></p>
<p>Now, we will create a Route Generator File and add all our route in in it. Lets see how we can do it.</p>
<p>First create a new file, then add  a Route Generator Class and add two methods in it, First method, will return a Material Page Route to a specific Screen and second method will return a error Screen, if in case there occurs any error we can return that screen.</p>
<p>We are using named route,  using Route Settings we can get the name of each called route.</p>
<p><strong>Note : We are repeating code for now, but in later section we will remove this repeating code
</strong></p>
<pre><code><span class="hljs-keyword">import</span> <span class="hljs-string">'package:flutter/material.dart'</span>;

<span class="hljs-keyword">import</span> <span class="hljs-string">'package:simple_routing/Screens/screen_one.dart'</span>;
<span class="hljs-keyword">import</span> <span class="hljs-string">'package:simple_routing/Screens/screen_two.dart'</span>;
<span class="hljs-keyword">import</span> <span class="hljs-string">'package:simple_routing/Screens/screen_third.dart'</span>;

class RouteGenerator {

  Route<span class="hljs-operator">&lt;</span>dynamic<span class="hljs-operator">&gt;</span> generateRoute(RouteSettings routeSettings) {
    switch (routeSettings.<span class="hljs-built_in">name</span>) {
      case <span class="hljs-string">'/'</span>:
        <span class="hljs-keyword">return</span> MaterialPageRoute(builder: (<span class="hljs-keyword">_</span>) <span class="hljs-operator">=</span><span class="hljs-operator">&gt;</span> const Screen1());
      case <span class="hljs-string">'/second'</span>:
        <span class="hljs-keyword">return</span> MaterialPageRoute(builder: (<span class="hljs-keyword">_</span>) <span class="hljs-operator">=</span><span class="hljs-operator">&gt;</span> const Screen2());
      case <span class="hljs-string">'/third'</span>:
        <span class="hljs-keyword">return</span> MaterialPageRoute(builder: (<span class="hljs-keyword">_</span>) <span class="hljs-operator">=</span><span class="hljs-operator">&gt;</span> const Screen3());
      default:
        <span class="hljs-keyword">return</span> _errorRoute();
    }
  }

  static Route<span class="hljs-operator">&lt;</span>dynamic<span class="hljs-operator">&gt;</span> _errorRoute() {
    <span class="hljs-keyword">return</span> MaterialPageRoute(
      builder: (<span class="hljs-keyword">_</span>) <span class="hljs-operator">=</span><span class="hljs-operator">&gt;</span> Scaffold(
        appBar: AppBar(
          title: const Text(<span class="hljs-string">'Error'</span>),
        ),
        body: const Center(
          child: Text(<span class="hljs-string">'Please try again later'</span>),
        ),
      ),
    );
  }
}
</code></pre><p>Now, we will add this generateRoute Method to our material App widget in main.dart file. We will remove "home" parameter in Material App and pass a initial Screen Route to "initialRoute" parameter, we will give '/' as a initialRoute parameter's value, which corresponds to First Screen in our generateRoute Method of Route Generator Class.</p>
<pre><code><span class="hljs-keyword">import</span> <span class="hljs-symbol">'package</span>:flutter/material.dart';
<span class="hljs-keyword">import</span> <span class="hljs-symbol">'package</span>:simple_routing/route_generator.dart';

void main() {
  runApp(const <span class="hljs-type">MyApp</span>());
}

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyApp</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">StatelessWidget</span> </span>{
  const <span class="hljs-type">MyApp</span>({<span class="hljs-type">Key</span>? key}) : <span class="hljs-keyword">super</span>(key: key);

  <span class="hljs-comment">// This widget is the root of your application.</span>
  <span class="hljs-meta">@override</span>
  <span class="hljs-type">Widget</span> build(<span class="hljs-type">BuildContext</span> context) {
    <span class="hljs-keyword">return</span> <span class="hljs-type">MaterialApp</span>(
      debugShowCheckedModeBanner: <span class="hljs-literal">false</span>,
      initialRoute: '/',
      onGenerateRoute: <span class="hljs-type">RouteGenerator</span>().generateRoute,
    );
  }
}
</code></pre><p>Lets, start navigating using Route generator class. Now, go to screen1, and in onTapCallback of Screen2's button, navigate to screen2.  Similarly, on tapCallback of Screen3's button, navigate to Screen3.
We are going to use Navigator.pushNamed() method to navigate between screens.</p>
<pre><code>MyCustomButton(
        onTapFunction: () {
              Navigator.pushNamed(context, <span class="hljs-string">'/second'</span>);
         },
        title: <span class="hljs-string">"Screen 2"</span>,
  ),
MyCustomButton(
          onTapFunction: () {
              Navigator.pushNamed(context, <span class="hljs-string">'/third'</span>);
          },
         title: <span class="hljs-string">"Screen 3"</span>,
  ),
</code></pre><p>Now,  you may add named route in callbacks of buttons of Screen2 and Screen3 respectively.</p>
<p>Note: On using  Navigator.pushNamed() method, screens are added to the stack, it means next screen are added to top of current screen, You can use Navigator.popAndPushNamed() to remove current screen from stack and then push to next screen.</p>
<p>I hope you will now be able to route between different screens!.</p>
<p>We can also check error Route, passing wrong arguments in Navigator.pushNamed() method, or not passing any value in method that does not corresponds to mentioned names in Route generator Class.</p>
<p>Lastly, we can also avoid using the "MaterialPageRoute(builder: (_) =&gt; const Screen1())" again and again in Route Generator Class by making a new method, that takes a widget in in its parameter and returns a Material Page Route.</p>
<pre><code><span class="hljs-keyword">import</span> <span class="hljs-string">'package:flutter/material.dart'</span>;

<span class="hljs-keyword">import</span> <span class="hljs-string">'package:simple_routing/Screens/screen_one.dart'</span>;
<span class="hljs-keyword">import</span> <span class="hljs-string">'package:simple_routing/Screens/screen_two.dart'</span>;
<span class="hljs-keyword">import</span> <span class="hljs-string">'package:simple_routing/Screens/screen_third.dart'</span>;

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">RouteGenerator</span> </span>{
  <span class="hljs-function">Route&lt;dynamic&gt; <span class="hljs-title">generateRoute</span><span class="hljs-params">(RouteSettings routeSettings)</span> </span>{
    <span class="hljs-keyword">switch</span> (routeSettings.name) {
      <span class="hljs-keyword">case</span> <span class="hljs-string">'/'</span>:
        <span class="hljs-keyword">return</span> getMaterialPageRoute(<span class="hljs-function"><span class="hljs-keyword">const</span> <span class="hljs-title">Screen1</span><span class="hljs-params">()</span>)</span>;
      <span class="hljs-keyword">case</span> <span class="hljs-string">'/second'</span>:
        <span class="hljs-keyword">return</span> getMaterialPageRoute(<span class="hljs-function"><span class="hljs-keyword">const</span> <span class="hljs-title">Screen2</span><span class="hljs-params">()</span>)</span>;
      <span class="hljs-keyword">case</span> <span class="hljs-string">'/third'</span>:
        <span class="hljs-keyword">return</span> getMaterialPageRoute(<span class="hljs-function"><span class="hljs-keyword">const</span> <span class="hljs-title">Screen3</span><span class="hljs-params">()</span>)</span>;
      <span class="hljs-keyword">default</span>:
        <span class="hljs-keyword">return</span> _errorRoute();
    }
  }

  <span class="hljs-function"><span class="hljs-keyword">static</span> Route&lt;dynamic&gt; <span class="hljs-title">_errorRoute</span><span class="hljs-params">()</span> </span>{
    <span class="hljs-keyword">return</span> MaterialPageRoute(
      builder: (_) =&gt; Scaffold(
        appBar: AppBar(
          title: <span class="hljs-function"><span class="hljs-keyword">const</span> <span class="hljs-title">Text</span><span class="hljs-params">(<span class="hljs-string">'Error'</span>)</span>,
        ),
        body: <span class="hljs-keyword">const</span> <span class="hljs-title">Center</span><span class="hljs-params">(
          child: Text(<span class="hljs-string">'Please try again later'</span>)</span>,
        ),
      ),
    )</span>;
  }

  <span class="hljs-function">MaterialPageRoute <span class="hljs-title">getMaterialPageRoute</span><span class="hljs-params">(Widget widget)</span> </span>{
    <span class="hljs-keyword">return</span> MaterialPageRoute(builder: (_) =&gt; widget);
  }
}
</code></pre><p>Thus we can avoid repeating code, increase code reusability. We don't have to use "Navigator.push(context, MaterialPageRoute(builder: (context) =&gt;widget()),);" route Function again and again and  avoid  import screens in each file. Our code looks clean and way better now.</p>
<p>Please check the GitHub repository for complete code.</p>
<p>I hope this article have created some help for you!
Please share it with other developers</p>
]]></content:encoded></item></channel></rss>