<?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: Dilanka Rathnasiri</title>
    <description>The latest articles on DEV Community by Dilanka Rathnasiri (@dilanka-rathnasiri).</description>
    <link>https://dev.to/dilanka-rathnasiri</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%2F1352604%2F681e510d-5b75-4824-bd67-a4f5ee5bca63.jpeg</url>
      <title>DEV Community: Dilanka Rathnasiri</title>
      <link>https://dev.to/dilanka-rathnasiri</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dilanka-rathnasiri"/>
    <language>en</language>
    <item>
      <title>🔐 OTP CLI Utils — A Simple and Powerful CLI tool for TOTP Codes</title>
      <dc:creator>Dilanka Rathnasiri</dc:creator>
      <pubDate>Sat, 25 Oct 2025 12:29:50 +0000</pubDate>
      <link>https://dev.to/dilanka-rathnasiri/otp-cli-utils-a-simple-and-powerful-cli-tool-for-totp-codes-197p</link>
      <guid>https://dev.to/dilanka-rathnasiri/otp-cli-utils-a-simple-and-powerful-cli-tool-for-totp-codes-197p</guid>
      <description>&lt;p&gt;Hello everyone 👋&lt;/p&gt;

&lt;p&gt;I recently built a new Python CLI tool called &lt;strong&gt;OTP CLI Utils&lt;/strong&gt; — a lightweight command-line utility to &lt;strong&gt;generate, validate, and manage Time-based One-Time Password (TOTP)&lt;/strong&gt; codes. If you use &lt;a href="https://play.google.com/store/apps/details?id=com.google.android.apps.authenticator2&amp;amp;hl=en" rel="noopener noreferrer"&gt;Google Authenticator&lt;/a&gt; or work with 2FA systems, this tool can make your developer workflow a lot smoother.&lt;/p&gt;

&lt;p&gt;🔗 GitHub: &lt;a href="https://github.com/dilanka-rathnasiri/otp-cli-utils" rel="noopener noreferrer"&gt;https://github.com/dilanka-rathnasiri/otp-cli-utils&lt;/a&gt;&lt;br&gt;
🔗 PyPI: &lt;a href="https://pypi.org/project/otp-cli-utils" rel="noopener noreferrer"&gt;https://pypi.org/project/otp-cli-utils&lt;/a&gt;&lt;/p&gt;


&lt;h2&gt;
  
  
  🚀 What It Does
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;OTP CLI Utils&lt;/strong&gt; provides a simple interface to handle everything related to TOTP (used in 2FA systems). You can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🔑 &lt;strong&gt;Generate&lt;/strong&gt; current OTP codes from a secret&lt;/li&gt;
&lt;li&gt;✅ &lt;strong&gt;Validate&lt;/strong&gt; OTP codes against a secret&lt;/li&gt;
&lt;li&gt;🔄 &lt;strong&gt;Generate&lt;/strong&gt; secure random OTP secrets&lt;/li&gt;
&lt;li&gt;📱 &lt;strong&gt;Create&lt;/strong&gt; Google Authenticator compatible QR codes&lt;/li&gt;
&lt;li&gt;🧰 All from your &lt;strong&gt;command line&lt;/strong&gt;, no web tools or GUIs needed&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  ⚙️ Installation
&lt;/h2&gt;

&lt;p&gt;You can install it easily from PyPI:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip &lt;span class="nb"&gt;install &lt;/span&gt;otp-cli-utils
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  💡 Usage Examples
&lt;/h2&gt;

&lt;h3&gt;
  
  
  🔹 Generate the Current OTP Code
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;otp-cli-utils get-otp &amp;lt;secret&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;otp-cli-utils get-otp ABCDEF1234567890
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  🔹 Validate an OTP
&lt;/h3&gt;

&lt;p&gt;Check if an OTP code is valid for a given secret.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;otp-cli-utils validate &amp;lt;secret&amp;gt; &amp;lt;otp&amp;gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;--window-count&lt;/span&gt; &amp;lt;count&amp;gt; | &lt;span class="nt"&gt;--time-period&lt;/span&gt; &amp;lt;seconds&amp;gt;]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;otp-cli-utils validate ABCDEF1234567890 123456
otp-cli-utils validate ABCDEF1234567890 123456 &lt;span class="nt"&gt;--window-count&lt;/span&gt; 2
otp-cli-utils validate ABCDEF1234567890 123456 &lt;span class="nt"&gt;--time-period&lt;/span&gt; 120
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  🔹 Generate a New OTP Secret
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;otp-cli-utils generate-secret
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  🔹 Create a QR Code for Google Authenticator
&lt;/h3&gt;

&lt;p&gt;Easily generate a QR code image to scan directly with authenticator apps.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;otp-cli-utils generate-secret-qr-code &lt;span class="s2"&gt;"user@example.com"&lt;/span&gt; &lt;span class="s2"&gt;"GitHub"&lt;/span&gt; github_2fa
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🤝 Contribute
&lt;/h2&gt;

&lt;p&gt;Contributions, ideas, and feedback are welcome!&lt;br&gt;
Check out the project on GitHub and feel free to open an issue or PR.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧾 License
&lt;/h2&gt;

&lt;p&gt;Released under the &lt;strong&gt;MIT License&lt;/strong&gt; — completely open source.&lt;/p&gt;

</description>
      <category>python</category>
      <category>cli</category>
    </item>
    <item>
      <title>🏗️ Simple K8s — A Minimal Kubernetes Stack for Learning</title>
      <dc:creator>Dilanka Rathnasiri</dc:creator>
      <pubDate>Fri, 08 Aug 2025 11:52:51 +0000</pubDate>
      <link>https://dev.to/dilanka-rathnasiri/simple-k8s-a-minimal-kubernetes-stack-for-learning-249d</link>
      <guid>https://dev.to/dilanka-rathnasiri/simple-k8s-a-minimal-kubernetes-stack-for-learning-249d</guid>
      <description>&lt;p&gt;I wanted a &lt;strong&gt;lightweight, reproducible way&lt;/strong&gt; to explore how modern cloud-native tools work together — without a full complex setup. So, I built &lt;strong&gt;&lt;a href="https://github.com/dilanka-rathnasiri/simple-k8s" rel="noopener noreferrer"&gt;Simple K8s&lt;/a&gt;&lt;/strong&gt; — a &lt;strong&gt;local minimal Kubernetes stack&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;🔗 &lt;strong&gt;GitHub Repo:&lt;/strong&gt; &lt;a href="https://github.com/dilanka-rathnasiri/simple-k8s" rel="noopener noreferrer"&gt;github.com/dilanka-rathnasiri/simple-k8s&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  🛠️ Stack Overview
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Tool&lt;/th&gt;
&lt;th&gt;Purpose&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href="https://minikube.sigs.k8s.io/docs/" rel="noopener noreferrer"&gt;Minikube&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;Local Kubernetes cluster&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href="https://helm.sh/" rel="noopener noreferrer"&gt;Helm&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;Kubernetes package manager&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href="https://gateway.envoyproxy.io/" rel="noopener noreferrer"&gt;Envoy Gateway&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;Kubernetes native API Gateway&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href="https://knative.dev/docs/" rel="noopener noreferrer"&gt;Knative Serving&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;Serverless platform with scale-to-zero support&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href="https://headlamp.dev/" rel="noopener noreferrer"&gt;Headlamp&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;User-friendly Kubernetes dashboard&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  💡 Why I Built This
&lt;/h2&gt;

&lt;p&gt;I wanted a setup that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Runs &lt;strong&gt;locally&lt;/strong&gt; on my machine
&lt;/li&gt;
&lt;li&gt;Quickly set up and clean up
&lt;/li&gt;
&lt;li&gt;Uses &lt;strong&gt;real-world tools&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Let me &lt;strong&gt;experiment freely&lt;/strong&gt; without worrying about costs&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  🎯 What It is For
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Learning &lt;strong&gt;Kubernetes Gateway API&lt;/strong&gt; with Envoy Gateway
&lt;/li&gt;
&lt;li&gt;Understanding &lt;strong&gt;Kubernetes native serverless deployments&lt;/strong&gt; via Knative
&lt;/li&gt;
&lt;li&gt;Playing with a &lt;strong&gt;modern Kubernetes dashboard&lt;/strong&gt; (Headlamp)
&lt;/li&gt;
&lt;li&gt;Experimenting with &lt;strong&gt;HTTP routing&lt;/strong&gt; between multiple services
&lt;/li&gt;
&lt;li&gt;Running &lt;strong&gt;sample apps&lt;/strong&gt; in a safe, local environment
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  🚀 How to Use It
&lt;/h2&gt;

&lt;h4&gt;
  
  
  🏁 Quick Start
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/dilanka-rathnasiri/simple-k8s.git
&lt;span class="nb"&gt;cd &lt;/span&gt;simple-k8s
sh setup.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  🧹 Clean Up
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sh clean-up.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>kubernetes</category>
      <category>cloudnative</category>
    </item>
    <item>
      <title>I Built My Personal Portfolio with Angular and Hosted It on GitHub Pages</title>
      <dc:creator>Dilanka Rathnasiri</dc:creator>
      <pubDate>Sat, 28 Jun 2025 14:26:19 +0000</pubDate>
      <link>https://dev.to/dilanka-rathnasiri/i-built-my-personal-portfolio-with-angular-and-hosted-it-on-github-pages-2c7b</link>
      <guid>https://dev.to/dilanka-rathnasiri/i-built-my-personal-portfolio-with-angular-and-hosted-it-on-github-pages-2c7b</guid>
      <description>&lt;p&gt;Hello devs! 👋&lt;/p&gt;

&lt;p&gt;I'm excited to share that I've built and launched my personal portfolio — a simple, modern web app to showcase my projects, skills, and background as a backend engineer.&lt;/p&gt;

&lt;p&gt;🔗 &lt;strong&gt;Web url&lt;/strong&gt;: &lt;a href="https://dilanka-rathnasiri.github.io/portfolio/" rel="noopener noreferrer"&gt;https://dilanka-rathnasiri.github.io/portfolio/&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Why I Built It
&lt;/h2&gt;

&lt;p&gt;I wanted a clean and professional place to highlight my experience, work, and technical skills. Angular felt like the right choice due to its:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Modular architecture&lt;/li&gt;
&lt;li&gt;Strong tooling ecosystem&lt;/li&gt;
&lt;li&gt;Great documentation and community&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  🛠️ Tech Stack
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Framework&lt;/strong&gt;: &lt;a href="https://angular.dev/" rel="noopener noreferrer"&gt;Angular&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Styling&lt;/strong&gt;: &lt;a href="https://sass-lang.com/" rel="noopener noreferrer"&gt;SCSS&lt;/a&gt; + &lt;a href="https://getbootstrap.com/" rel="noopener noreferrer"&gt;Bootstrap&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hosting&lt;/strong&gt;: &lt;a href="https://pages.github.com/" rel="noopener noreferrer"&gt;GitHub Pages&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The project is fully open-source and available on GitHub:&lt;/p&gt;

&lt;p&gt;💻 &lt;a href="https://github.com/dilanka-rathnasiri/portfolio" rel="noopener noreferrer"&gt;https://github.com/dilanka-rathnasiri/portfolio&lt;/a&gt;&lt;/p&gt;

