<?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: Itamar Knafo</title>
    <description>The latest articles on DEV Community by Itamar Knafo (@itamadev).</description>
    <link>https://dev.to/itamadev</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%2F662849%2Ff1b92026-69f5-4489-8c65-709cea8239b0.png</url>
      <title>DEV Community: Itamar Knafo</title>
      <link>https://dev.to/itamadev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/itamadev"/>
    <language>en</language>
    <item>
      <title>Bootstrap your Blog</title>
      <dc:creator>Itamar Knafo</dc:creator>
      <pubDate>Sat, 03 Jun 2023 13:20:25 +0000</pubDate>
      <link>https://dev.to/itamadev/bootstrap-your-blog-1kbc</link>
      <guid>https://dev.to/itamadev/bootstrap-your-blog-1kbc</guid>
      <description>&lt;p&gt;Here we will go through how to bootstrap your own blog using Hugo and fly.io.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;Here is a list of toolings you will need to have installed on your machine:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://gohugo.io"&gt;Hugo&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://fly.io"&gt;fly.io&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://git-scm.com"&gt;git&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://github.com"&gt;GitHub&lt;/a&gt; account&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Optional:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://golang.org"&gt;Golang&lt;/a&gt; (optional, but I will be using it in this guide)&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.docker.com"&gt;Docker&lt;/a&gt; (optional, only needed to run the blog locally using Docker)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Create a new Hugo site
&lt;/h2&gt;

&lt;p&gt;First, we need to create a new Hugo site. To do so, we will use the &lt;code&gt;hugo mod init&lt;/code&gt; command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;hugo mod init github.com/&amp;lt;username&amp;gt;/&amp;lt;repo-name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will populate your project directory with the following structure:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;your-project
├── public/
├── resources/
└── go.mod
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Add a theme
&lt;/h2&gt;

&lt;p&gt;Next, we need to add a theme to our blog. For this guide, I will be using the &lt;a href="https://themes.gohugo.io/blowfish/"&gt;blowfish&lt;/a&gt; theme. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Now we want to add the theme to our blog, so we will reference it in our &lt;code&gt;config/_default/module.toml&lt;/code&gt; file:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight toml"&gt;&lt;code&gt;&lt;span class="c"&gt;# config/_default/module.toml&lt;/span&gt;
&lt;span class="nn"&gt;[[imports]]&lt;/span&gt;
&lt;span class="py"&gt;path&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"github.com/nunocoracao/blowfish/v2"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Start your server using &lt;code&gt;hugo server&lt;/code&gt; and the theme will be downloaded automatically.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the root folder of your website, delete the config.toml file that was generated by Hugo. Copy the *.toml config files from the theme into your config/_default/ folder, &lt;a href="https://minhaskamal.github.io/DownGit/#/home?url=https:%2F%2Fgithub.com%2Fnunocoracao%2Fblowfish%2Ftree%2Fmain%2Fconfig%2F_default"&gt;download a copy from here&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Do not overwrite the &lt;code&gt;module.toml&lt;/code&gt; file you created above!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now so far if we run &lt;code&gt;hugo server&lt;/code&gt; we will see the following when we access &lt;a href="http://localhost:1313"&gt;http://localhost:1313&lt;/a&gt;:&lt;/p&gt;

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

&lt;p&gt;From here you can start working on your blog following the &lt;a href="https://blowfish.page/docs/getting-started/"&gt;blowfish theme documentation&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Recomnadation:&lt;/strong&gt; I recommend you use vendoring to manage your theme dependencies. &lt;/p&gt;

&lt;p&gt;To do so, you can use the &lt;code&gt;hugo mod vendor&lt;/code&gt; command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;hugo mod vendor
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Add a Dockerfile
&lt;/h2&gt;

&lt;p&gt;Now that we have our blog ready, we need to add a Dockerfile to our project so we can deploy it to fly.io.&lt;/p&gt;

&lt;p&gt;Create a new file called &lt;code&gt;Dockerfile&lt;/code&gt; in the root of your project and add the following content:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;&lt;span class="k"&gt;FROM&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;golang:1.19.0-buster&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;AS&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;build&lt;/span&gt;

