<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Rahul sawra</title>
    <description>The latest articles on DEV Community by Rahul sawra (@im_rsawra).</description>
    <link>https://dev.to/im_rsawra</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F691931%2Ff10a9e3c-bf24-4c92-bb09-330f9038378e.jpg</url>
      <title>DEV Community: Rahul sawra</title>
      <link>https://dev.to/im_rsawra</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/im_rsawra"/>
    <language>en</language>
    <item>
      <title>Harnessing the Power of Generics in Go: A Comprehensive Guide - Part I</title>
      <dc:creator>Rahul sawra</dc:creator>
      <pubDate>Sun, 30 Jul 2023 10:36:01 +0000</pubDate>
      <link>https://dev.to/im_rsawra/harnessing-the-power-of-generics-in-go-a-comprehensive-guide-part-i-4c13</link>
      <guid>https://dev.to/im_rsawra/harnessing-the-power-of-generics-in-go-a-comprehensive-guide-part-i-4c13</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Go,has gained significant popularity for its simplicity, efficiency, and concurrency features. However, one critical feature that has been missing for a long time was generics. Generic programming enables developers to write code that can work with different data types, making code more flexible, reusable, and less error-prone. With the introduction of generics in Go 1.18, the language has taken a giant leap forward, empowering developers to tackle complex problems with greater elegance and efficiency. In this blog post, we'll dive into the world of generics in Go and explore how this new feature revolutionizes the way we write code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Need for Generics&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Before the introduction of generics in Go, developers had to rely on interfaces or write type-specific code to handle various data types. While interfaces allowed some level of abstraction, they often introduced performance overhead and forced developers to compromise on type safety. Additionally, code duplication was common when dealing with multiple data types, leading to maintainability challenges.&lt;/p&gt;

&lt;p&gt;Generics address these limitations by enabling the creation of functions, data structures, and algorithms that work with any type while maintaining strict type safety. This means developers can write code once and apply it to multiple data types, resulting in cleaner, more maintainable, and efficient programs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Type Parameters and Type Constraints&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;At the core of generics are type parameters, which are placeholders for specific types used within a generic function or data structure.&lt;br&gt;
Functions and types are now permitted to have type parameters. A type parameter list looks like an ordinary parameter list, except that it uses square brackets instead of parentheses.&lt;/p&gt;