</description>
      <category>portfolio</category>
      <category>angular</category>
    </item>
    <item>
      <title>🚀 Just published my first Python package on PyPI: py-sse-client</title>
      <dc:creator>Dilanka Rathnasiri</dc:creator>
      <pubDate>Sat, 12 Apr 2025 14:16:30 +0000</pubDate>
      <link>https://dev.to/dilanka-rathnasiri/just-published-my-first-python-package-on-pypi-py-sse-client-3enp</link>
      <guid>https://dev.to/dilanka-rathnasiri/just-published-my-first-python-package-on-pypi-py-sse-client-3enp</guid>
      <description>&lt;p&gt;Hey devs! 👋&lt;/p&gt;

&lt;p&gt;I'm thrilled to announce the release of my first PyPI package: &lt;a href="https://pypi.org/project/py-sse-client" rel="noopener noreferrer"&gt;py-sse-client&lt;/a&gt;!&lt;/p&gt;

&lt;p&gt;🔗 Links&lt;br&gt;
→ GitHub: &lt;a href="https://github.com/dilanka-rathnasiri/py-sse-client" rel="noopener noreferrer"&gt;https://github.com/dilanka-rathnasiri/py-sse-client&lt;/a&gt;&lt;br&gt;
→ PyPI: &lt;a href="https://pypi.org/project/py-sse-client" rel="noopener noreferrer"&gt;https://pypi.org/project/py-sse-client&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;📦 What is py-sse-client?&lt;br&gt;
It's a lightweight asynchronous Server-Sent Events (SSE) client for Python that helps you connect to real-time SSE streams in a clean and Pythonic way.&lt;/p&gt;

&lt;p&gt;🚀 Why I built it&lt;br&gt;
I've worked with SSE in some of my backend projects and always wanted a minimalist and reliable client that just works. So I decided to build one, and finally took the step to publish it on PyPI. Also, I believe this will be a good starting point for my open source development.&lt;/p&gt;

&lt;p&gt;🛤️ "This is one small step — but it’s a significant milestone in my software development journey."&lt;/p&gt;

&lt;p&gt;It feels great to give back to the community, and I plan to keep improving this package and work on more open-source tools.&lt;/p&gt;

&lt;p&gt;Check it out and feel free to contribute or drop feedback!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Kubernetes ReplicaSet</title>
      <dc:creator>Dilanka Rathnasiri</dc:creator>
      <pubDate>Sun, 17 Nov 2024 15:32:01 +0000</pubDate>
      <link>https://dev.to/dilanka-rathnasiri/kubernetes-replicaset-42ck</link>
      <guid>https://dev.to/dilanka-rathnasiri/kubernetes-replicaset-42ck</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;cover image: Photo by &lt;a href="https://unsplash.com/@frankiefoto?utm_content=creditCopyText&amp;amp;utm_medium=referral&amp;amp;utm_source=unsplash" rel="noopener noreferrer"&gt;frank mckenna&lt;/a&gt; on &lt;a href="https://unsplash.com/photos/assorted-color-filed-intermodal-containers-tjX_sniNzgQ?utm_content=creditCopyText&amp;amp;utm_medium=referral&amp;amp;utm_source=unsplash" rel="noopener noreferrer"&gt;Unsplash&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In this article, we'll talk about Kubernetes ReplicaSet. Being familiar with the earlier articles in this series is helpful for a better understanding.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Is a ReplicaSet?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;A ReplicaSet is a Kubernetes object that ensures a specified number of pods of a given template are running at any
given time&lt;/li&gt;
&lt;li&gt;It guarantees the availability of a specified number of identical pods&lt;/li&gt;
&lt;li&gt;Most of the time, we don't directly manage ReplicaSets&lt;/li&gt;
&lt;li&gt;Instead, we use &lt;a href="https://kubernetes.io/docs/concepts/workloads/controllers/deployment/" rel="noopener noreferrer"&gt;Deployments&lt;/a&gt; for managing ReplicaSet&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Creating a ReplicaSet With a Manifest File
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;To understand how ReplicaSets work, let’s start with the manifest file&lt;/li&gt;
&lt;li&gt;Here’s an example of a ReplicaSet manifest file:
&lt;/li&gt;
&lt;/ul&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;apps/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;ReplicaSet&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;my-replicaset&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;replicas&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;
  &lt;span class="na"&gt;selector&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;matchLabels&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;app&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;my-app&lt;/span&gt;
  &lt;span class="na"&gt;template&lt;/span&gt;&lt;span class="pi"&gt;:&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;labels&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;app&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;my-app&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;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;my-container&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;ports&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
            &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;containerPort&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;80&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then we can create this ReplicaSet using &lt;a href="https://kubernetes.io/docs/reference/kubectl" rel="noopener noreferrer"&gt;kubectl&lt;/a&gt; with one of the following commands&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl create &lt;span class="nt"&gt;-f&lt;/span&gt; my-replicaset.yaml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl apply &lt;span class="nt"&gt;-f&lt;/span&gt; my-replicaset.yaml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above manifest file creates ReplicaSet &lt;code&gt;my-replicaset&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Key Fields in the ReplicaSet Manifest File
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;.spec.replicas&lt;/code&gt;:

&lt;ul&gt;
&lt;li&gt;Number of pods managed by the ReplicaSet&lt;/li&gt;
&lt;li&gt;In the above ReplicaSet, we have 3 pods&lt;/li&gt;
&lt;li&gt;If we don't specify a value, then the default value is 1&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;
&lt;code&gt;.spec.template&lt;/code&gt;:

&lt;ul&gt;
&lt;li&gt;The pod template used to create the ReplicaSet’s pods&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;
&lt;code&gt;.spec.template.metadata.labels&lt;/code&gt;:

&lt;ul&gt;
&lt;li&gt;labels of the pods created from the pod template&lt;/li&gt;
&lt;li&gt;These labels must match &lt;code&gt;.spec.selector.matchLabels&lt;/code&gt; labels&lt;/li&gt;
&lt;li&gt;In the above ReplicaSet, the labels of the pods are &lt;code&gt;app: my-app&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;
&lt;code&gt;.spec.selector.matchLabels&lt;/code&gt;:

&lt;ul&gt;
&lt;li&gt;Replicaset identifies the pods required to be managed by the ReplicaSet from these labels&lt;/li&gt;
&lt;li&gt;ReplicaSet will manage pods with matching labels (even if not created by the ReplicaSet)&lt;/li&gt;
&lt;li&gt;e.g., if 2 pods with the label &lt;code&gt;app: my-app&lt;/code&gt; already exist, the ReplicaSet will create only 1 more pod but manage all 3 pods&lt;/li&gt;
&lt;li&gt;ReplicaSets can also use advanced &lt;a href="https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/" rel="noopener noreferrer"&gt;label selectors&lt;/a&gt; like &lt;code&gt;matchExpressions&lt;/code&gt; instead of &lt;code&gt;matchLabels&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h2&gt;
  
  
  How a ReplicaSet Links to Its Pods
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;A ReplicaSet links to its pods via the &lt;code&gt;metadata.ownerReferences&lt;/code&gt; field in the pod's metadata.&lt;/li&gt;
&lt;li&gt;Field &lt;code&gt;metadata.ownerReferences&lt;/code&gt; specifies the owner of the object&lt;/li&gt;
&lt;li&gt;This field specifies the ReplicaSet &lt;code&gt;my-replicaset&lt;/code&gt; as the owner&lt;/li&gt;
&lt;li&gt;Here's an example output YAML of a pod managed by &lt;code&gt;my-replicaset&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&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;generateName&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;my-replicaset-&lt;/span&gt;
  &lt;span class="na"&gt;labels&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;app&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;my-app&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;my-replicaset-dxzzg&lt;/span&gt;
  &lt;span class="na"&gt;namespace&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;default&lt;/span&gt;
  &lt;span class="na"&gt;ownerReferences&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;apiVersion&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;apps/v1&lt;/span&gt;
      &lt;span class="na"&gt;blockOwnerDeletion&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
      &lt;span class="na"&gt;controller&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&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;ReplicaSet&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;my-replicaset&lt;/span&gt;
      &lt;span class="na"&gt;uid&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;a93e48a6-9ec6-46e6-b92f-c61ccd9a2d40&lt;/span&gt;
  &lt;span class="na"&gt;resourceVersion&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;472"&lt;/span&gt;
  &lt;span class="na"&gt;uid&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;6cf20e31-a73a-4846-ad8d-a4b41e7711ac&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;imagePullPolicy&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Always&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;my-container&lt;/span&gt;
      &lt;span class="na"&gt;ports&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;containerPort&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;80&lt;/span&gt;
          &lt;span class="na"&gt;protocol&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;TCP&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Deleting a ReplicaSet
&lt;/h2&gt;

&lt;p&gt;We can delete the above ReplicaSet using kubectl with one of the following commands&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl delete &lt;span class="nt"&gt;-f&lt;/span&gt; my-replicaset.yaml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl delete rs my-replicaset
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Replicaset vs. Replication Controller
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;ReplicaSet is the next generation of Replication Controller&lt;/li&gt;
&lt;li&gt;Kubernetes documentation recommends using ReplicaSets instead of Replications Controllers&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;In this article, we discussed the Kubernetes ReplicaSet. We looked at what ReplicaSet is, how it works, and how to create and delete a ReplicaSet.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://kubernetes.io/docs/concepts/workloads/controllers/replicaset" rel="noopener noreferrer"&gt;https://kubernetes.io/docs/concepts/workloads/controllers/replicaset&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://kubernetes.io/docs/concepts/workloads/controllers/replicationcontroller" rel="noopener noreferrer"&gt;https://kubernetes.io/docs/concepts/workloads/controllers/replicationcontroller&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>kubernetes</category>
      <category>containers</category>
      <category>devops</category>
    </item>
    <item>
      <title>Kubernetes Pods</title>
      <dc:creator>Dilanka Rathnasiri</dc:creator>
      <pubDate>Sun, 03 Nov 2024 14:15:02 +0000</pubDate>
      <link>https://dev.to/dilanka-rathnasiri/kubernetes-pods-4a5n</link>
      <guid>https://dev.to/dilanka-rathnasiri/kubernetes-pods-4a5n</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;cover image: Photo by &lt;a href="https://unsplash.com/@ilangamuwa?utm_content=creditCopyText&amp;amp;utm_medium=referral&amp;amp;utm_source=unsplash" rel="noopener noreferrer"&gt;Nilantha Ilangamuwa&lt;/a&gt; on &lt;a href="https://unsplash.com/photos/ship-on-dock-near-shipping-containers-d3766qQNQIY?utm_content=creditCopyText&amp;amp;utm_medium=referral&amp;amp;utm_source=unsplash" rel="noopener noreferrer"&gt;Unsplash&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In this article, we’ll talk about Kubernetes pods. We'll discuss what they are, how they work, and why they’re essential in the Kubernetes ecosystem.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are Kubernetes Objects?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Kubernetes Objects are the foundational entities of Kubernetes&lt;/li&gt;