&lt;span class="k"&gt;RUN &lt;/span&gt;apt update &lt;span class="nt"&gt;-y&lt;/span&gt; 
&lt;span class="k"&gt;RUN &lt;/span&gt;apt &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-y&lt;/span&gt; wget
&lt;span class="c"&gt;# Install Hugo&lt;/span&gt;
&lt;span class="k"&gt;RUN &lt;/span&gt;wget https://github.com/gohugoio/hugo/releases/download/v0.106.0/hugo_extended_0.106.0_linux-amd64.deb
&lt;span class="k"&gt;RUN &lt;/span&gt;dpkg &lt;span class="nt"&gt;-i&lt;/span&gt; hugo_extended_0.106.0_linux-amd64.deb
&lt;span class="k"&gt;RUN &lt;/span&gt;apt-get &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt;

&lt;span class="k"&gt;WORKDIR&lt;/span&gt;&lt;span class="s"&gt; /var/hugo/src&lt;/span&gt;
&lt;span class="k"&gt;COPY&lt;/span&gt;&lt;span class="s"&gt; . .&lt;/span&gt;
&lt;span class="k"&gt;RUN &lt;/span&gt;hugo &lt;span class="nt"&gt;--minify&lt;/span&gt;

&lt;span class="k"&gt;EXPOSE&lt;/span&gt;&lt;span class="s"&gt; 1313&lt;/span&gt;
&lt;span class="k"&gt;CMD&lt;/span&gt;&lt;span class="s"&gt; ["hugo", "server", "--bind", "0.0.0.0"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can try running &lt;code&gt;docker build .&lt;/code&gt; to build your image locally and see your docker hosted blog.&lt;/p&gt;

&lt;h2&gt;
  
  
  Important Configurations
&lt;/h2&gt;

&lt;p&gt;Before we jump and deploy our blog to fly, we need to configure the &lt;code&gt;baseURL&lt;/code&gt; of our blog.&lt;/p&gt;

&lt;p&gt;Add a &lt;code&gt;baseURL&lt;/code&gt; to our &lt;code&gt;config/_default/config.toml&lt;/code&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight toml"&gt;&lt;code&gt;&lt;span class="c"&gt;# config/_default/config.toml&lt;/span&gt;
&lt;span class="py"&gt;baseURL&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"https://&amp;lt;your-app-name&amp;gt;.fly.dev"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Hosting on fly.io
&lt;/h2&gt;

&lt;p&gt;Now we can create a new app on fly.io. &lt;/p&gt;

&lt;p&gt;To do so, we will use the &lt;code&gt;fly launch&lt;/code&gt; command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;fly launch
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The command will prompt you with a few questions about your app like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;? App Name &lt;span class="o"&gt;(&lt;/span&gt;leave blank to use an auto-generated name&lt;span class="o"&gt;)&lt;/span&gt;:
? Select organization: You &lt;span class="o"&gt;(&lt;/span&gt;personal&lt;span class="o"&gt;)&lt;/span&gt;
? Select region: lax &lt;span class="o"&gt;(&lt;/span&gt;Los Angeles, California &lt;span class="o"&gt;(&lt;/span&gt;US&lt;span class="o"&gt;))&lt;/span&gt;
Created app &lt;span class="k"&gt;***&lt;/span&gt; &lt;span class="k"&gt;in &lt;/span&gt;organization personal
Wrote config file fly.toml
? Would you like to deploy now? &lt;span class="o"&gt;(&lt;/span&gt;y/N&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;launch&lt;/code&gt; command generates a &lt;code&gt;fly.toml&lt;/code&gt; file for your project with the settings. You can deploy right away, or add some config first.&lt;/p&gt;

&lt;p&gt;Now your &lt;code&gt;fly.toml&lt;/code&gt; file should look something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight toml"&gt;&lt;code&gt;&lt;span class="py"&gt;app&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"&amp;lt;app-name&amp;gt;"&lt;/span&gt;
&lt;span class="py"&gt;primary_region&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"&amp;lt;region-name&amp;gt;"&lt;/span&gt;

&lt;span class="nn"&gt;[http_service]&lt;/span&gt;
  &lt;span class="py"&gt;internal_port&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1313&lt;/span&gt;
  &lt;span class="py"&gt;force_https&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
  &lt;span class="py"&gt;auto_stop_machines&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
  &lt;span class="py"&gt;auto_start_machines&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
  &lt;span class="py"&gt;min_machines_running&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Automatic Deployment with GitHub Actions
&lt;/h2&gt;

&lt;p&gt;Now that we have our blog ready, we need to automate the deployment process. To do so, we will use &lt;code&gt;GitHub Actions&lt;/code&gt;.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;First, we need to create a new file called &lt;code&gt;.github/workflows/deploy.yml&lt;/code&gt; with the following content:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="c1"&gt;# .github/workflows/deploy.yml&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;Fly Deploy&lt;/span&gt;
&lt;span class="na"&gt;on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;push&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;branches&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;main&lt;/span&gt;
&lt;span class="na"&gt;jobs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;deploy&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;Deploy app&lt;/span&gt;
    &lt;span class="na"&gt;runs-on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ubuntu-latest&lt;/span&gt;
    &lt;span class="na"&gt;environment&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;production&lt;/span&gt;
    &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;actions/checkout@v3&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;superfly/flyctl-actions/setup-flyctl@master&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;flyctl deploy --remote-only&lt;/span&gt;
        &lt;span class="na"&gt;env&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
&lt;span class="kt"&gt;![Image&lt;/span&gt; &lt;span class="s"&gt;description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j0q7n4nbdlug9c0tjozb.png)&lt;/span&gt;


          &lt;span class="s"&gt;FLY_API_TOKEN&lt;/span&gt;&lt;span class="err"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ secrets.FLY_API_TOKEN }}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Make sure you add a &lt;code&gt;FLY_API_TOKEN&lt;/code&gt; to your repos secrets. You can get it from &lt;a href="https://fly.io/user/personal_access_tokens"&gt;https://fly.io/user/personal_access_tokens&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  (Optional) Adding a custom domain