&lt;p&gt;To show how this works, let’s start with the basic non-generic Min function for floating point values:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;func Min(x, y float64) float64 {
    if x &amp;lt; y {
        return x
    }
    return y
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above function &lt;code&gt;Min()&lt;/code&gt; only works for floating type values. In order to calculate Min() of integers you need to write a seperate function (or use interfaces).&lt;/p&gt;

&lt;p&gt;We can make this function generic–make it work for different types–by adding a type parameter list. In this example we add a type parameter list with a single type parameter T, and replace the uses of float64 with T.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import "golang.org/x/exp/constraints"

func GMin[T constraints.Ordered](x, y T) T {
    if x &amp;lt; y {
        return x
    }
    return y
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It is now possible to call this function with a type argument by writing a call like&lt;/p&gt;

&lt;p&gt;&lt;code&gt;x := GMin[int](2, 3)&lt;/code&gt;&lt;br&gt;
&lt;code&gt;y := GMin[float64](2.1, 3.1)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Type constraints play a crucial role in ensuring type safety while using generics. By specifying constraints, developers limit the types that can be used with a generic function, preventing misuse and providing better error messages during compilation.&lt;/p&gt;

&lt;p&gt;In the generic GMin implementation, the type constraint is obtained from the constraints package. &lt;br&gt;
&lt;code&gt;constraints.Ordered&lt;/code&gt; is a type constraint.&lt;/p&gt;

&lt;p&gt;Specifically, the Ordered constraint is responsible for defining the set of types whose values can be ordered, i.e., compared using operators such as &amp;lt;, &amp;lt;=, &amp;gt;, etc. This constraint guarantees that only types with comparable values can be used in GMin.&lt;/p&gt;

&lt;p&gt;It's important to note that in Go, type constraints are required to be implemented as interfaces.&lt;/p&gt;

&lt;p&gt;We look at the interfaces in a new way now.&lt;br&gt;
Until recently, the Go spec said that an interface defines a method set, which is roughly the set of methods enumerated in the interface. Any type that implements all those methods implements that interface.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4AIhS5c3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aqskqjmm3qyo7heutaqq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4AIhS5c3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aqskqjmm3qyo7heutaqq.png" alt="Go Interfaces" width="800" height="386"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can now define type set in a interface. For instance, interface{ int|string|bool } defines the type set containing the types int, string, and bool.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZkXxmv73--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wwhoxk54unwyip1808nb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZkXxmv73--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wwhoxk54unwyip1808nb.png" alt="type-sets" width="800" height="330"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Another way of saying this is that this interface is satisfied by only int, string, or bool.&lt;br&gt;
Now let’s look at the actual definition of constraints.Ordered:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type Ordered interface {
    Integer|Float|~string
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This declaration says that the Ordered interface is the set of all integer, floating-point, and string types. The vertical bar expresses a union of types. Integer and Float are interface types that are similarly defined in the constraints package. Note that there are no methods defined by the Ordered interface.&lt;/p&gt;

&lt;p&gt;Now let's look at a simple example where a func &lt;code&gt;SumIntsOrFloats&lt;/code&gt; is a generic function that sums the values of map m. It supports value of both types int64 and float64.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package main

import (
    "fmt" 
)

// SumIntsOrFloats sums the values of map m. It supports both int64 and float64
// as types for map values.
// K avd V are type params
// comparable = type constraint (built in)
// Number = type constraint
type Number interface {
    int64 | float64
}

func SumIntsOrFloats[K comparable, V Number](m map[K]V) V {
    var s V
    for _, v := range m {
        s += v
    }
    return s
}

func main() {
    // Initialize a map for the integer values
    ints := map[string]int64{
        "first":  34,
        "second": 12,
    }

    // Initialize a map for the float values
    floats := map[string]float64{
        "first":  35.98,
        "second": 26.99,
    }
    fmt.Printf("Generic Sums: %v and %v\n",
    SumIntsOrFloats(ints),
    SumIntsOrFloats(floats))
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;go run main.go 
Generic Sums: 46 and 62.97
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Well, that's all about generics in this blog. We will dive deep into generics in coming blogs and look at more use cases.&lt;/p&gt;

&lt;p&gt;Reach out to me, if you want to discuss anything about GO! :D&lt;br&gt;
Twitter - &lt;a href="https://twitter.com/im_rsawra"&gt;https://twitter.com/im_rsawra&lt;/a&gt;&lt;br&gt;
LinkedIn - &lt;a href="https://www.linkedin.com/in/rahul-sawra/"&gt;https://www.linkedin.com/in/rahul-sawra/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Ref: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://go.dev/blog/intro-generics"&gt;https://go.dev/blog/intro-generics&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://youtu.be/Pa_e9EeCdy8"&gt;https://youtu.be/Pa_e9EeCdy8&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>go</category>
      <category>generics</category>
      <category>programming</category>
    </item>
    <item>
      <title>Strategy Design Pattern in Go</title>
      <dc:creator>Rahul sawra</dc:creator>
      <pubDate>Wed, 16 Feb 2022 13:17:40 +0000</pubDate>
      <link>https://dev.to/im_rsawra/strategy-design-pattern-in-go-77e</link>
      <guid>https://dev.to/im_rsawra/strategy-design-pattern-in-go-77e</guid>
      <description>&lt;p&gt;According to Wikipedia,&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The strategy pattern (also known as the policy pattern) is a behavioral software design pattern that enables selecting an algorithm at runtime. Instead of implementing a single algorithm directly, code receives run-time instructions as to which in a family of algorithms to use&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The strategy design pattern comes under the behavioural pattern.&lt;br&gt;
&lt;strong&gt;Strategy design pattern&lt;/strong&gt; turns a set of behaviors(strategies) into objects and makes them interchangable inside original context object.&lt;br&gt;
We create objects which represent various strategies and a context object(original object),which holds a reference to a strategy object and delegates it executing the behaviour.&lt;br&gt;
In order to change the context object perform its work, other objects may replace the currently linked strategy object with another one.&lt;/p&gt;
&lt;h2&gt;
  
  
  Example
&lt;/h2&gt;

&lt;p&gt;Suppose we are building an in-memory cache.Since, the size of an im-memory cache is limited, whenever it reaches its maximum size alloted, some enteries have to be removed in order to free up the space. This task can happen via several algorithms:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;First In , First Out (FIFO) - remove an entry from in memory cache , that was created first.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Least Recently Used (LRU) - remove an entry from in memory cache, that has been used least recently&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Least Frequently Used (LFU) - remove an entry from in memory cache, that has been used least frequently&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The main idea is to decouple the cache object/class from these algorithms (strategies) so that we can change the algorithm at runtime.&lt;/p&gt;

&lt;p&gt;Also, the original cache class should not change when a new algorithm is being added in the future.&lt;/p&gt;

&lt;p&gt;This is where &lt;strong&gt;Strategy Pattern&lt;/strong&gt; comes into play. It basically suggests to create the family of algorithms and each algorithm having its own class. Each of these classes implement the same interface and this way the algorithm becomes interchangable within the family.&lt;/p&gt;

&lt;p&gt;Lets say the common interface name is &lt;code&gt;evictionAlgo&lt;/code&gt;&lt;br&gt;
evictionAlgo.go: Strategy Interface&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fauziq0rcya6chojgfgxy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fauziq0rcya6chojgfgxy.png" alt="Strategy Interface"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;fifo.go: Strategy&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkr2h5lq4dqg20ptqqviu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkr2h5lq4dqg20ptqqviu.png" alt="fifo.go"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;lru.go: Strategy&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F33hfvhfnh3lwsaa2dq35.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F33hfvhfnh3lwsaa2dq35.png" alt="lru.go"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;lfu.go: Strategy&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F03nmh9p724agqjyl5tff.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F03nmh9p724agqjyl5tff.png" alt="lfu.go"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;cache.go: Context&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F910ohektwm7biujr2wz8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F910ohektwm7biujr2wz8.png" alt="cache context object"&gt;&lt;/a&gt;&lt;br&gt;
Here as you can see , the original context object(cache) holds a reference to a strategy interface(evictionAlgo). &lt;/p&gt;

&lt;p&gt;main.go: Client Code&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4trksng8b0mf7jfdfaws.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4trksng8b0mf7jfdfaws.png" alt="main.go"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Evicting by lfu strtegy
Evicting by lru strtegy
Evicting by fifo strtegy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>go</category>
      <category>programming</category>
    </item>
    <item>
      <title>Taints and Tolerations in Kubernetes</title>
      <dc:creator>Rahul sawra</dc:creator>
      <pubDate>Tue, 24 Aug 2021 06:42:24 +0000</pubDate>
      <link>https://dev.to/im_rsawra/taints-and-tolerations-in-kubernetes-19ck</link>
      <guid>https://dev.to/im_rsawra/taints-and-tolerations-in-kubernetes-19ck</guid>
      <description>&lt;p&gt;In this blogpost, we'll learn about Taints and Tolerations in Kubernetes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Taints&lt;/strong&gt;&lt;br&gt;
Taints are the property of nodes , that is used to repel the pods if they don't tolerate this taint.&lt;br&gt;
Taints can be applied on the nodes just like labels.&lt;br&gt;
This means that only those pods that are tolerant to the taints , will be scheduled on that node.&lt;/p&gt;

&lt;p&gt;To apply a taint on a node:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl taint nodes &amp;lt;node_name&amp;gt; key1=value1:taint_effect
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;places the taint on node.The taint has key=key1,value=value1 and a taint_effect&lt;/p&gt;

&lt;p&gt;taint_effect can take 3 different values:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;NoSchedule&lt;/strong&gt;: If this effect is applied to the node , then the pods that are tolerant to all the taints applied on the node, are only scheduled on this node.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;PreferNoSchedule&lt;/strong&gt;: In this case, the system will try to avoid placing a pod that does not tolerate the taint on the node, but it is not required.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;NoExecute&lt;/strong&gt;: In this case, the new pods that do not match the taint are not scheduled on the node and existing pods on the node will also be evicted if they do not tolerate all the taints.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Tolerations&lt;/strong&gt;&lt;br&gt;
Tolerations are applied on the pods,that allow the pods to schedule on the nodes with matching taints.&lt;/p&gt;

&lt;p&gt;We apply the toleration for a Pod in PodSpec.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;tolerations&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;key&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;key1"&lt;/span&gt;
      &lt;span class="na"&gt;operator&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Equal"&lt;/span&gt;
      &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;value1"&lt;/span&gt;
      &lt;span class="na"&gt;effect&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;NoSchedule"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By Default the value of operator is &lt;em&gt;Equal&lt;/em&gt;&lt;br&gt;
A toleration "matches" a taint if the keys are the same and the effects are the same, and:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the operator is Exists (in which case no value should be specified), or&lt;/li&gt;
&lt;li&gt;the operator is Equal and the values are equal.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let us take an example&lt;br&gt;
Suppose we have two worker nodes node01 and node02&lt;br&gt;
We apply the taints to nodes as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl taint nodes node01 key1=value1:NoSchedule
kubectl taint nodes node02 key2=value2:NoExecute
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And then we apply toleration to a pod as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;apiVersion&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;v1&lt;/span&gt;
&lt;span class="na"&gt;kind&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Pod&lt;/span&gt;
&lt;span class="na"&gt;metadata&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;nginx-pod&lt;/span&gt;
&lt;span class="na"&gt;spec&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;containers&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
       &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;nginx&lt;/span&gt;
         &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;nginx-container&lt;/span&gt;
    &lt;span class="na"&gt;tolerations&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;key&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;key1"&lt;/span&gt;
          &lt;span class="na"&gt;operator&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Equals"&lt;/span&gt;
          &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;value1"&lt;/span&gt;
          &lt;span class="na"&gt;effect&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;NoSchedule"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this case the pod will be scheduled on node01 since it has the toleration to its taint. &lt;/p&gt;

&lt;p&gt;Ever wondered why the pods are not scheduled on master(controlplane) nodes?&lt;br&gt;
Because it has a taint &lt;code&gt;node-role.kubernetes.io/master=true:NoSchedule&lt;/code&gt;&lt;br&gt;
which prevents pods from being scheduled unless otherwise untainted the master node. &lt;br&gt;
Using Taints and Tolerations , we can create nodes that are reserved(dedicated) for specific pods.&lt;/p&gt;

&lt;p&gt;Ref: &lt;a href="https://kubernetes.io/docs/concepts/scheduling-eviction/taint-and-toleration/"&gt;https://kubernetes.io/docs/concepts/scheduling-eviction/taint-and-toleration/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>kubernetes</category>
      <category>devops</category>
      <category>sre</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