&lt;li&gt;We can consider Kubernetes objects as the building blocks of the Kubernetes&lt;/li&gt;
&lt;li&gt;Each Kubernetes object has its own specific attributes and responsibilities&lt;/li&gt;
&lt;li&gt;There are many types of Kubernetes objects&lt;/li&gt;
&lt;li&gt;The following are some of them

&lt;ul&gt;
&lt;li&gt;Pods&lt;/li&gt;
&lt;li&gt;Deployments&lt;/li&gt;
&lt;li&gt;Services&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h2&gt;
  
  
  What is a Pod?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;In Kubernetes, pods are the smallest deployable units of computing&lt;/li&gt;
&lt;li&gt;Kubernetes pod is one type of the Kubernetes objects&lt;/li&gt;
&lt;li&gt;A pod can contain one container or a group of tightly coupled containers&lt;/li&gt;
&lt;li&gt;So, Pods can be considered as abstractions that encapsulate one or more containers&lt;/li&gt;
&lt;li&gt;In most use cases, we use pods that contain a single container&lt;/li&gt;
&lt;li&gt;Pods are ephemeral and disposable&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Creating a Pod with a Manifest File
&lt;/h2&gt;

&lt;p&gt;Here’s an example of a basic pod manifest file:&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&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;name&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;image&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;nginx:latest&lt;/span&gt;
    &lt;span class="na"&gt;ports&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;containerPort&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;80&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then we can create this pod using &lt;a href="https://kubernetes.io/docs/reference/kubectl" rel="noopener noreferrer"&gt;kubectl&lt;/a&gt; with one of the following commands&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl create &lt;span class="nt"&gt;-f&lt;/span&gt; nginx.yaml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl apply &lt;span class="nt"&gt;-f&lt;/span&gt; nginx.yaml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;The above manifest file creates a pod with a single nginx container&lt;/li&gt;
&lt;li&gt;In many use cases, we don't directly create and manipulate pods&lt;/li&gt;
&lt;li&gt;Instead, we’ll use &lt;a href="https://kubernetes.io/docs/concepts/workloads" rel="noopener noreferrer"&gt;workload resources&lt;/a&gt; like Deployments or ReplicaSets to manage pods at scale&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We can delete above pod using kubectl with one of the following commands&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl delete &lt;span class="nt"&gt;-f&lt;/span&gt; nginx.yaml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl delete pod nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Multi-container pods
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Containers that are tightly coupled and required to work together can be encapsulated into a single pod&lt;/li&gt;
&lt;li&gt;These containers are automatically &lt;strong&gt;co-located&lt;/strong&gt; and &lt;strong&gt;co-scheduled&lt;/strong&gt; in the same physical or virtual machine&lt;/li&gt;
&lt;li&gt;So, this allows them to

&lt;ul&gt;
&lt;li&gt;communicate and coordinate with each other&lt;/li&gt;
&lt;li&gt;share resources and dependencies&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;Example Multi-Container Pod Manifest:&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&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;name&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;image&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;nginx:latest&lt;/span&gt;
    &lt;span class="na"&gt;ports&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;containerPort&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;80&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;redis&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;redis:latest&lt;/span&gt;
    &lt;span class="na"&gt;ports&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;containerPort&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;6379&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The above pod has two containers; &lt;code&gt;nginx&lt;/code&gt; container and &lt;code&gt;redis&lt;/code&gt; container&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;There are several types of multi-container pods&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The following are 3 types used commonly&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Sidecar Containers&lt;/li&gt;
&lt;li&gt;Ambassador Containers&lt;/li&gt;
&lt;li&gt;Adapter Containers&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h2&gt;
  
  
  Sidecar Containers
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Sidecar containers are the secondary containers that run along with the main application container within the same Pod&lt;/li&gt;
&lt;li&gt;They provide additional services or functionalities such as logging, monitoring, etc.&lt;/li&gt;
&lt;li&gt;In most cases, we don't directly manage sidecar containers&lt;/li&gt;
&lt;li&gt;Instead, Helm charts manage sidecar containers&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Init Container
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Init container is a container that runs before the main application containers of the pod&lt;/li&gt;
&lt;li&gt;They’re used for tasks required to be completed once before the application container startup&lt;/li&gt;
&lt;li&gt;Init containers are also regular containers&lt;/li&gt;
&lt;li&gt;But unlike regular containers,

&lt;ul&gt;
&lt;li&gt;Init containers always run to completion&lt;/li&gt;
&lt;li&gt;Init containers run only at the pod startup&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;A pod can have multiple init containers and they execute sequentially&lt;/li&gt;

&lt;li&gt;Init containers are specified within the &lt;code&gt;initContainers&lt;/code&gt; section of the manifest file&lt;/li&gt;

&lt;li&gt;Init containers run sequentially in the order of &lt;code&gt;initContainers&lt;/code&gt; section of the manifest file&lt;/li&gt;

&lt;li&gt;Only one init container runs at a time&lt;/li&gt;

&lt;li&gt;If an init container fails, it'll be restarted until it succeeds&lt;/li&gt;

&lt;li&gt;However, we can control the restart behavior by using &lt;code&gt;restartPolicy&lt;/code&gt; of the pod&lt;/li&gt;

&lt;li&gt;&lt;p&gt;If an init container fails, the whole pod will fail&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Example Kubernetes Manifest with Init Containers:&lt;br&gt;&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;