&lt;/h2&gt;

&lt;p&gt;If you want to add a custom domain to your blog, first you need a domain. My personal choice was &lt;a href="https://www.namecheap.com/"&gt;Namecheap&lt;/a&gt;, but there are many other options out there like &lt;a href="https://www.godaddy.com/"&gt;GoDaddy&lt;/a&gt;, &lt;a href="https://www.hostinger.com/"&gt;Hostinger&lt;/a&gt;, &lt;a href="https://aws.amazon.com/route53/"&gt;AWS Route 53&lt;/a&gt;, etc.&lt;/p&gt;

&lt;p&gt;Once you have your domain, we'll need to run the following command to add it to our fly.io app:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;fly certs create &amp;lt;your-domain&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You'll get prompted by fly needing to verify and configure your domain. Just follow the instructions and add an &lt;code&gt;A Record&lt;/code&gt; and &lt;code&gt;AAAA Record&lt;/code&gt; to your DNS provider as well as adding the &lt;code&gt;CNAME&lt;/code&gt; record for &lt;code&gt;www&lt;/code&gt; as well.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Type&lt;/th&gt;
&lt;th&gt;Name&lt;/th&gt;
&lt;th&gt;Value&lt;/th&gt;
&lt;th&gt;TTL&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;A Record&lt;/td&gt;
&lt;td&gt;@&lt;/td&gt;
&lt;td&gt;&amp;lt;value provided by fly&amp;gt;&lt;/td&gt;
&lt;td&gt;Automatic&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;AAAA Record&lt;/td&gt;
&lt;td&gt;@&lt;/td&gt;
&lt;td&gt;&amp;lt;value provided by fly&amp;gt;&lt;/td&gt;
&lt;td&gt;Automatic&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;CNAME Record&lt;/td&gt;
&lt;td&gt;www&lt;/td&gt;
&lt;td&gt;&amp;lt;your-app-name&amp;gt;.fly.dev.&lt;/td&gt;
&lt;td&gt;5 min&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Once it's ready, you can run &lt;code&gt;fly certs show &amp;lt;your-domain&amp;gt;&lt;/code&gt; to see if everything is working as expected and add any other configuration if needed.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Don't forget to re-configure your &lt;code&gt;baseURL&lt;/code&gt; in your &lt;code&gt;config/_default/config.toml&lt;/code&gt; file:&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight toml"&gt;&lt;code&gt;&lt;span class="c"&gt;# config/_default/config.toml&lt;/span&gt;
&lt;span class="py"&gt;baseURL&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"https://&amp;lt;your-domain&amp;gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;Now you have a blog of your own, just like this one. You can now start writing your own posts and deploy them to fly.io.&lt;/p&gt;

&lt;p&gt;If you have any questions, feel free to reach out to me on any social.&lt;/p&gt;




&lt;p&gt;Originally published at &lt;a href="https://itamadev.com/posts/20230603-bootstrap-your-blog/"&gt;https://itamadev.com&lt;/a&gt; on June 3, 2023.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>tutorial</category>
      <category>blog</category>
      <category>devops</category>
    </item>
    <item>
      <title>Pod &amp; Node Eviction</title>
      <dc:creator>Itamar Knafo</dc:creator>
      <pubDate>Wed, 12 Apr 2023 11:39:01 +0000</pubDate>
      <link>https://dev.to/itamadev/pod-node-eviction-5fjl</link>
      <guid>https://dev.to/itamadev/pod-node-eviction-5fjl</guid>
      <description>&lt;p&gt;In the world of container orchestration, Kubernetes is the de facto standard. It is an open-source platform for automating the deployment, scaling, and management of containerized applications. Kubernetes abstracts the underlying infrastructure and provides a unified API for managing containerized workloads. However, as with any complex system, Kubernetes is not immune to failures. In this article, we will discuss one such failure scenario - Pod and Node eviction in Kubernetes.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Pod and Node Eviction?
&lt;/h2&gt;

&lt;p&gt;Pod and Node eviction are two related concepts in Kubernetes. A Pod is the smallest deployable unit in Kubernetes. It consists of one or more containers that share the same network namespace and storage. A Node is a physical or virtual machine that runs the Kubernetes software and can host one or more Pods.&lt;/p&gt;

&lt;p&gt;Pod eviction happens when a Pod is terminated by the Kubernetes system due to some reason, such as a Node failure or resource constraints. Node eviction, on the other hand, happens when a Node is marked un-schedulable and the Pods running on it are evicted to other Nodes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why does Pod and Node Eviction happen?
&lt;/h2&gt;

&lt;p&gt;Pod and Node eviction can happen due to a variety of reasons, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Node failures - A Node can fail due to hardware or software issues, such as network failure, power outage, or kernel panic.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Resource constraints - A Node may run out of resources, such as CPU, memory, or disk space, which can cause Pods to be evicted.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Node maintenance - A Node may be taken down for maintenance, such as kernel upgrades, security patches, or hardware replacement.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Pod failures - A Pod may fail due to application errors or resource constraints, which can trigger Pod eviction and rescheduling on other Nodes.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Some Examples of Pod and Node Evictions
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Node failure - Suppose you have a Kubernetes cluster with three Nodes. One of the Nodes experiences a hardware failure, causing it to become un-schedulable. The Kubernetes scheduler identifies the Pods running on the failed Node and reschedules them on the remaining Nodes, marking the failed Node for eviction.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Resource constraints - If a Pod starts consuming too much CPU or memory, it can cause the Node to run out of resources. Kubernetes may then decide to evict the Pod to free up resources for other Pods running on the Node.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Node maintenance - When you need to perform maintenance on a Node, you can mark it as un-schedulable using the Kubernetes API. Kubernetes then identifies the Pods running on the Node and reschedules them on other Nodes, allowing you to take the Node offline for maintenance.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Pod failures - If a Pod fails due to a crash or error, Kubernetes may decide to evict it and reschedule it on another Node. This helps ensure that the Pod remains available and responsive even in the face of failures.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In all of these scenarios, Kubernetes controllers monitor the state of Nodes and Pods and take appropriate actions to ensure the availability and reliability of your applications&lt;/p&gt;