&lt;/ul&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;myapp-pod&lt;/span&gt;
  &lt;span class="na"&gt;labels&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;app.kubernetes.io/name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;MyApp&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;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;myapp-container&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;busybox:1.28&lt;/span&gt;
      &lt;span class="na"&gt;command&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;sh'&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;-c'&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;echo&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;The&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;app&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;is&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;running!&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;&amp;amp;&amp;amp;&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;sleep&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;3600'&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;
  &lt;span class="na"&gt;initContainers&lt;/span&gt;&lt;span class="pi"&gt;:&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;init-myservice&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;busybox:1.28&lt;/span&gt;
      &lt;span class="na"&gt;command&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;sh'&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;-c'&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;until&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;nslookup&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;myservice.$(cat&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;/var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local;&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;do&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;echo&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;waiting&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;for&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;myservice;&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;sleep&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;2;&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;done"&lt;/span&gt;&lt;span class="pi"&gt;]&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;init-mydb&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;busybox:1.28&lt;/span&gt;
      &lt;span class="na"&gt;command&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;sh'&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;-c'&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;until&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;nslookup&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;mydb.$(cat&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;/var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local;&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;do&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;echo&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;waiting&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;for&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;mydb;&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;sleep&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;2;&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;done"&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;In the above example &lt;code&gt;init-myservice&lt;/code&gt; and &lt;code&gt;init-mydb&lt;/code&gt; are init containers&lt;/li&gt;
&lt;li&gt;Containers of the above manifest run in the following order,

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;init-myservice&lt;/code&gt; init container starts first and runs to completion&lt;/li&gt;
&lt;li&gt;After successfully completing &lt;code&gt;init-myservice&lt;/code&gt; init container, &lt;code&gt;init-mydb&lt;/code&gt; init container starts and runs to the completion&lt;/li&gt;
&lt;li&gt;After successfully completing &lt;code&gt;init-mydb&lt;/code&gt; init container, &lt;code&gt;myapp-container&lt;/code&gt; container starts&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;In this article, we covered the basics of Kubernetes pods. We looked at what pods are, how they can encapsulate one or more containers, and the different types of containers that can run within a pod, including sidecar and init containers.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://kubernetes.io/docs/concepts/workloads/pods" rel="noopener noreferrer"&gt;https://kubernetes.io/docs/concepts/workloads/pods&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://kubernetes.io/docs/concepts/overview/working-with-objects" rel="noopener noreferrer"&gt;https://kubernetes.io/docs/concepts/overview/working-with-objects&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://kubernetes.io/docs/concepts/workloads/pods/sidecar-containers" rel="noopener noreferrer"&gt;https://kubernetes.io/docs/concepts/workloads/pods/sidecar-containers&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://kubernetes.io/docs/concepts/workloads/pods/init-containers" rel="noopener noreferrer"&gt;https://kubernetes.io/docs/concepts/workloads/pods/init-containers&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>kubernetes</category>
      <category>containers</category>
      <category>devops</category>
    </item>
    <item>
      <title>Kubernetes Cluster Architecture</title>
      <dc:creator>Dilanka Rathnasiri</dc:creator>
      <pubDate>Sun, 06 Oct 2024 15:00:54 +0000</pubDate>
      <link>https://dev.to/dilanka-rathnasiri/kubernetes-cluster-architecture-3f87</link>
      <guid>https://dev.to/dilanka-rathnasiri/kubernetes-cluster-architecture-3f87</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;cover image: Photo by &lt;a href="https://unsplash.com/@gwundrig?utm_content=creditCopyText&amp;amp;utm_medium=referral&amp;amp;utm_source=unsplash" rel="noopener noreferrer"&gt;Manuel Nägeli&lt;/a&gt; on &lt;a href="https://unsplash.com/photos/orchestra-playing-their-piece-7CcPLtywRso?utm_content=creditCopyText&amp;amp;utm_medium=referral&amp;amp;utm_source=unsplash" rel="noopener noreferrer"&gt;Unsplash&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://kubernetes.io" rel="noopener noreferrer"&gt;Kubernetes&lt;/a&gt; is the most popular container orchestration platform. It's open-source, production-ready, and extensible. Kubernetes has emerged as the de facto standard for container orchestration, empowering organizations to scale and manage containerized applications effortlessly. Its open-source nature, coupled with its robust ecosystem, makes it a go-to platform for automating deployment, scaling, and operations in the cloud-native world. In this article, we will talk about the architecture of Kubernetes. Understanding the architecture and components of Kubernetes will be a good starting point for the Kubernetes journey.&lt;/p&gt;

&lt;h2&gt;
  
  
  Kubernetes Cluster Architecture
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fkubernetes.io%2Fimages%2Fdocs%2Fkubernetes-cluster-architecture.svg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fkubernetes.io%2Fimages%2Fdocs%2Fkubernetes-cluster-architecture.svg" alt="App Platorm" width="1402" height="882"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Figure 1: Basic Kubernetes cluster architecture; Image from &lt;a href="https://kubernetes.io/docs/concepts/architecture/" rel="noopener noreferrer"&gt;Kubernetes docs&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Figure 1 shows the architecture of a basic Kubernetes cluster. More components can be added to the cluster depending on the use cases.&lt;/p&gt;

&lt;p&gt;There are 2 main parts in the Kubernetes cluster.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Control plane&lt;/li&gt;
&lt;li&gt;Worker nodes&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Control plane
&lt;/h2&gt;

&lt;p&gt;Control plane controls the cluster. It acts as the brain of the cluster. It makes decisions about the cluster. Also, It detects and responds to cluster events.&lt;/p&gt;

&lt;p&gt;Components of the control plane:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;kube-apiserver&lt;/li&gt;
&lt;li&gt;etcd&lt;/li&gt;
&lt;li&gt;kube-scheduler&lt;/li&gt;
&lt;li&gt;kube-controller-manager&lt;/li&gt;
&lt;li&gt;cloud-controller-manager&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Worker nodes
&lt;/h2&gt;

&lt;p&gt;Worker nodes do the actual workload of applications. They act as the muscles of the cluster. There will be one or more worker nodes.&lt;/p&gt;

&lt;p&gt;Components of the worker node:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;kubelet&lt;/li&gt;
&lt;li&gt;kube-proxy&lt;/li&gt;
&lt;li&gt;Container runtime&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each worker node consists of the above node components.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is a pod?
&lt;/h2&gt;

&lt;p&gt;Understanding the pods will be more helpful for talking about Kubernetes cluster architecture.&lt;/p&gt;

&lt;p&gt;In Kubernetes, pods are the smallest deployable units of computing. A pod can be one container or a group of containers.&lt;/p&gt;

&lt;h2&gt;
  
  
  Control plane components
&lt;/h2&gt;

&lt;h3&gt;
  
  
  kube-apiserver
&lt;/h3&gt;

&lt;p&gt;Kube-apiserver exposes Kubernetes APIs (Application Programming Interface) for interacting with the Kubernetes cluster. It acts as the front-end of the control plane. Also, kube-apiserver can be scaled horizontally.&lt;/p&gt;

&lt;p&gt;We can access Kubernetes APIs via:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;REST API calls&lt;/li&gt;
&lt;li&gt;CLI tools such as &lt;a href="https://kubernetes.io/docs/reference/kubectl/" rel="noopener noreferrer"&gt;kubectl&lt;/a&gt;, &lt;a href="https://kubernetes.io/docs/reference/setup-tools/kubeadm/" rel="noopener noreferrer"&gt;kubeadm&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  etcd
&lt;/h3&gt;

&lt;p&gt;Etcd is a key value store for all cluster data. It is an &lt;a href="https://etcd.io/" rel="noopener noreferrer"&gt;etcd&lt;/a&gt; data store. So, It is highly available, reliable, and distributed.&lt;/p&gt;

&lt;p&gt;Data stored in the etcd:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Cluster configuration data&lt;/li&gt;
&lt;li&gt;Information about Kubernetes objects' states&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  kube-scheduler
&lt;/h3&gt;

&lt;p&gt;Kube-scheduler maintains the health of the cluster. It watches the pods. Also, it schedules pods to an appropriate node. Various factors are considered when scheduling. The following are some of them:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;individual and collective resource requirements&lt;/li&gt;
&lt;li&gt;hardware/software/policy constraints&lt;/li&gt;
&lt;li&gt;affinity and anti-affinity specifications&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  kube-controller-manager
&lt;/h3&gt;

&lt;p&gt;Kube-controller-manager consists of multiple controllers. These controllers make the decisions about the cluster and maintain the cluster. Logically, each controller can be considered as a separate process. To reduce the complexity, all the controller processes are compiled into a single binary and run as a single process. The following are some of them:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Node Controller: Noticing and responding when nodes go down&lt;/li&gt;
&lt;li&gt;Job Controller: Watches the job objects and executes them&lt;/li&gt;
&lt;li&gt;EndpointSlice Controller: Populate EndpointSlice objects&lt;/li&gt;
&lt;li&gt;ServiceAccount Controller: Create default ServiceAccounts for new namespaces&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We actually don't need to know in-depth about these controllers to use a Kubernetes cluster. However, in-depth knowledge will be valuable for Kubernetes administrators.&lt;/p&gt;

&lt;h3&gt;
  
  
  cloud-controller-manager
&lt;/h3&gt;

&lt;p&gt;Cloud-controller-manager contains cloud service provider's (e.g., AWS, GCP, etc.) specific controller logics. It links the cluster with the cloud provider's APIs.&lt;/p&gt;

&lt;p&gt;Similar to the kube-controller-manager, cloud-controller-manager consists of multiple control logics compiled into a single binary and run as a single process.&lt;/p&gt;

&lt;p&gt;If the Kubernetes cluster is on-premise or in a learning environment (e.g., Minikube, kind, etc.), there's no cloud-controller-manager.&lt;/p&gt;

&lt;h2&gt;
  
  
  Worker nodes components
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Container Runtime
&lt;/h3&gt;

&lt;p&gt;Container runtime empowers Kubernetes to run containers effectively. It manages the execution and lifecycle of containers.&lt;/p&gt;

&lt;p&gt;Kubernetes supports container runtimes that are any implementation of &lt;a href="https://kubernetes.io/docs/concepts/architecture/cri/" rel="noopener noreferrer"&gt;Kubernetes CRI (Container Runtime Interface)&lt;/a&gt;. The following are some of the Container runtimes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.docker.com/" rel="noopener noreferrer"&gt;Docker&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://containerd.io/" rel="noopener noreferrer"&gt;Containerd&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://cri-o.io/" rel="noopener noreferrer"&gt;CRI-O&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  kubelet
&lt;/h3&gt;

&lt;p&gt;Kubelet is an application that communicates with the control plane. It acts as an agent of the control plane. It executes the decisions made by the control plane. It takes a set of PodSpecs and ensures that the containers described in the PodSpecs are running and healthy.&lt;/p&gt;

&lt;h3&gt;
  
  
  kube-proxy
&lt;/h3&gt;

&lt;p&gt;Kube-proxy is a network proxy for facilitating Kubernetes networking services. It handles communication inside or outside the cluster.&lt;/p&gt;

&lt;p&gt;If there is a network plugin that has similar functionalities to the kube-proxy, kube-proxy won't be necessary.&lt;/p&gt;

&lt;h2&gt;
  
  
  Production Kubernetes Cluster
&lt;/h2&gt;

&lt;p&gt;Creating a production Kubernetes cluster from scratch is tedious. Also, I don't recommend it at all.&lt;/p&gt;

&lt;p&gt;We can use a deployment tool to create a production Kubernetes cluster. The following are some of the deployment tools:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://kubernetes.io/docs/reference/setup-tools/kubeadm" rel="noopener noreferrer"&gt;kubeadm&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://kops.sigs.k8s.io" rel="noopener noreferrer"&gt;kops&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The easiest way to have a production-grade Kubernetes cluster is by using a managed Kubernetes service. The following are some of the managed Kubernetes services:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://cloud.google.com/kubernetes-engine/?hl=en" rel="noopener noreferrer"&gt;GCP&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://aws.amazon.com/eks" rel="noopener noreferrer"&gt;EKS&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://azure.microsoft.com/en-us/products/kubernetes-service" rel="noopener noreferrer"&gt;AKS&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  My thoughts
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F2hza9qhfsthpd7akjspo.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F2hza9qhfsthpd7akjspo.gif" alt="Baby yoda eating" width="480" height="270"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Since I use AWS as my day-to-day cloud provider, I personally have used EKS only. Honestly, my experience with EKS is awful. Although AWS EKS is a managed service, I'm encountering many issues with it. Also, managing AWS EKS cluster with IaC (Infrastructure as Code) such as Terraform or Pulumi is very challenging. The only reason I use EKS is that my current organization's whole system is in AWS.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;[!IMPORTANT]&lt;br&gt;
If you're planning to use AWS EKS, I highly recommend using &lt;a href="https://eksctl.io" rel="noopener noreferrer"&gt;eksctl&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;But keep in mind as of 6th October 2024, eksctl doesn't have a stable major release yet. Its latest version is still 0.191.0.&lt;/p&gt;

&lt;p&gt;I recommend reading &lt;a href="https://medium.com/@elliotgraebert/comparing-the-top-eight-managed-kubernetes-providers-2ae39662391b" rel="noopener noreferrer"&gt;this medium article&lt;/a&gt; for having a comparison of managed Kubernetes services.&lt;/p&gt;

&lt;p&gt;In my opinion, for a simple production system, Kubernetes is unnecessary. But for a complex large-distributed system, Kubernetes is the best solution.&lt;/p&gt;

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

&lt;p&gt;In this article, we explored the architecture of Kubernetes. Understanding the architecture and components of Kubernetes will be valuable for a solid foundation of Kubernetes. Also, I encourage you to get hands-on experience with Kubernetes. &lt;a href="https://minikube.sigs.k8s.io/docs" rel="noopener noreferrer"&gt;MiniKube&lt;/a&gt; will be a good starting point for that.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://kubernetes.io/docs/concepts/architecture" rel="noopener noreferrer"&gt;https://kubernetes.io/docs/concepts/architecture&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.redhat.com/en/topics/containers/kubernetes-architecture" rel="noopener noreferrer"&gt;https://www.redhat.com/en/topics/containers/kubernetes-architecture&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://kubernetes.io/docs/setup/production-environment" rel="noopener noreferrer"&gt;https://kubernetes.io/docs/setup/production-environment&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>kubernetes</category>
      <category>devops</category>
      <category>containers</category>
    </item>
    <item>
      <title>Deploying Kubernetes dashboard on a Kubernetes cluster</title>
      <dc:creator>Dilanka Rathnasiri</dc:creator>
      <pubDate>Sat, 10 Aug 2024 08:19:46 +0000</pubDate>
      <link>https://dev.to/dilanka-rathnasiri/deploying-kubernetes-dashboard-on-a-kubernetes-cluster-kmi</link>
      <guid>https://dev.to/dilanka-rathnasiri/deploying-kubernetes-dashboard-on-a-kubernetes-cluster-kmi</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;cover image: Photo by &lt;a href="https://unsplash.com/@jbcreate_?utm_content=creditCopyText&amp;amp;utm_medium=referral&amp;amp;utm_source=unsplash" rel="noopener noreferrer"&gt;Joseph Barrientos&lt;/a&gt; on &lt;a href="https://unsplash.com/photos/ship-helm-eUMEWE-7Ewg?utm_content=creditCopyText&amp;amp;utm_medium=referral&amp;amp;utm_source=unsplash" rel="noopener noreferrer"&gt;Unsplash&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In this article, we will talk about deploying &lt;a href="https://github.com/kubernetes/dashboard" rel="noopener noreferrer"&gt;Kubernetes dashboard&lt;/a&gt; on a Kubernetes cluster. Kubernetes dashboard is the official web user interface for getting an overview of a Kubernetes cluster. It can be used for managing, monitoring, and troubleshooting a Kubernetes cluster. Kubernetes dashboard is one of the easiest ways to have a dashboard for Kubernetes cluster managing and monitoring.&lt;/p&gt;

&lt;h2&gt;
  
  
  Install Kubernetes dashboard
&lt;/h2&gt;

&lt;p&gt;Kubernetes dashboard can be easily installed with &lt;a href="https://helm.sh" rel="noopener noreferrer"&gt;Helm&lt;/a&gt;. Execute the following commands in a terminal for installation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Add kubernetes-dashboard repository&lt;/span&gt;
helm repo add kubernetes-dashboard https://kubernetes.github.io/dashboard/
&lt;span class="c"&gt;# Deploy a Helm Release named "kubernetes-dashboard" using the kubernetes-dashboard chart&lt;/span&gt;
helm upgrade &lt;span class="nt"&gt;--install&lt;/span&gt; kubernetes-dashboard kubernetes-dashboard/kubernetes-dashboard &lt;span class="nt"&gt;--create-namespace&lt;/span&gt; &lt;span class="nt"&gt;--namespace&lt;/span&gt; kubernetes-dashboard
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We'll get a reply similar to the following.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Reply-A:&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Release &lt;span class="s2"&gt;"kubernetes-dashboard"&lt;/span&gt; does not exist. Installing it now.
NAME: kubernetes-dashboard
LAST DEPLOYED: Fri Aug  9 20:35:55 2024
NAMESPACE: kubernetes-dashboard
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
&lt;span class="k"&gt;*************************************************************************************************&lt;/span&gt;
&lt;span class="k"&gt;***&lt;/span&gt; PLEASE BE PATIENT: Kubernetes Dashboard may need a few minutes to get up and become ready &lt;span class="k"&gt;***&lt;/span&gt;
&lt;span class="k"&gt;*************************************************************************************************&lt;/span&gt;

Congratulations! You have just installed Kubernetes Dashboard &lt;span class="k"&gt;in &lt;/span&gt;your cluster.

To access Dashboard run:
  kubectl &lt;span class="nt"&gt;-n&lt;/span&gt; kubernetes-dashboard port-forward svc/kubernetes-dashboard-kong-proxy 8443:443

NOTE: In &lt;span class="k"&gt;case&lt;/span&gt; port-forward &lt;span class="nb"&gt;command &lt;/span&gt;does not work, make sure that kong service name is correct.
      Check the services &lt;span class="k"&gt;in &lt;/span&gt;Kubernetes Dashboard namespace using:
        kubectl &lt;span class="nt"&gt;-n&lt;/span&gt; kubernetes-dashboard get svc

Dashboard will be available at:
  https://localhost:8443 &lt;span class="c"&gt;# ‼ Note down this url for accessing the dashboard&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Create a user for accessing kubernetes dashboard
&lt;/h2&gt;

&lt;p&gt;We need a user to access the Kubernetes dashboard. We can regulate access control with Role-based access control (RBAC). Reference &lt;a href="https://kubernetes.io/docs/reference/access-authn-authz/rbac/#role-and-clusterrole" rel="noopener noreferrer"&gt;[3]&lt;/a&gt; provides a detailed explanation of RBAC.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Service Account:&lt;/em&gt;&lt;/strong&gt; &lt;br&gt;
A service account provides a distinct identity in a Kubernetes cluster. We can consider a service account to be similar to a user. But a Service account and a user account are two different things. Reference &lt;a href="https://kubernetes.io/docs/concepts/security/service-accounts" rel="noopener noreferrer"&gt;[4]&lt;/a&gt; provides a detailed explanation of the service account. We can use the following YAML configuration for creating a service account for the Kubernetes dashboard.&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;ServiceAccount&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;admin-user&lt;/span&gt;
  &lt;span class="na"&gt;namespace&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;kubernetes-dashboard&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;Cluster Role:&lt;/em&gt;&lt;/strong&gt; &lt;br&gt;
A cluster role is a set of rules that provides specific permissions. We only discuss four predefined roles for simplicity.&lt;/p&gt;

&lt;p&gt;They are,&lt;/p&gt;

&lt;p&gt;&lt;em&gt;cluster-admin:&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Provides superuser access to do anything on any resource.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;admin:&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Provides permissions to do most of the actions on most of the resources.&lt;/li&gt;
&lt;li&gt;It doesn't give the permission for the following,

&lt;ul&gt;
&lt;li&gt;write access to the resource quota or to the namespace itself&lt;/li&gt;
&lt;li&gt;write access to EndpointSlices (or Endpoints)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;edit:&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Provides permission to read and write access for most of the resources&lt;/li&gt;
&lt;li&gt;It doesn't give the permission for the following,

&lt;ul&gt;
&lt;li&gt;viewing or modifying roles or role bindings&lt;/li&gt;
&lt;li&gt;permissions aren't provided by the admin cluster role&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;view:&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Provides read-only access for most of the resources&lt;/li&gt;
&lt;li&gt;It doesn't give the permission for the following,

&lt;ul&gt;
&lt;li&gt;viewing roles or role bindings&lt;/li&gt;
&lt;li&gt;viewing Secrets&lt;/li&gt;
&lt;li&gt;permissions aren't provided by the edit cluster role&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Since great power comes with great responsibility, it is good to use minimum permission as much as possible.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fe0jdwbassu696miufm1z.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fe0jdwbassu696miufm1z.gif" alt="Uncle Ben advice" width="500" height="209"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this example Kubernetes configuration, we use the predefined admin cluster role.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Cluster Role Binding:&lt;/em&gt;&lt;/strong&gt; &lt;br&gt;
Cluster role binding attaches a cluster role to a service account. We can use the following YAML configuration for creating a cluster role binding for the created user.&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;rbac.authorization.k8s.io/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;ClusterRoleBinding&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;admin-user&lt;/span&gt;
&lt;span class="na"&gt;roleRef&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;apiGroup&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;rbac.authorization.k8s.io&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;ClusterRole&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;cluster-admin&lt;/span&gt;
&lt;span class="na"&gt;subjects&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
&lt;span class="pi"&gt;-&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;ServiceAccount&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;admin-user&lt;/span&gt;
  &lt;span class="na"&gt;namespace&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;kubernetes-dashboard&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Generating token for accessing Kubernetes dashboard
&lt;/h2&gt;

&lt;p&gt;We can generate an access token using the following.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl &lt;span class="nt"&gt;-n&lt;/span&gt; kubernetes-dashboard create token admin-user
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Accessing kubernetes dashboard
&lt;/h2&gt;

&lt;p&gt;There are two ways of accessing the Kubernetes dashboard.&lt;/p&gt;

&lt;p&gt;1.kubectl port-forward &lt;strong&gt;(I prefer this way)&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;execute the following command in the terminal,
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl &lt;span class="nt"&gt;-n&lt;/span&gt; kubernetes-dashboard port-forward svc/kubernetes-dashboard-kong-proxy 8443:443
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Now we can access Kubernetes dashboard from &lt;code&gt;https://localhost:8443&lt;/code&gt; &lt;strong&gt;(URL in Reply-A)&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;We use HTTPS for accessing because the URL in Reply-A is a https request&lt;/li&gt;
&lt;li&gt;If the URL in Reply-A is an HTTP request, we have to access the Kubernetes dashboard with HTTP&lt;/li&gt;
&lt;li&gt;Since we'll get a short URL in this method, I prefer this method.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;2.kubectl proxy&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;execute the following command in the terminal,
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl proxy &lt;span class="nt"&gt;--port&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;8001
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Now we can access the kubernetes dashboard
 from &lt;code&gt;http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard-kong-proxy:443/proxy/&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Create a long-lived Bearer Token for accessing the Kubernetes dashboard
&lt;/h2&gt;

&lt;p&gt;We can create a token and save it as a secret with the following YAML configuration.&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;Secret&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;admin-user&lt;/span&gt;
  &lt;span class="na"&gt;namespace&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;kubernetes-dashboard&lt;/span&gt;
  &lt;span class="na"&gt;annotations&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;kubernetes.io/service-account.name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;admin-user"&lt;/span&gt;
&lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;kubernetes.io/service-account-token&lt;/span&gt;  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then we can get the created token by executing the following command on the terminal.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl get secret admin-user &lt;span class="nt"&gt;-n&lt;/span&gt; kubernetes-dashboard &lt;span class="nt"&gt;-o&lt;/span&gt; &lt;span class="nv"&gt;jsonpath&lt;/span&gt;&lt;span class="o"&gt;={&lt;/span&gt;&lt;span class="s2"&gt;".data.token"&lt;/span&gt;&lt;span class="o"&gt;}&lt;/span&gt; | &lt;span class="nb"&gt;base64&lt;/span&gt; &lt;span class="nt"&gt;-d&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  That's it! We’ve successfully deployed the Kubernetes dashboard on our cluster.
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fe7j02so8ebzt2ulcl8gl.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fe7j02so8ebzt2ulcl8gl.gif" alt="minions hurray" width="500" height="226"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Pulumi Infrastructure as Code for Kubernetes dashboard deployment (Optional)
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;a href="https://github.com/dilanka-rathnasiri/simple-k8s" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;simple-k8s&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This GitHub project is an example of Infrastructure as Code with &lt;a href="https://www.pulumi.com" rel="noopener noreferrer"&gt;Pulumi&lt;/a&gt; for Kubernetes dashboard deployment. Since this article doesn't focus on Infrastructure as Code, we'll not discuss the code here. But I think this will help to get a rough idea.&lt;/p&gt;

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

&lt;p&gt;In this article, we’ve discussed deploying the Kubernetes dashboard on a Kubernetes cluster. The Kubernetes dashboard is one of the easiest ways to get an overview of a Kubernetes cluster. Hands-on experience with the Kubernetes dashboard is valuable in learning Kubernetes. Also, it'll be a good jumpstart. Even though the Kubernetes dashboard provides an overview of the cluster to some extent, I think it'll not be enough for an advanced production Kubernetes cluster.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://github.com/kubernetes/dashboard/blob/master/docs/user/accessing-dashboard/README.md" rel="noopener noreferrer"&gt;https://github.com/kubernetes/dashboard/blob/master/docs/user/accessing-dashboard/README.md&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/kubernetes/dashboard/blob/master/docs/user/access-control/creating-sample-user.md" rel="noopener noreferrer"&gt;https://github.com/kubernetes/dashboard/blob/master/docs/user/access-control/creating-sample-user.md&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://kubernetes.io/docs/reference/access-authn-authz/rbac/#role-and-clusterrole" rel="noopener noreferrer"&gt;https://kubernetes.io/docs/reference/access-authn-authz/rbac/#role-and-clusterrole&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://kubernetes.io/docs/concepts/security/service-accounts" rel="noopener noreferrer"&gt;https://kubernetes.io/docs/concepts/security/service-accounts&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>kubernetes</category>
    </item>
    <item>
      <title>Introduction to Authentication and Authorization</title>
      <dc:creator>Dilanka Rathnasiri</dc:creator>
      <pubDate>Fri, 05 Apr 2024 12:50:52 +0000</pubDate>
      <link>https://dev.to/dilanka-rathnasiri/introduction-to-authentication-and-authorization-7mh</link>
      <guid>https://dev.to/dilanka-rathnasiri/introduction-to-authentication-and-authorization-7mh</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;cover image: Photo by &lt;a href="https://unsplash.com/@introspectivedsgn?utm_content=creditCopyText&amp;amp;utm_medium=referral&amp;amp;utm_source=unsplash" rel="noopener noreferrer"&gt;Erik Mclean&lt;/a&gt; on &lt;a href="https://unsplash.com/photos/selective-focus-photography-of-gray-metal-padlock-XUJcmgEhpjA?utm_content=creditCopyText&amp;amp;utm_medium=referral&amp;amp;utm_source=unsplash" rel="noopener noreferrer"&gt;Unsplash&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;We will talk about the basics of authentication and authorization in this blog. I hope to write a blog series on IAM (Identity and Access Management). Understanding authentication and authorization is essential for IAM. So, this is the first article of my IAM blog series.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. What is Authentication?
&lt;/h2&gt;

&lt;p&gt;Authentication is the process of verifying the identity of someone or something. Simply authentication means proving identity.&lt;/p&gt;

&lt;p&gt;Let's consider traveling from Sri Lanka to Germany by airplane. We use passports to prove our identity at the airport before leaving Sri Lanka and after arriving in Germany. This process of proving the identity using a passport is an example of authentication.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Authorization
&lt;/h2&gt;

&lt;p&gt;Authorization is the process of verifying permission of someone or something to take some action. Simply that means checking whether someone can access a resource or not.&lt;/p&gt;

&lt;p&gt;Let's go to our airplane traveling example again. Even though we have a passport, we cannot leave or enter a country. We should have legal permission to leave or enter the country. As an example, some countries have banned the passports of certain nations. So, those passport holders cannot enter the country. Our permission for leaving or entering a country is checked at the airport. This process of verifying having legal permissions is an example of authorization.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Authentication vs Authorization
&lt;/h2&gt;

&lt;p&gt;Many people have a confusion about authentication and authorization. Even though authentication and authorization are related to each other in many use cases, they are different terms with different meanings.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;tr&gt;
&lt;th&gt;Authentication&lt;/th&gt;
&lt;th&gt;Authorization&lt;/th&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td&gt;Verifying the identity of the user&lt;/td&gt;
&lt;td&gt;Checking whether the user has permission to access a resource&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td&gt;Password, PIN, biometrics, and authentication apps are a few ways for authentication&lt;/td&gt;
&lt;td&gt;Access policy and security settings are a few ways for authorization&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td&gt;Usually done before authorization&lt;/td&gt;
&lt;td&gt;Usually done after authentication&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td&gt;OpenID Connect can be used for authentication&lt;/td&gt;
&lt;td&gt;OAuth 2.0 can be used for authorization&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td&gt;Usually, transmit information through ID tokens&lt;/td&gt;
&lt;td&gt;Usually, transmit information through Access token&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;&lt;/div&gt;

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

&lt;p&gt;We talked about the basics of authentication and authorization in this blog. These basics will help to understand the next blogs of this IAM blog series.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reference
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://auth0.com/docs/get-started/identity-fundamentals/authentication-and-authorization" rel="noopener noreferrer"&gt;https://auth0.com/docs/get-started/identity-fundamentals/authentication-and-authorization&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.okta.com/identity-101/authentication-vs-authorization" rel="noopener noreferrer"&gt;https://www.okta.com/identity-101/authentication-vs-authorization&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>beginners</category>
      <category>authentication</category>
      <category>authorization</category>
    </item>
    <item>
      <title>Delivering images in AWS S3 bucket through AWS API gateway</title>
      <dc:creator>Dilanka Rathnasiri</dc:creator>
      <pubDate>Sat, 16 Mar 2024 11:57:54 +0000</pubDate>
      <link>https://dev.to/dilanka-rathnasiri/delivering-images-in-aws-s3-bucket-through-aws-api-gateway-49e</link>
      <guid>https://dev.to/dilanka-rathnasiri/delivering-images-in-aws-s3-bucket-through-aws-api-gateway-49e</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;cover image: Photo by &lt;a href="https://unsplash.com/@francesco_ungaro?utm_content=creditCopyText&amp;amp;utm_medium=referral&amp;amp;utm_source=unsplash" rel="noopener noreferrer"&gt;Francesco Ungaro&lt;/a&gt; on &lt;a href="https://unsplash.com/photos/grey-bucket-on-brown-wooden-surface-VSwlS0PpWwc?utm_content=creditCopyText&amp;amp;utm_medium=referral&amp;amp;utm_source=unsplash" rel="noopener noreferrer"&gt;Unsplash&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In this article, we will talk about creating an AWS REST API as an AWS S3 proxy and delivering images in an S3 bucket through the API gateway.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;What are the different ways to deliver images in the s3 bucket?&lt;/strong&gt;
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Deliver images using public S3 URLs&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Deliver images in S3 using AWS Lambda API Gateway Integration&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Creating an AWS REST API as an S3 proxy&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Why deliver images in the S3 bucket through the API gateway?
&lt;/h2&gt;

&lt;p&gt;The simplest way to deliver images in the S3 bucket is public S3 URLs. However, the major drawback of this approach is that the S3 bucket will be public. Public cloud resources are vulnerable to attacks, and avoiding public cloud resources is a good practice.&lt;/p&gt;

&lt;p&gt;AWS API gateway will be a public interface for most endpoints. Many security methods can be used with AWS API gateway such as IAM, request throttling, and many more.&lt;/p&gt;

&lt;p&gt;AWS Lambda can be integrated into the AWS API gateway. Images in an S3 bucket can be delivered using a Lambda. But then we have to develop and maintain an additional Lambda function. Also, there will be an extra cost for it.&lt;/p&gt;

&lt;p&gt;When we use AWS API Gateway REST API as an S3 proxy, we can use security features in the AWS API gateway and we do not want to maintain an additional Lambda function. Also, we can keep our S3 bucket as a private resource.&lt;/p&gt;

&lt;h2&gt;
  
  
  Use AWS API Gateway REST API as an S3 proxy
&lt;/h2&gt;

&lt;p&gt;I explain the method using an example scenario. Also, I write this article with multiple steps for better understanding. Names and AWS regions can be changed according to the requirements. I use the new version of the AWS console (as of March 2024) in this article.&lt;/p&gt;

&lt;h2&gt;
  
  
  Table of content
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Create an IAM role for allowing API gateway to access S3 bucket objects&lt;/li&gt;
&lt;li&gt;Create an S3 bucket and upload an image&lt;/li&gt;
&lt;li&gt;Create an AWS API Gateway REST API&lt;/li&gt;
&lt;li&gt;Create REST resource&lt;/li&gt;
&lt;li&gt;Create REST method&lt;/li&gt;
&lt;li&gt;Configure method request&lt;/li&gt;
&lt;li&gt;Configure integration request&lt;/li&gt;
&lt;li&gt;Configure integration response&lt;/li&gt;
&lt;li&gt;Configure Method response&lt;/li&gt;
&lt;li&gt;Enable binary support in API Gateway&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  1. Create an IAM role for allowing API gateway to access S3 bucket objects
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Log into the AWS console&lt;/li&gt;
&lt;li&gt;Navigate to &lt;code&gt;IAM&lt;/code&gt; → &lt;code&gt;Roles&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Click on the &lt;code&gt;Create role&lt;/code&gt; button&lt;/li&gt;
&lt;li&gt;Select &lt;code&gt;Custom trust policy&lt;/code&gt; as the trusted entity type&lt;/li&gt;
&lt;li&gt;Enter the following policy as the custom trust policy
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;       {
           "Version": "2012-10-17",
           "Statement": [
               {
                   "Sid": "",
                   "Effect": "Allow",
                   "Principal": {
                       "Service": "apigateway.amazonaws.com"
                   },
                   "Action": "sts:AssumeRole"
               }
           ]
       }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Click on the &lt;code&gt;Next&lt;/code&gt; button&lt;/li&gt;
&lt;li&gt;Search for &lt;code&gt;AmazonS3ReadOnlyAccess&lt;/code&gt; and select it&lt;/li&gt;
&lt;li&gt;Then Click on the &lt;code&gt;Next&lt;/code&gt; button&lt;/li&gt;
&lt;li&gt;Enter a role name as &lt;code&gt;iam-test-role&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Then click on the &lt;code&gt;Create role&lt;/code&gt; button&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  2. Create an S3 bucket and upload an image
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Log into the AWS console&lt;/li&gt;
&lt;li&gt;Navigate to &lt;code&gt;S3&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Click on the &lt;code&gt;Create bucket&lt;/code&gt; button&lt;/li&gt;
&lt;li&gt;Select &lt;code&gt;us-east-1&lt;/code&gt; as the region&lt;/li&gt;
&lt;li&gt;Enter &lt;code&gt;api-gw-image-test-s3&lt;/code&gt; as the bucket name&lt;/li&gt;
&lt;li&gt;Leave default values for other configurations&lt;/li&gt;
&lt;li&gt;Click on the &lt;code&gt;Create bucket&lt;/code&gt; button&lt;/li&gt;
&lt;li&gt;Create a folder named &lt;code&gt;images&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Upload an image into the created folder&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  3. Create an AWS API Gateway REST API
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Log into your AWS console&lt;/li&gt;
&lt;li&gt;Navigate to &lt;code&gt;API Gateway&lt;/code&gt; → &lt;code&gt;APIs&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Click on the &lt;code&gt;Create API&lt;/code&gt; button&lt;/li&gt;
&lt;li&gt;Click on the &lt;code&gt;Build&lt;/code&gt; button on &lt;code&gt;Rest API&lt;/code&gt; pane&lt;/li&gt;
&lt;li&gt;Select &lt;code&gt;New API&lt;/code&gt; and use &lt;code&gt;test-api&lt;/code&gt; as the name&lt;/li&gt;
&lt;li&gt;Leave default values for other configurations&lt;/li&gt;
&lt;li&gt;Then click on the &lt;code&gt;Create API&lt;/code&gt; button&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  4. Create REST resource
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Click on the &lt;code&gt;Create resource&lt;/code&gt; button&lt;/li&gt;
&lt;li&gt;Create a resource and create REST resource &lt;code&gt;s3&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  5. Create REST method
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Click on the &lt;code&gt;Create method&lt;/code&gt; button to create a method&lt;/li&gt;
&lt;li&gt;Choose as following

&lt;ul&gt;
&lt;li&gt;Method type → GET&lt;/li&gt;
&lt;li&gt;Integration type → AWS service&lt;/li&gt;
&lt;li&gt;AWS Region → us-east-1&lt;/li&gt;
&lt;li&gt;AWS service → Simple Storage Service (S3)&lt;/li&gt;
&lt;li&gt;HTTP method → GET&lt;/li&gt;
&lt;li&gt;Action type → Use path override&lt;/li&gt;
&lt;li&gt;Path override → api-gw-image-test-s3/images/{image}&lt;/li&gt;
&lt;li&gt;Execution role → arn of the created aws role in the step (1)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Leave the other options as default&lt;/li&gt;
&lt;li&gt;Click on the &lt;code&gt;Create method&lt;/code&gt; button&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  6. Configure method request
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Select &lt;code&gt;Method request&lt;/code&gt; tab pane&lt;/li&gt;
&lt;li&gt;Click on &lt;code&gt;Edit&lt;/code&gt; button&lt;/li&gt;
&lt;li&gt;Expand &lt;code&gt;URL query string parameters&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Click on &lt;code&gt;Add query string&lt;/code&gt; button&lt;/li&gt;
&lt;li&gt;Enter &lt;code&gt;image&lt;/code&gt; as the Name&lt;/li&gt;
&lt;li&gt;Check &lt;code&gt;Required&lt;/code&gt; button&lt;/li&gt;
&lt;li&gt;Click on &lt;code&gt;Save&lt;/code&gt; button&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  7. Configure integration request
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Select &lt;code&gt;Integration request&lt;/code&gt; tab pane&lt;/li&gt;
&lt;li&gt;Click on &lt;code&gt;Edit&lt;/code&gt; button&lt;/li&gt;
&lt;li&gt;Select &lt;code&gt;When there are no templates defined (recommended)&lt;/code&gt; as &lt;code&gt;Request body passthrough&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Expand &lt;code&gt;URL path parameters&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Click on &lt;code&gt;Add path parameter&lt;/code&gt; button&lt;/li&gt;
&lt;li&gt;Enter &lt;code&gt;image&lt;/code&gt; as the name&lt;/li&gt;
&lt;li&gt;Enter &lt;code&gt;method.request.querystring.image&lt;/code&gt; as the path&lt;/li&gt;
&lt;li&gt;Expand &lt;code&gt;URL request headers parameters&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Click on &lt;code&gt;Add query string parameter&lt;/code&gt; button&lt;/li&gt;
&lt;li&gt;Enter &lt;code&gt;Accept&lt;/code&gt; as &lt;code&gt;Name&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Enter &lt;code&gt;'*/*'&lt;/code&gt; (Value should be given with single quotes) as &lt;code&gt;Mapped from&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Click on &lt;code&gt;Save&lt;/code&gt; button&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  8. Configure integration response
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Select &lt;code&gt;Integration responses&lt;/code&gt; tab pane&lt;/li&gt;
&lt;li&gt;Delete &lt;code&gt;Default - Response&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Click on &lt;code&gt;Create response&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Enter &lt;code&gt;2\d{2}&lt;/code&gt; as HTTP status regex&lt;/li&gt;
&lt;li&gt;Click on &lt;code&gt;Create&lt;/code&gt; button&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  9. Configure Method response
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Select &lt;code&gt;Method responses&lt;/code&gt; tab pane&lt;/li&gt;
&lt;li&gt;Click on &lt;code&gt;Edit&lt;/code&gt; button on &lt;code&gt;Response 200&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Click on &lt;code&gt;Add header&lt;/code&gt; button&lt;/li&gt;
&lt;li&gt;Enter &lt;code&gt;Content-Type&lt;/code&gt; as &lt;code&gt;Header name&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Remove &lt;code&gt;Response body&lt;/code&gt; items&lt;/li&gt;
&lt;li&gt;Click on &lt;code&gt;Save&lt;/code&gt; button&lt;/li&gt;
&lt;li&gt;Then again select &lt;code&gt;Integration responses&lt;/code&gt; tab pane&lt;/li&gt;
&lt;li&gt;Click on &lt;code&gt;Edit&lt;/code&gt; button&lt;/li&gt;
&lt;li&gt;Enter &lt;code&gt;'*/*'&lt;/code&gt; (Value should be given with single quotes) as &lt;code&gt;Mapping value&lt;/code&gt; of the &lt;code&gt;Content-Type&lt;/code&gt; response header&lt;/li&gt;
&lt;li&gt;Click on &lt;code&gt;Save&lt;/code&gt; button&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  10. Enable binary support in API Gateway
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Navigate to &lt;code&gt;API settings&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Click on &lt;code&gt;Manage media type&lt;/code&gt; button on &lt;code&gt;Binary media types&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Click on &lt;code&gt;Add binary media type&lt;/code&gt; button&lt;/li&gt;
&lt;li&gt;Enter &lt;code&gt;*/*&lt;/code&gt; as &lt;code&gt;Binary media type&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Click on &lt;code&gt;Save changes&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Finally,
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Click on &lt;code&gt;Deploy API&lt;/code&gt; and do an API Gateway deployment&lt;/li&gt;
&lt;li&gt;Enter the invoked URI on the browser with the image query string (e.g.: &lt;a href="https://aabhd7xr1z.execute-api.us-east-1.amazonaws.com/test/s3?image=porsche-911.jpg" rel="noopener noreferrer"&gt;https://aabhd7xr1z.execute-api.us-east-1.amazonaws.com/test/s3?image=porsche-911.jpg&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;Ultimately, the Image is displayed in the browser&lt;/li&gt;
&lt;/ol&gt;

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

&lt;p&gt;In this article, we have discussed creating an AWS REST API as an Amazon S3 proxy and delivering images in an S3 bucket through the API gateway. We can use AWS API Gateway as a secure and cost-effective way to deliver S3 images.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.aws.amazon.com/apigateway/latest/developerguide/integrating-api-with-aws-services-s3.html" rel="noopener noreferrer"&gt;https://docs.aws.amazon.com/apigateway/latest/developerguide/integrating-api-with-aws-services-s3.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://serverlessland.com/patterns/apigateway-rest-s3-sam" rel="noopener noreferrer"&gt;https://serverlessland.com/patterns/apigateway-rest-s3-sam&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>aws</category>
      <category>apigateway</category>
      <category>s3</category>
    </item>
    <item>
      <title>Introduction to Java Servlets</title>
      <dc:creator>Dilanka Rathnasiri</dc:creator>
      <pubDate>Fri, 15 Mar 2024 15:05:33 +0000</pubDate>
      <link>https://dev.to/dilanka-rathnasiri/introduction-to-java-servlets-32oc</link>
      <guid>https://dev.to/dilanka-rathnasiri/introduction-to-java-servlets-32oc</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;cover image: Photo by &lt;a href="https://unsplash.com/@evansmogor?utm_content=creditCopyText&amp;amp;utm_medium=referral&amp;amp;utm_source=unsplash" rel="noopener noreferrer"&gt;Evan Smogor&lt;/a&gt; on &lt;a href="https://unsplash.com/photos/blue-and-white-sailboat-on-ocean-during-daytime-9-i4lI1ijes?utm_content=creditCopyText&amp;amp;utm_medium=referral&amp;amp;utm_source=unsplash" rel="noopener noreferrer"&gt;Unsplash&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;We are discussing the basics of Java Servlets in this article.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Java Servlet?
&lt;/h2&gt;

&lt;p&gt;Java servlet is the Java way to develop a web application that can generate dynamic web pages. Servlets are on the server side.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is the web container?
&lt;/h2&gt;

&lt;p&gt;The web container is the interface between the servlets and the web server. All the servlets are run inside the web container. In this article, I use Apache Tomcat as the web container. Also, you can use Java EE servers like JBoss or GlassFish for running Java servlets. But Apache Tomcat is lightweight and easy to use.&lt;/p&gt;

&lt;h2&gt;
  
  
  Let’s build our first Java Servlet
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Technologies used in this article
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Java 11&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Apache Maven 3.6.3&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Apache Tomcat 10.1.7&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;IntelliJ IDEA Community Edition&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Do we need IntelliJ Idea Ultimate?
&lt;/h3&gt;

&lt;p&gt;No, we do not need it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Create Maven project
&lt;/h3&gt;

&lt;p&gt;Let’s generate a Maven project in batch mode. For that, enter the following command on the command line.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mvn archetype:generate -B -DgroupId="com.example" -DartifactId="servlet-example-1"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;We can change “groupId” and “artifactId” as we want. In this example project&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;groupId = com.example&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;artifactId = servlet-example-1&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Project structure
&lt;/h3&gt;

&lt;p&gt;We need to set up the project structure as followings.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fw0tgunwgx8xor5eesfnt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fw0tgunwgx8xor5eesfnt.png" alt="Project structure" width="391" height="276"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Modify POM file
&lt;/h3&gt;

&lt;p&gt;First, we open the project from IntelliJ IDEA.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"&amp;gt;

  &amp;lt;modelVersion&amp;gt;4.0.0&amp;lt;/modelVersion&amp;gt;
  &amp;lt;groupId&amp;gt;com.example&amp;lt;/groupId&amp;gt;
  &amp;lt;artifactId&amp;gt;servlet-example-1&amp;lt;/artifactId&amp;gt;
  &amp;lt;packaging&amp;gt;war&amp;lt;/packaging&amp;gt;
  &amp;lt;version&amp;gt;1.0-SNAPSHOT&amp;lt;/version&amp;gt;
  &amp;lt;name&amp;gt;servlet-example-1&amp;lt;/name&amp;gt;

  &amp;lt;properties&amp;gt;
    &amp;lt;project.build.sourceEncoding&amp;gt;UTF-8&amp;lt;/project.build.sourceEncoding&amp;gt;
    &amp;lt;maven.compiler.source&amp;gt;11&amp;lt;/maven.compiler.source&amp;gt;
    &amp;lt;maven.compiler.target&amp;gt;11&amp;lt;/maven.compiler.target&amp;gt;
  &amp;lt;/properties&amp;gt;

  &amp;lt;dependencies&amp;gt;
    &amp;lt;dependency&amp;gt;
      &amp;lt;groupId&amp;gt;jakarta.servlet&amp;lt;/groupId&amp;gt;
      &amp;lt;artifactId&amp;gt;jakarta.servlet-api&amp;lt;/artifactId&amp;gt;
      &amp;lt;version&amp;gt;6.0.0&amp;lt;/version&amp;gt;
      &amp;lt;scope&amp;gt;provided&amp;lt;/scope&amp;gt;
    &amp;lt;/dependency&amp;gt;
  &amp;lt;/dependencies&amp;gt;

  &amp;lt;build&amp;gt;
    &amp;lt;plugins&amp;gt;
      &amp;lt;plugin&amp;gt;
        &amp;lt;groupId&amp;gt;org.apache.maven.plugins&amp;lt;/groupId&amp;gt;
        &amp;lt;artifactId&amp;gt;maven-war-plugin&amp;lt;/artifactId&amp;gt;
        &amp;lt;version&amp;gt;3.3.2&amp;lt;/version&amp;gt;
        &amp;lt;configuration&amp;gt;
          &amp;lt;webappDirectory&amp;gt;src/main/webapp&amp;lt;/webappDirectory&amp;gt;
          &amp;lt;webXml&amp;gt;src/main/webapp/WEB-INF/web.xml&amp;lt;/webXml&amp;gt;
        &amp;lt;/configuration&amp;gt;
      &amp;lt;/plugin&amp;gt;
    &amp;lt;/plugins&amp;gt;
  &amp;lt;/build&amp;gt;
&amp;lt;/project&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The POM file of the example project is shown above. Let’s discuss each required component in the POM file.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fnr6a7ogu9kwjn7m3jpy8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fnr6a7ogu9kwjn7m3jpy8.png" alt="pom.xml file" width="800" height="664"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;1 → We use war (web application archive) files in java servlets. Therefore, we have to set the packaging to WAR.&lt;/p&gt;

&lt;p&gt;2 → We set the encoding system of Apache Maven to UTF-8. This is not related to the Java servlets. This is done for Apache Maven.&lt;/p&gt;

&lt;p&gt;3 and 4 → We set the Java version to 11.&lt;/p&gt;

&lt;p&gt;5 → Adding required “servlet-api” dependency for Java servlet. Since Apache Tomcat has all the required libraries, we set the scope to “provided”.&lt;/p&gt;

&lt;p&gt;6 → We need “maven-war-plugin” for creating a Java WAR file.&lt;/p&gt;

&lt;p&gt;7 → Web app directory path from the content root.&lt;/p&gt;

&lt;p&gt;8 → web.xml file path from the content root.&lt;/p&gt;

&lt;h3&gt;
  
  
  Servlet App.java class source code
&lt;/h3&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package com.example;

import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;

public class App extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        PrintWriter out = resp.getWriter();
        out.println("Hello!");
        out.close();
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;“HttpServlet” class provides methods for handling REST API methods such as GET, POST, PUT, and POST.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;“doGet” method → Java method for handling GET requests&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“doPost” method → Java method for handling POST requests&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“doPut” method → Java method for handling PUT requests&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;“doDelete” method → Java method for handling DELETE requests&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In this example project, we only used the “doGet” method. It provides a “Hello!” response for GET requests.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is web.xml?
&lt;/h3&gt;

&lt;p&gt;The web.xml file is the deployment descriptor of the project. This deployment descriptor contains information about the servlet. The deployment descriptor tells the web container how to handle the files in the servlet project.&lt;/p&gt;

&lt;h3&gt;
  
  
  Content of the deployment descriptor
&lt;/h3&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE web-app PUBLIC
        "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
        "http://java.sun.com/dtd/web-app_2_3.dtd" &amp;gt;

&amp;lt;web-app&amp;gt;
    &amp;lt;servlet&amp;gt;
        &amp;lt;servlet-name&amp;gt;hello&amp;lt;/servlet-name&amp;gt;
        &amp;lt;servlet-class&amp;gt;com.example.App&amp;lt;/servlet-class&amp;gt;
    &amp;lt;/servlet&amp;gt;
    &amp;lt;servlet-mapping&amp;gt;
        &amp;lt;servlet-name&amp;gt;hello&amp;lt;/servlet-name&amp;gt;
        &amp;lt;url-pattern&amp;gt;/hello&amp;lt;/url-pattern&amp;gt;
    &amp;lt;/servlet-mapping&amp;gt;
&amp;lt;/web-app&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The web descriptor of the example project is shown above.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;All the servlet related tags have to use inside the "" and “” tags.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The “” tag is used to define the name of the servlet. “” and “” tags are used inside the "" and “” tags. The “” tag is used to provide the name of the servlet. The “” tag is used to provide the Java class for the relevant servlet.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The “” tag is used to define the mapping of the servlet. “” and “” tags are used inside the “" and “” tags. The “” tag is used to provide the name of the servlet. The “” tag is used to provide the URL pattern of the relevant servlet.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Deploying servlet
&lt;/h3&gt;

&lt;p&gt;First, we have to build the WAR file. We can do that by executing the following command in the terminal or PowerShell.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mvn clean install
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This WAR file can be deployed in Apache Tomcat. First, we have to start the Apache Tomcat. Then let’s go to the “Manager App”. In the “deploy” section, let’s click on the “Choose File” button in the “WAR file to deploy” subsection. Then let’s choose the WAR file and click on the “Deploy” button. Then, we can see the “/servlet-example-2–1.0-SNAPSHOT” in the “Application” section. Now, we can call the servlet by sending requests to “&lt;a href="http://localhost:8080/servlet-example-2-1.0-SNAPSHOT/hello" rel="noopener noreferrer"&gt;http://localhost:8080/servlet-example-2-1.0-SNAPSHOT/hello&lt;/a&gt;”.&lt;/p&gt;

&lt;h3&gt;
  
  
  Servlet Annotations
&lt;/h3&gt;

&lt;p&gt;We can replace the web.xml file with annotations.&lt;/p&gt;

&lt;p&gt;We can use “@WebServlet” annotation for “” and “” tags in web.xml. We can use the “value” attribute to define the URL pattern of the servlet. We can use the “name” attribute to define the name of the servlet.&lt;/p&gt;

&lt;p&gt;We can rewrite App.java class with annotations as followings.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package com.example;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(
        value = "/hello",
        name = "hello"
)
public class App extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        PrintWriter out = resp.getWriter();
        out.println("Hello!");
        out.close();
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Also, we need to change the POM file to stop searching for the web.xml file. For that, we have to change the configurations of the “maven-war-plugin” in the POM file as followings.&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;plugin&amp;gt;&lt;br&gt;
  &amp;lt;groupId&amp;gt;org.apache.maven.plugins&amp;lt;/groupId&amp;gt;&lt;br&gt;
  &amp;lt;artifactId&amp;gt;maven-war-plugin&amp;lt;/artifactId&amp;gt;&lt;br&gt;
  &amp;lt;version&amp;gt;3.3.2&amp;lt;/version&amp;gt;&lt;br&gt;
  &amp;lt;configuration&amp;gt;&lt;br&gt;
    &amp;lt;failOnMissingWebXml&amp;gt;false&amp;lt;/failOnMissingWebXml&amp;gt;&lt;br&gt;
  &amp;lt;/configuration&amp;gt;&lt;br&gt;
&amp;lt;/plugin&amp;gt;&lt;br&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  Summary&lt;br&gt;
&lt;/h2&gt;

&lt;p&gt;In this article, we have discussed the basics of Java Servlets with an example. We can create a Java servlet with a web.xml file or annotations. We can use Apache Tomcat for deploying Java servlet.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://javatutorial.net/category/java-ee/" rel="noopener noreferrer"&gt;&lt;strong&gt;Java Tutorial Network&lt;/strong&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.geeksforgeeks.org/introduction-java-servlets/" rel="noopener noreferrer"&gt;&lt;strong&gt;Introduction to Java Servlets - GeeksforGeeks&lt;/strong&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://docs.oracle.com/cd/E19226-01/820-7759/gcrmb/index.html" rel="noopener noreferrer"&gt;&lt;strong&gt;The Web Container (Your First Cup: An Introduction to the Java EE Platform)&lt;/strong&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.educative.io/answers/what-is-a-web-container" rel="noopener noreferrer"&gt;&lt;strong&gt;What is a web container?&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>java</category>
      <category>programming</category>
    </item>
    <item>
      <title>Java Method overriding</title>
      <dc:creator>Dilanka Rathnasiri</dc:creator>
      <pubDate>Fri, 15 Mar 2024 14:51:24 +0000</pubDate>
      <link>https://dev.to/dilanka-rathnasiri/java-method-overriding-6e8</link>
      <guid>https://dev.to/dilanka-rathnasiri/java-method-overriding-6e8</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;small&gt;cover image: Photo by &lt;a href="https://unsplash.com/@ewitsoe?utm_content=creditCopyText&amp;amp;utm_medium=referral&amp;amp;utm_source=unsplash" rel="noopener noreferrer"&gt;Erik Witsoe&lt;/a&gt; on &lt;a href="https://unsplash.com/photos/white-coffee-cup-on-table-DvbkZqpllGs?utm_content=creditCopyText&amp;amp;utm_medium=referral&amp;amp;utm_source=unsplash" rel="noopener noreferrer"&gt;Unsplash&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;We are discussing Java Method overriding in this article with examples.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Java Method Overriding?
&lt;/h2&gt;

&lt;p&gt;There is a child class. Let’s take it as class A. Its parent class is B. All methods in B are inherited from B to A. A has a method c. It has the same signature (method name and parameter types) as a method in B. Method c in A has its own implementation specific to A. This is called method overriding.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why do we need Java Method Overriding?
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;When we want specific implementation for a function in the child class&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Achieve Runtime Polymorphism in Java&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;When we want to have customized implementation of java native methods&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Run Time Polymorphism
&lt;/h2&gt;

&lt;p&gt;In Run Time Polymorphism, Java Virtual Machine determines which methods to call at the run time. A child class has its own specific implementation for a method that already exists in the parent class.&lt;/p&gt;

&lt;h2&gt;
  
  
  Example 1
&lt;/h2&gt;

&lt;p&gt;First, we see a simple example of how to do Java Method overriding.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Car {
    public void running() {
        System.out.println("Car is running");
    }
}

public class Benz extends Car{
}

public class BMW extends Car{
    @Override
    public void running() {
        System.out.println("BMW car is running");
    }
}

public class Example1 {
    public static void main( String[] args ) {
        Car car1 = new Benz();
        Car car2 = new BMW();

        car1.running();
        car2.running();
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Car is running
BMW car is running
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In this example, we have overridden running method in BMW class.&lt;/p&gt;

&lt;h2&gt;
  
  
  Example 2
&lt;/h2&gt;

&lt;p&gt;Also, we can use Java method overriding for customizing the implementation of java native methods.&lt;/p&gt;

&lt;p&gt;Let’s see how we implement a simple case-insensitive Java HashMap.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Student {
    private String name;
    private int grade;

    public Student(String name, int grade) {
        this.name = name;
        this.grade = grade;
    }

    public String getName() {
        return name;
    }

    public int getGrade() {
        return grade;
    }
}

import java.util.HashMap;
import java.util.Map;

public class Example2 {
    public static void main(String[] args) {
        Student student1 = new Student("Kamal", 10);
        Student student2 = new Student("Nimal", 7);

        Map&amp;lt;String, Student&amp;gt; studentOverrideMap = new HashMap&amp;lt;&amp;gt;() {
            @Override
            public Student put(String key, Student value) {
                return super.put(key.toLowerCase(), value);
            }

            @Override
            public Student get(Object key) {
                return super.get(key.toString().toLowerCase());
            }

            @Override
            public boolean containsKey(Object key) {
                return super.containsKey(key.toString().toLowerCase());
            }
        };

        studentOverrideMap.put("Kamal", student1);
        studentOverrideMap.put("Nimal", student2);

        System.out.println("Student1 name:" + studentOverrideMap.get("KAMAL").getName() + " grade:" + studentOverrideMap.get("KAMAL").getGrade());
        System.out.println("Student2 name:" + studentOverrideMap.get("NIMAL").getName() + " grade:" + studentOverrideMap.get("NIMAL").getGrade());
        System.out.println("KAMAL is in map: " + studentOverrideMap.containsKey("KAMAL"));
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Student1 name:Kamal grade:10
Student2 name:Nimal grade:7
KAMAL is in map: true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In this example, we have overridden put, get, and containsKey methods in Java HashMap. In put method, we have converted the HashMap key to lowercase before we add an element to the HashMap. In get method, we have converted the HashMap key to lowercase before getting the object. In containsKey method, we have converted the HashMap key to lowercase before searching for the key.&lt;/p&gt;

&lt;h2&gt;
  
  
  The situations when we cannot use Java Method Overriding
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;We cannot use Java Method Overriding for static methods&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We cannot use Java Method Overriding for final methods&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

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

&lt;p&gt;A child class has its own specific implementation for a method that already exists in the parent class. This is called Java Method Overriding. We can use Java Method Overriding for having a specific implementation for a function in the child class, achieving Runtime Polymorphism in Java, and having a customized implementation of java native methods. We cannot use Java Method Overriding for final or static methods.&lt;/p&gt;

&lt;p&gt;Thank you for reading!&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://www.geeksforgeeks.org/overriding-in-java/" rel="noopener noreferrer"&gt;&lt;strong&gt;Overriding in Java - GeeksforGeeks&lt;/strong&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.simplilearn.com/tutorials/java-tutorial/overriding-in-java#why_is_overriding_in_java_useful" rel="noopener noreferrer"&gt;&lt;strong&gt;What is Method Overriding in Java? Uses, Examples &amp;amp; Everything You Should Know&lt;/strong&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.geeksforgeeks.org/difference-between-compile-time-and-run-time-polymorphism-in-java/" rel="noopener noreferrer"&gt;&lt;strong&gt;Difference between Compile-time and Run-time Polymorphism in Java - GeeksforGeeks&lt;/strong&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>java</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