&lt;h2&gt;
  
  
  How do Pod and Node Eviction work?
&lt;/h2&gt;

&lt;p&gt;Pod and Node eviction are handled by Kubernetes controllers, which monitor the state of Nodes and Pods and take actions based on the configured policies. When a Node fails or becomes un-schedulable, the Kubernetes scheduler identifies the Pods running on the Node and selects new Nodes to run them. The Pods are then rescheduled on the new Nodes, and the old Nodes are marked for eviction.&lt;/p&gt;

&lt;p&gt;The eviction process involves sending a &lt;code&gt;SIGTERM&lt;/code&gt; signal to the containers running in the Pod, giving them a grace period to shut down gracefully. If the containers do not stop within the grace period, they are forcibly terminated with a &lt;code&gt;SIGKILL&lt;/code&gt; signal. Once all the containers are terminated, the Pod is deleted from the Node.&lt;/p&gt;

&lt;p&gt;In the case of Node eviction, the Kubernetes system follows a similar process. It first identifies the Pods running on the Node and selects new Nodes to run them. The Pods are then rescheduled on the new Nodes, and the old Node is marked un-schedulable. The Pods running on the old Node are then evicted using the same process as Pod eviction.&lt;/p&gt;

&lt;h2&gt;
  
  
  How can we handle Pod and Node Eviction?
&lt;/h2&gt;

&lt;p&gt;Pod and Node eviction is inevitable in a Kubernetes cluster, and it is essential to have a strategy in place to handle them. Here are some best practices to handle Pod and Node eviction:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Use resource limits - Set resource limits on Pods to prevent them from consuming all the resources on a Node, which can cause other Pods to be evicted.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use &lt;code&gt;PodDisruptionBudgets&lt;/code&gt; - Use &lt;code&gt;PodDisruptionBudgets&lt;/code&gt; to ensure that a minimum number of Pods are available during Pod eviction, which can prevent service disruption.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use &lt;code&gt;NodeAffinity&lt;/code&gt; and anti-affinity - Use &lt;code&gt;NodeAffinity&lt;/code&gt; and anti-affinity rules to ensure that Pods are scheduled on Nodes that meet certain criteria, such as having enough resources or being in a specific zone.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use node maintenance modes - Use node maintenance modes to gracefully drain a Node before evicting the Pods, which can prevent service disruption.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;Pod and Node eviction is an integral part of Kubernetes, and it is essential to understand how they work and how to handle them. By following the best practices mentioned above, you can ensure that your applications remain available and responsive even in the face of Pod and Node eviction.&lt;/p&gt;

&lt;p&gt;In conclusion, Pod and Node eviction is a necessary "evil" in a Kubernetes cluster. While they may seem daunting, understanding how they work and taking the necessary precautions can help minimize their impact on your applications. As Kubernetes continues to evolve, we can expect more tools and techniques to emerge to help us manage Pod and Node eviction more effectively.&lt;/p&gt;




&lt;p&gt;Originally published at &lt;a href="https://itamadev.com/posts/20230412-pod-node-eviction/"&gt;https://itamadev.com&lt;/a&gt; on April 12, 2023.&lt;/p&gt;

</description>
      <category>kubernetes</category>
      <category>cloud</category>
      <category>devops</category>
    </item>
    <item>
      <title>Adopting Technologies</title>
      <dc:creator>Itamar Knafo</dc:creator>
      <pubDate>Sat, 17 Dec 2022 15:36:30 +0000</pubDate>
      <link>https://dev.to/itamadev/adopting-technologies-4ebn</link>
      <guid>https://dev.to/itamadev/adopting-technologies-4ebn</guid>
      <description>&lt;p&gt;When thinking about and testing new and exciting technologies, teams can often get overwhelmed with the thoughts of what to test. or what should be important to us even before testing or considering a tool, framework, or platform we might want to add to our tech stack.&lt;/p&gt;

&lt;p&gt;Here is a curated list of some of the key features I look into when learning and considering using tech in my personal projects or at work with the teams I work with.&lt;/p&gt;

&lt;h2&gt;
  
  
  Activity &amp;amp; Community
&lt;/h2&gt;

&lt;p&gt;One of the first and more noticeable things to look for when checking out new tech is the community and activity of the project, an active community can serve you well at the start and further down the road.&lt;/p&gt;

&lt;p&gt;It could be helpful even when reading into the tool you’re using with more articles or documentation being written or when getting stuck and in need of help, someone might just be stuck with you, and even better - someone might have already got a solution to your problem!&lt;/p&gt;

&lt;p&gt;Some things to look for are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Stars on GitHub ⭐&lt;/li&gt;
&lt;li&gt;Is the project “mature”? (how long has it been in use/development)&lt;/li&gt;
&lt;li&gt;Active Users&lt;/li&gt;
&lt;li&gt;Issues &amp;amp; PRs&lt;/li&gt;
&lt;li&gt;A slack/discord/platform of the community&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Project Size
&lt;/h2&gt;

&lt;p&gt;When looking to get a job done you might want some ready-made software to already do your job for you, and that’s great! so you can start and get your hands dirty with the real challenge.&lt;/p&gt;

&lt;p&gt;That is indeed a very good way to not repeat others’ work, but when doing so it’s important to remember you’re also introducing yourself to someone else’s code, someone you might not be familiar with and someone you might not be able to rely on for long.&lt;/p&gt;

&lt;p&gt;That puts us in a position where the size of the project really matters.&lt;/p&gt;

&lt;p&gt;If we’re looking at a complex project fixing a slight problem, we might be better off just implementing it ourselves, but if we are looking at a more challenging chore, considering using a project even if it’s a bit large, it can prove to be very practical and save us a lot of time in the end.&lt;/p&gt;

&lt;h2&gt;
  
  
  Maintenance
&lt;/h2&gt;

&lt;p&gt;As we just mentioned while talking about the project size and activity, maintenance is very important, we want to be sure we can rely on the projects we use.&lt;/p&gt;

&lt;p&gt;OpenSource projects don’t have a strict responsibility when it comes to maintenance, and when we don’t have active maintenance this metric becomes far more concerning, someday we might hear that our favorite CI/CD platform isn’t going to be maintained anymore, or even our central go framework which we based our whole application on will stop being maintained.&lt;/p&gt;

&lt;p&gt;Some tools have active support, and they might even have the founder/owner of the project actively responding to PRs, and Issues.&lt;/p&gt;

&lt;p&gt;While a strong community can really boost your whole workflow and process, support from the maker of the tool might be needed in some obscure use cases, it’s essential to rely on software that is actively being maintained, and so even without intimate support from the owner, the maintenance might be just enough, and we need to keep in mind that in the future the project might have a different owner and even from the active community.&lt;/p&gt;

&lt;p&gt;Something important to keep in mind is that after we choose our technology we still need to actively watch out for updates and maintenance changes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Programming Language
&lt;/h2&gt;

&lt;p&gt;The last but certainly not least bullet point is the programming language being used and supported by the project.&lt;/p&gt;

&lt;p&gt;Sometimes we might just be using a project as an outside service and sometimes as a fully integrated library or SDK.&lt;/p&gt;

&lt;p&gt;We need to check that the main languages that we use are being supported and it’s even better if the project itself is written in one of them, then when experiencing problems or looking at Issues some of our team might be able to help fix them and submit a PR.&lt;/p&gt;

&lt;p&gt;This metric isn’t as groundbreaking but can definitely serve you well, as I can say from my experience it has.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;We want to be aware when using someone else’s code and looking at new tech, we want to know we aren’t just inviting problems into our workflow and tech stack and we want to follow some rules in doing so. I hope now you can be a little bit more sure about when integrating new technologies into your tech stack.&lt;/p&gt;




&lt;p&gt;Originally published at &lt;a href="https://itamadev.com/posts/20221126-adopting-tech/" rel="noopener noreferrer"&gt;https://itamadev.com&lt;/a&gt; on November 26, 2022.&lt;/p&gt;

</description>
      <category>career</category>
      <category>productivity</category>
      <category>community</category>
    </item>
  </channel>
</rss>
