<?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: Subham Nandi</title>
    <description>The latest articles on DEV Community by Subham Nandi (@subham_nandi).</description>
    <link>https://dev.to/subham_nandi</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%2F1821460%2F5b955725-53bd-4e82-a49b-882028f7ac80.jpeg</url>
      <title>DEV Community: Subham Nandi</title>
      <link>https://dev.to/subham_nandi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/subham_nandi"/>
    <language>en</language>
    <item>
      <title>Understanding the Transition from Docker to Kubernetes</title>
      <dc:creator>Subham Nandi</dc:creator>
      <pubDate>Thu, 30 Jan 2025 10:40:47 +0000</pubDate>
      <link>https://dev.to/subham_nandi/understanding-the-transition-from-docker-to-kubernetes-44oc</link>
      <guid>https://dev.to/subham_nandi/understanding-the-transition-from-docker-to-kubernetes-44oc</guid>
      <description>&lt;h3&gt;
  
  
  Understanding Docker's Limitations
&lt;/h3&gt;

&lt;h4&gt;
  
  
  1. Single Host Architecture
&lt;/h4&gt;

&lt;p&gt;Docker's fundamental limitation lies in its single-host nature. When running containers on a single host:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Resource conflicts become common&lt;/li&gt;
&lt;li&gt;One container's high resource usage can affect others&lt;/li&gt;
&lt;li&gt;Scale is limited by the host's capacity&lt;/li&gt;
&lt;li&gt;No built-in failover mechanisms exist&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  2. Lack of Auto-healing
&lt;/h4&gt;

&lt;p&gt;In production environments, containers can fail for numerous reasons. Docker's approach to container failures is passive:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Failed containers remain down until manually restarted&lt;/li&gt;
&lt;li&gt;Requires constant monitoring by DevOps engineers&lt;/li&gt;
&lt;li&gt;Not feasible for managing thousands of containers&lt;/li&gt;
&lt;li&gt;Creates potential downtime and reliability issues&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  3. Manual Scaling Challenges
&lt;/h4&gt;

&lt;p&gt;As application traffic fluctuates, especially during peak periods like holiday seasons or special events:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Docker requires manual intervention for scaling&lt;/li&gt;
&lt;li&gt;No native load balancing capabilities&lt;/li&gt;
&lt;li&gt;Complex coordination needed for traffic distribution&lt;/li&gt;
&lt;li&gt;Resource allocation becomes a manual, time-consuming process&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  4. Limited Enterprise Support
&lt;/h4&gt;

&lt;p&gt;Docker, as a container platform, lacks several crucial enterprise-level features:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Advanced load balancing capabilities&lt;/li&gt;
&lt;li&gt;Built-in firewall management&lt;/li&gt;
&lt;li&gt;API gateway integration&lt;/li&gt;
&lt;li&gt;Enterprise-grade security features&lt;/li&gt;
&lt;li&gt;Comprehensive monitoring solutions&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Enter Kubernetes: The Solution to Container Orchestration
&lt;/h2&gt;

&lt;p&gt;Kubernetes, originally developed by Google based on their internal system called Borg, addresses these limitations comprehensively. Let's explore how Kubernetes solves each of Docker's core limitations.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Cluster Architecture
&lt;/h3&gt;

&lt;p&gt;Kubernetes introduces a distributed system architecture:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Multiple nodes working together as a cluster&lt;/li&gt;
&lt;li&gt;Intelligent workload distribution&lt;/li&gt;
&lt;li&gt;Resource isolation between applications&lt;/li&gt;
&lt;li&gt;Better fault tolerance and high availability&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2. Automatic Health Management
&lt;/h3&gt;

&lt;p&gt;Through its auto-healing capabilities, Kubernetes ensures application reliability:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Continuous monitoring of container health&lt;/li&gt;
&lt;li&gt;Automatic replacement of failed containers&lt;/li&gt;
&lt;li&gt;Proactive container replacement before failure&lt;/li&gt;
&lt;li&gt;Maintenance of desired state without human intervention&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3. Intelligent Scaling
&lt;/h3&gt;

&lt;p&gt;Kubernetes provides sophisticated scaling mechanisms:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Horizontal Pod Autoscaling (HPA) for automatic scaling&lt;/li&gt;
&lt;li&gt;Declaration-based manual scaling through YAML&lt;/li&gt;
&lt;li&gt;Built-in load balancing&lt;/li&gt;
&lt;li&gt;Traffic distribution management&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  4. Enterprise-Ready Features
&lt;/h3&gt;

&lt;p&gt;As a complete container orchestration platform, Kubernetes offers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Advanced load balancing through Ingress controllers&lt;/li&gt;
&lt;li&gt;Network policy management&lt;/li&gt;
&lt;li&gt;Role-Based Access Control (RBAC)&lt;/li&gt;
&lt;li&gt;Custom Resource Definitions (CRDs) for extensibility&lt;/li&gt;
&lt;li&gt;Integration with enterprise security tools&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>docker</category>
      <category>kubernetes</category>
    </item>
    <item>
      <title>Docker: Day 8 - Docker Compose</title>
      <dc:creator>Subham Nandi</dc:creator>
      <pubDate>Fri, 10 Jan 2025 12:32:51 +0000</pubDate>
      <link>https://dev.to/subham_nandi/docker-day-8-1718</link>
      <guid>https://dev.to/subham_nandi/docker-day-8-1718</guid>
      <description>&lt;h1&gt;
  
  
  Mastering Docker Compose: A Comprehensive Guide
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Docker Compose is a powerful tool that simplifies the management of multi-container Docker applications. By using a single configuration file, you can define, build, and orchestrate services, networks, and volumes for your applications. In this article, we will delve into the key features, components, and workflows of Docker Compose, helping you understand how to efficiently manage containerized applications.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why Docker Compose?
&lt;/h2&gt;

&lt;p&gt;When dealing with multi-container applications, managing individual containers can become complex. Docker Compose streamlines this process by allowing you to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Define an entire application stack&lt;/strong&gt; in one &lt;code&gt;docker-compose.yml&lt;/code&gt; file.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Start, stop, and rebuild services&lt;/strong&gt; with simple commands.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Monitor running services&lt;/strong&gt;, including logs and statuses.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Execute one-off commands&lt;/strong&gt; on services for debugging or maintenance.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Docker Compose Workflow
&lt;/h2&gt;

&lt;p&gt;The Docker Compose workflow follows a straightforward sequence:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Build&lt;/strong&gt;: Create images for your services using &lt;code&gt;docker-compose build&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Start Up&lt;/strong&gt;: Launch all services with &lt;code&gt;docker-compose up&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tear Down&lt;/strong&gt;: Stop and remove containers, networks, and volumes using &lt;code&gt;docker-compose down&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Key Commands:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Build images&lt;/span&gt;
docker-compose build

&lt;span class="c"&gt;# Start services&lt;/span&gt;
docker-compose up

&lt;span class="c"&gt;# Stop and clean up&lt;/span&gt;
docker-compose down
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  YAML File Fundamentals
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;docker-compose.yml&lt;/code&gt; file is the backbone of Docker Compose. It uses YAML (Yet Another Markup Language) syntax, which is human-readable and structured.&lt;/p&gt;

&lt;h3&gt;
  
  
  Key Points:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Indentation Matters&lt;/strong&gt;: Use consistent spaces; avoid tabs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Maps&lt;/strong&gt;: Define &lt;code&gt;key: value&lt;/code&gt; pairs for structured data.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Lists&lt;/strong&gt;: Define sequences of items using a &lt;code&gt;-&lt;/code&gt; prefix.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Examples:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Map example&lt;/span&gt;
&lt;span class="na"&gt;person&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;John Doe&lt;/span&gt;
  &lt;span class="na"&gt;address&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;street&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;123 Main Street&lt;/span&gt;
    &lt;span class="na"&gt;city&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Anytown&lt;/span&gt;
    &lt;span class="na"&gt;state&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;CA&lt;/span&gt;

&lt;span class="c1"&gt;# List example&lt;/span&gt;
&lt;span class="na"&gt;pets&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;Fluffy&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;Rover&lt;/span&gt;

&lt;span class="c1"&gt;# List of maps&lt;/span&gt;
&lt;span class="na"&gt;list_of_maps&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;Alice&lt;/span&gt;
    &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;25&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;Bob&lt;/span&gt;
    &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;30&lt;/span&gt;
    &lt;span class="na"&gt;address&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;street&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;456 Oak Avenue&lt;/span&gt;
      &lt;span class="na"&gt;city&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Someville&lt;/span&gt;
      &lt;span class="na"&gt;state&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;NY&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Key Components of a Docker Compose File
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Version
&lt;/h3&gt;

&lt;p&gt;Defines the Docker Compose syntax version. For example:&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;version&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;3.8"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Services
&lt;/h3&gt;

&lt;p&gt;Defines the containers that make up your application. Each service can specify:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Image&lt;/strong&gt;: The Docker image to use.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ports&lt;/strong&gt;: Host-to-container port mappings.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Environment Variables&lt;/strong&gt;: Dynamic configuration.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Volumes&lt;/strong&gt;: Data persistence.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Example:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;services&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;web&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: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="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;80:80"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Volumes
&lt;/h3&gt;

&lt;p&gt;Define named volumes for persistent data or bind mounts for sharing host files.&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;volumes&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;data-volume&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Networks
&lt;/h3&gt;

&lt;p&gt;Define custom networks for service communication.&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;networks&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;custom-network&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Environment Variables
&lt;/h3&gt;

&lt;p&gt;Set dynamic values for services.&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;environment&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;NODE_ENV=production&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Commands
&lt;/h3&gt;

&lt;p&gt;Override the default container commands.&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;command&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;npm start&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Building Images with Docker Compose
&lt;/h2&gt;

&lt;p&gt;Docker Compose simplifies image creation by integrating the build process directly into the &lt;code&gt;docker-compose.yml&lt;/code&gt; file.&lt;/p&gt;

&lt;h3&gt;
  
  
  Build Properties:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Context&lt;/strong&gt;: Path to the directory containing the Dockerfile or a Git repository.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dockerfile&lt;/strong&gt;: Specify an alternative Dockerfile.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Args&lt;/strong&gt;: Pass dynamic build arguments.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tags&lt;/strong&gt;: Define tags for the built image.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Example:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;services&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;webapp&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;build&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;context&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;./dir&lt;/span&gt;
      &lt;span class="na"&gt;dockerfile&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Dockerfile.dev&lt;/span&gt;
      &lt;span class="na"&gt;args&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;GIT_COMMIT&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;cdc3b19&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;custom-image-name:tag&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Advanced Features
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Managing Application Lifecycle
&lt;/h3&gt;

&lt;p&gt;Docker Compose provides robust lifecycle management capabilities:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Start/Stop/Rebuild Services&lt;/strong&gt;: Easily control service states.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;View Running Services&lt;/strong&gt;: Monitor status and logs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Run One-Off Commands&lt;/strong&gt;: Perform maintenance or debugging tasks.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Communication Between Containers
&lt;/h3&gt;

&lt;p&gt;Using Docker Compose, you can orchestrate multiple containers efficiently. Services defined in the same Compose file can communicate seamlessly through custom networks.&lt;/p&gt;

&lt;h4&gt;
  
  
  Example:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;networks&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;app-network&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;driver&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;bridge&lt;/span&gt;

&lt;span class="na"&gt;services&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="na"&gt;image&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;app-image&lt;/span&gt;
    &lt;span class="na"&gt;networks&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;app-network&lt;/span&gt;
  &lt;span class="na"&gt;api&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;api-image&lt;/span&gt;
    &lt;span class="na"&gt;networks&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;app-network&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






</description>
      <category>docker</category>
    </item>
    <item>
      <title>Docker: Day 7 - Docker Bind Mounts</title>
      <dc:creator>Subham Nandi</dc:creator>
      <pubDate>Thu, 09 Jan 2025 05:04:20 +0000</pubDate>
      <link>https://dev.to/subham_nandi/docker-day-7-e4g</link>
      <guid>https://dev.to/subham_nandi/docker-day-7-e4g</guid>
      <description>&lt;h3&gt;
  
  
  What Are Bind Mounts?
&lt;/h3&gt;

&lt;p&gt;A &lt;strong&gt;bind mount&lt;/strong&gt; is a powerful feature of Docker that allows a file or directory on the host machine to be mounted into a container. This enables seamless interaction between the host system and the Docker container. Below are some key characteristics of bind mounts:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Mapping Host Files to Container Files:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Bind mounts allow specific files or directories from the host machine to be mapped to the corresponding files or directories in the container.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Flexible Storage Location:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Unlike Docker volumes, bind mounts can be stored anywhere on the host system.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Direct Modifications:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Both Docker containers and non-Docker processes on the host machine can modify files in the bind mount at any time.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Unsupported in Dockerfile:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Bind mounts cannot be used within a Dockerfile. They are exclusively configured during the &lt;code&gt;docker run&lt;/code&gt; command.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  Good Use Cases for Bind Mounts
&lt;/h3&gt;

&lt;p&gt;Bind mounts are especially useful in the following scenarios:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Sharing Configuration Files:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Share configuration files from the host machine to one or more containers to ensure consistent application behavior.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Development and Testing Environments:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Share source code or build artifacts between a development environment on the Docker host and the container. This allows developers to edit files on the host machine and see changes reflected in real time within the container.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  Starting NGINX with a Bind Mount
&lt;/h3&gt;

&lt;p&gt;To understand bind mounts in action, let’s use a practical example by starting an &lt;strong&gt;NGINX&lt;/strong&gt; container with a bind mount. This will demonstrate how to map a directory from the host system to the container.&lt;/p&gt;

&lt;h4&gt;
  
  
  Steps to Start NGINX with a Bind Mount:
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Run the NGINX Container:&lt;/strong&gt;
Use the following Docker command to start an NGINX container and bind mount the current directory (&lt;code&gt;$(pwd)&lt;/code&gt;) to &lt;code&gt;/app&lt;/code&gt; in the container:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   docker container run &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="nt"&gt;--name&lt;/span&gt; nginx &lt;span class="nt"&gt;--mount&lt;/span&gt; &lt;span class="nb"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;bind&lt;/span&gt;,source&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;pwd&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;,target&lt;span class="o"&gt;=&lt;/span&gt;/app nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;--name nginx&lt;/code&gt;&lt;/strong&gt;: Names the container &lt;code&gt;nginx&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;--mount type=bind&lt;/code&gt;&lt;/strong&gt;: Specifies the type of mount as &lt;code&gt;bind&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;source=$(pwd)&lt;/code&gt;&lt;/strong&gt;: Defines the source directory on the host machine as the current working directory.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;target=/app&lt;/code&gt;&lt;/strong&gt;: Maps the source directory to &lt;code&gt;/app&lt;/code&gt; inside the container.&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Verify the Bind Mount:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use &lt;code&gt;docker inspect&lt;/code&gt; to confirm that the bind mount has been successfully created:
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; docker inspect nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;Check the &lt;code&gt;Mounts&lt;/code&gt; section in the output to ensure the mapping between the host and container directories.&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Interact with the Mounted Directory:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Any changes made to the files in the host directory will immediately reflect inside the container under the &lt;code&gt;/app&lt;/code&gt; directory, and vice versa.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;




</description>
    </item>
    <item>
      <title>Docker: Day 6 - Docker Volumes</title>
      <dc:creator>Subham Nandi</dc:creator>
      <pubDate>Wed, 08 Jan 2025 12:24:08 +0000</pubDate>
      <link>https://dev.to/subham_nandi/docker-day-6-21n7</link>
      <guid>https://dev.to/subham_nandi/docker-day-6-21n7</guid>
      <description>&lt;h2&gt;
  
  
  Docker: Service Containers and Volumes
&lt;/h2&gt;

&lt;p&gt;Docker provides a robust framework for containerized applications, and understanding its volume management system is key for handling data storage effectively. In this article, we will explore how Docker manages volumes and service containers in detail, with practical examples.&lt;/p&gt;

&lt;h3&gt;
  
  
  What Are Docker Volumes?
&lt;/h3&gt;

&lt;p&gt;Volumes in Docker are used to persist data generated and used by Docker containers. Unlike bind mounts, which rely on the host filesystem, volumes are managed directly by Docker, providing a clean abstraction and better integration with the container ecosystem.&lt;/p&gt;

&lt;h4&gt;
  
  
  Key Features of Docker Volumes:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Storage Location&lt;/strong&gt;: Volumes are stored in a part of the host filesystem managed by Docker (e.g., &lt;code&gt;/var/lib/docker/volumes/&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Managed by Docker&lt;/strong&gt;: Containers create and manage volumes, providing a seamless experience.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Resilience&lt;/strong&gt;: Volumes persist even after containers are removed, ensuring data durability.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ease of Use&lt;/strong&gt;: Volumes can be easily created and manipulated using Docker commands.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Working with Volumes
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Creating a Volume
&lt;/h4&gt;

&lt;p&gt;To create a new volume, use the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker volume create &amp;lt;NAME&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For example, to create a volume named &lt;code&gt;mysql-db&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker volume create mysql-db
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Listing Volumes
&lt;/h4&gt;

&lt;p&gt;To list all available volumes, run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker volume &lt;span class="nb"&gt;ls&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command shows all volumes managed by Docker.&lt;/p&gt;

&lt;h4&gt;
  
  
  Inspecting a Volume
&lt;/h4&gt;

&lt;p&gt;To view detailed information about a specific volume, use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker volume inspect &amp;lt;NAME&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker volume inspect mysql-db
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Removing a Volume
&lt;/h4&gt;

&lt;p&gt;To delete a volume, use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker volume &lt;span class="nb"&gt;rm&lt;/span&gt; &amp;lt;NAME&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: Volumes are not removed when the container using them is destroyed. You need to explicitly delete them.&lt;/p&gt;

&lt;h3&gt;
  
  
  Using Volumes with Containers
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Pulling the MySQL Image
&lt;/h4&gt;

&lt;p&gt;First, pull the MySQL Docker image:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker pull mysql
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Running MySQL with Anonymous Volumes
&lt;/h4&gt;

&lt;p&gt;To run a MySQL container with anonymous volumes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker container run &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="nt"&gt;--name&lt;/span&gt; mysql &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="nv"&gt;MYSQL_ALLOW_EMPTY_PASSWORD&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;True mysql
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, &lt;code&gt;-e MYSQL_ALLOW_EMPTY_PASSWORD=True&lt;/code&gt; sets the MySQL container to allow an empty root password.&lt;/p&gt;

&lt;h4&gt;
  
  
  Running MySQL with Named Volumes
&lt;/h4&gt;

&lt;p&gt;To run a MySQL container with a named volume, specify the source and target:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker container run &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="nt"&gt;--name&lt;/span&gt; mysql &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="nv"&gt;MYSQL_ALLOW_EMPTY_PASSWORD&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;True &lt;span class="nt"&gt;--mount&lt;/span&gt; &lt;span class="nb"&gt;source&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;mysql-db,target&lt;span class="o"&gt;=&lt;/span&gt;/var/lib/mysql mysql
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Alternatively, you can use the &lt;code&gt;-v&lt;/code&gt; flag:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker container run &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="nt"&gt;--name&lt;/span&gt; mysql &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="nv"&gt;MYSQL_ALLOW_EMPTY_PASSWORD&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;True &lt;span class="nt"&gt;-v&lt;/span&gt; mysql-db:/var/lib/mysql mysql
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;source=mysql-db&lt;/code&gt; specifies the volume name.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;target=/var/lib/mysql&lt;/code&gt; specifies the directory inside the container where the volume is mounted.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Managing Volumes in Practice
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Creating Volumes&lt;/strong&gt;:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   docker volume create my-data
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command creates a new volume named &lt;code&gt;my-data&lt;/code&gt;.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Running a Container with the Volume&lt;/strong&gt;:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   docker container run &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="nt"&gt;--name&lt;/span&gt; my-app &lt;span class="nt"&gt;-v&lt;/span&gt; my-data:/app/data my-image
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, the &lt;code&gt;my-data&lt;/code&gt; volume is mounted to &lt;code&gt;/app/data&lt;/code&gt; inside the container.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Inspecting the Volume&lt;/strong&gt;:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   docker volume inspect my-data
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Removing the Volume&lt;/strong&gt;:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   docker volume &lt;span class="nb"&gt;rm &lt;/span&gt;my-data
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command deletes the &lt;code&gt;my-data&lt;/code&gt; volume.&lt;/p&gt;

&lt;h3&gt;
  
  
  Advantages of Using Docker Volumes
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Data Persistence&lt;/strong&gt;: Volumes ensure data remains intact even after the container is destroyed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ease of Sharing&lt;/strong&gt;: Multiple containers can share the same volume, making it ideal for collaborative workflows.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Performance&lt;/strong&gt;: Volumes offer better I/O performance compared to bind mounts.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Security&lt;/strong&gt;: Volumes are managed by Docker, providing a layer of abstraction from the host filesystem.&lt;/li&gt;
&lt;/ul&gt;




</description>
      <category>docker</category>
    </item>
    <item>
      <title>Docker: Day 5 - The Persistent Data Problem in Docker</title>
      <dc:creator>Subham Nandi</dc:creator>
      <pubDate>Sat, 04 Jan 2025 10:31:37 +0000</pubDate>
      <link>https://dev.to/subham_nandi/docker-day-5-1c2a</link>
      <guid>https://dev.to/subham_nandi/docker-day-5-1c2a</guid>
      <description>&lt;h3&gt;
  
  
  The Persistent Data Problem in Docker
&lt;/h3&gt;

&lt;p&gt;Containers are designed to be &lt;strong&gt;lightweight and immutable&lt;/strong&gt;, which makes them ideal for deploying applications in a consistent and reproducible manner. This immutability is a cornerstone of containerized systems, offering several benefits but also introducing challenges in handling persistent data. Let’s delve deeper:&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Benefits of Container Immutability&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Consistency Across Environments&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Containers encapsulate an application and its dependencies, ensuring that the application behaves the same way regardless of where it runs (development, testing, or production).&lt;/li&gt;
&lt;li&gt;This eliminates the "it works on my machine" problem, a common issue in traditional application deployment.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Version Control and Transparency&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Containers operate on a principle of re-deployment rather than modification.&lt;/li&gt;
&lt;li&gt;Any change to an application, whether it’s a configuration update or a version upgrade, requires rebuilding the container image and redeploying it.&lt;/li&gt;
&lt;li&gt;This process ensures transparency because every deployed container represents a known state of the application with a defined version and configuration.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Challenges of Container Immutability&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;While immutability brings many advantages, it also presents specific challenges related to &lt;strong&gt;data persistence and accessibility&lt;/strong&gt;:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Volatile Storage&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;By design, containers use a &lt;strong&gt;writable container layer&lt;/strong&gt; for file creation and storage during their lifecycle.&lt;/li&gt;
&lt;li&gt;This writable layer is ephemeral. When the container stops or is deleted, the data stored in the writable layer is lost.&lt;/li&gt;
&lt;li&gt;This makes containers unsuitable for applications that generate or rely on persistent data without additional configurations.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

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

&lt;ul&gt;
&lt;li&gt;A container running a database (e.g., MySQL) may store data inside the container. If the container crashes or is removed, all the stored data is lost unless mechanisms for persistence are in place.&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Data Accessibility&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;Containers are isolated entities. Retrieving or sharing data between containers or with processes outside the container can be challenging.&lt;/li&gt;
&lt;li&gt;In traditional systems, applications write data directly to disk or shared storage. However, in containerized environments, this is not straightforward due to the isolated nature of containers.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

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

&lt;ul&gt;
&lt;li&gt;A container generating logs might need another container (like a logging service) to access those logs. Without proper configuration, accessing those logs becomes cumbersome.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;The Persistent Data Problem&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The volatile nature of container storage and the challenges of accessing data lead to what is referred to as the &lt;strong&gt;persistent data problem&lt;/strong&gt; in containers. This problem can be summarized as follows:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Data Volatility&lt;/strong&gt;: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Data generated during a container’s runtime does not survive beyond the lifecycle of the container. This is problematic for stateful applications, such as databases or applications requiring long-term storage.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Data Isolation&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The container's file system is not inherently designed for shared or persistent data access, making it difficult for external processes or other containers to retrieve or modify the data.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Solutions to the Persistent Data Problem&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;To address these challenges, Docker provides two primary mechanisms for enabling persistent data:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Volumes&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A Docker-managed storage mechanism that is independent of the container's lifecycle.&lt;/li&gt;
&lt;li&gt;Volumes store data on the host machine in a specific location and allow multiple containers to access the data.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Bind Mounts&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A method to link a directory or file on the host machine to a container.&lt;/li&gt;
&lt;li&gt;Unlike volumes, bind mounts rely on the file structure of the host, offering greater control but less isolation.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;




</description>
      <category>devops</category>
    </item>
    <item>
      <title>Docker: Day 4 - Dockerfiles and Instructions</title>
      <dc:creator>Subham Nandi</dc:creator>
      <pubDate>Thu, 02 Jan 2025 06:30:13 +0000</pubDate>
      <link>https://dev.to/subham_nandi/docker-day-4-8om</link>
      <guid>https://dev.to/subham_nandi/docker-day-4-8om</guid>
      <description>&lt;h3&gt;
  
  
  &lt;strong&gt;Dockerfiles and Docker Images&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;A Dockerfile is a text document containing instructions to build Docker images. These images consist of read-only layers, each layer corresponding to a Dockerfile instruction. Docker can automatically create images by interpreting these instructions. The following command is used to build an image from a Dockerfile:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker build -f &amp;lt;dockerfile_path&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;Dockerfile Instructions&lt;/strong&gt;
&lt;/h3&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;1. FROM&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;FROM&lt;/code&gt; instruction initializes a new build stage and sets the base image for subsequent instructions. A valid Dockerfile must begin with a &lt;code&gt;FROM&lt;/code&gt; instruction. The base image can be any valid image.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FROM &amp;lt;Image_name&amp;gt;:&amp;lt;Image_tag&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;strong&gt;2. LABEL&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;LABEL&lt;/code&gt; instruction adds metadata to an image, helping to organize images by project or record licensing information. Each label is defined as a key-value pair.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;LABEL com.example.version="0.0.1-beta"
LABEL vendor1="ACME Incorporated"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;strong&gt;3. RUN&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;RUN&lt;/code&gt; instruction executes commands in a new layer on top of the current image and commits the results. The resulting image serves as the base for the next step.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FROM ubuntu:14.04
RUN apt-get update
RUN apt-get install -y curl
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;strong&gt;4. CMD&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;CMD&lt;/code&gt; instruction specifies the default command to run in the container. Only one &lt;code&gt;CMD&lt;/code&gt; instruction is allowed per Dockerfile; the last &lt;code&gt;CMD&lt;/code&gt; overrides any previous ones.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CMD ["executable", "param1", "param2"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;strong&gt;5. EXPOSE&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;EXPOSE&lt;/code&gt; instruction specifies the ports on which the container listens for connections.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;EXPOSE &amp;lt;port&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;strong&gt;6. ENV&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;ENV&lt;/code&gt; instruction sets environment variables for the container. It can also update the &lt;code&gt;PATH&lt;/code&gt; variable to make software easier to run.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ENV PATH /usr/local/nginx/bin:$PATH
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;strong&gt;7. ADD&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;ADD&lt;/code&gt; instruction copies files, directories, or remote URLs from the source to the specified destination within the image.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ADD hom* /mydir/  # Adds all files starting with “hom”
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;strong&gt;8. VOLUME&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;VOLUME&lt;/code&gt; instruction designates storage areas, such as database files or configuration storage, that should be persisted outside the container.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;9. WORKDIR&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;WORKDIR&lt;/code&gt; instruction sets the working directory for subsequent &lt;code&gt;RUN&lt;/code&gt;, &lt;code&gt;CMD&lt;/code&gt;, and &lt;code&gt;ADD&lt;/code&gt; instructions.&lt;/p&gt;




</description>
      <category>docker</category>
    </item>
    <item>
      <title>Docker: Day 3 - Docker Container Images</title>
      <dc:creator>Subham Nandi</dc:creator>
      <pubDate>Sun, 29 Dec 2024 17:48:06 +0000</pubDate>
      <link>https://dev.to/subham_nandi/docker-day-3-5cia</link>
      <guid>https://dev.to/subham_nandi/docker-day-3-5cia</guid>
      <description>&lt;h1&gt;
  
  
  Docker Container Images
&lt;/h1&gt;

&lt;p&gt;Docker container images are at the core of containerization technology, enabling efficient and scalable application deployment. This guide explores the essential concepts, commands, and best practices for managing Docker images and leveraging Docker Hub as a central repository.&lt;/p&gt;

&lt;h2&gt;
  
  
  Docker Hub: The Central Repository
&lt;/h2&gt;

&lt;p&gt;Docker Hub is Docker’s native registry for storing both public and private repositories. It serves as a crucial resource for managing and sharing Docker images.&lt;/p&gt;

&lt;h3&gt;
  
  
  Key Features of Docker Hub
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Public and Private Repositories&lt;/strong&gt;: Users can store both public and private images.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Integration with Docker Cloud&lt;/strong&gt;: Once images are pushed to Docker Hub, they become available in Docker Cloud.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Official Images&lt;/strong&gt;: Maintained by Docker, these images are reliable and widely used.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;User Images&lt;/strong&gt;: Custom images created and shared by the Docker community.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Accessing Docker Hub
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Account Creation&lt;/strong&gt;: Create an account on &lt;a href="https://hub.docker.com" rel="noopener noreferrer"&gt;Docker Hub&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Login Command&lt;/strong&gt;:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   docker login
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Pushing an Image&lt;/strong&gt;:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   docker image push USER/Image-name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Understanding Docker Tags
&lt;/h2&gt;

&lt;p&gt;Docker tags are identifiers that convey important details about an image's version or variant.&lt;/p&gt;

&lt;h3&gt;
  
  
  Characteristics of Docker Tags
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Assigned During Image Build&lt;/strong&gt;: Tags are specified during the image-building process.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Explicit Tagging&lt;/strong&gt;:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Default Tag&lt;/strong&gt;: If no tag is specified, Docker assigns the &lt;code&gt;latest&lt;/code&gt; tag by default.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Managing Docker Images
&lt;/h2&gt;

&lt;p&gt;Docker images are the building blocks of containers, consisting of a series of layers combined using union file systems.&lt;/p&gt;

&lt;h3&gt;
  
  
  Types of Docker Images
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Base Images&lt;/strong&gt;: No parent image; usually an OS like Ubuntu, BusyBox, or Debian.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Child Images&lt;/strong&gt;: Build upon base images, adding functionality.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Official Images&lt;/strong&gt;: Maintained and supported by Docker, often one-word names.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;User Images&lt;/strong&gt;: Created by users, formatted as &lt;code&gt;user/image-name&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Image Layers
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Docker uses union file systems to merge image layers.&lt;/li&gt;
&lt;li&gt;View layers and their details:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  docker history &amp;lt;image_name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Workflow: Building and Deploying Docker Images
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Build Docker Images
&lt;/h3&gt;

&lt;p&gt;Creating custom images involves defining instructions in a Dockerfile and building the image using:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; docker build -t IMAGE_NAME[:TAG] .
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Deploy Docker Images
&lt;/h3&gt;

&lt;p&gt;Deploy images to any environment using container orchestration tools like Kubernetes or Docker Swarm.&lt;/p&gt;

&lt;h3&gt;
  
  
  Push and Pull Images
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Push to Docker Hub&lt;/strong&gt;:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  docker push IMAGE_NAME[:TAG]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Pull from Docker Hub&lt;/strong&gt;:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  docker pull IMAGE_NAME[:TAG]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Exploring Docker Hub
&lt;/h2&gt;

&lt;p&gt;Docker Hub’s official site provides a repository for discovering, managing, and downloading images.&lt;/p&gt;

&lt;h3&gt;
  
  
  Steps to Use Docker Hub
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Browse Official Images&lt;/strong&gt;: High-quality images maintained by Docker.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Search for Images&lt;/strong&gt;: Use keywords to find specific images.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Download Images&lt;/strong&gt;:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   docker pull IMAGE_NAME[:TAG]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Explore Tags&lt;/strong&gt;: Choose specific versions or variants of an image.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Image Differentiation and Management
&lt;/h2&gt;

&lt;p&gt;Docker images are versatile, enabling both base and extended functionalities:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Base Images&lt;/strong&gt;: Provide foundational operating systems.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Child Images&lt;/strong&gt;: Enhance base images with application-specific tools.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Version Control&lt;/strong&gt;: Use tags to manage multiple versions of an image.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>docker</category>
    </item>
    <item>
      <title>Docker: Day 2 - Docker Networking</title>
      <dc:creator>Subham Nandi</dc:creator>
      <pubDate>Fri, 27 Dec 2024 12:05:21 +0000</pubDate>
      <link>https://dev.to/subham_nandi/docker-day-2-5fio</link>
      <guid>https://dev.to/subham_nandi/docker-day-2-5fio</guid>
      <description>&lt;h4&gt;
  
  
  Docker Networking: Connecting Containers and the Host Machine
&lt;/h4&gt;

&lt;p&gt;Docker provides a variety of networking features to ensure that containers can communicate with one another and with the host machine. Containers and services do not need to be aware of where they are deployed, which makes them portable and scalable.&lt;/p&gt;

&lt;h5&gt;
  
  
  Docker Network
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Bridge Network&lt;/strong&gt;: By default, Docker uses the bridge network for container communication. This virtual private network isolates containers within the same cluster but prevents communication between containers in different clusters unless additional configurations are applied.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Overlay Network&lt;/strong&gt;: This allows communication between containers across different Docker hosts. Technologies like VXLAN or IPSec are often used to create virtual networks that span multiple hosts.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Container Network Interfaces (CNI)&lt;/strong&gt;: CNI is a specification that defines how container runtimes interact with networking plugins. This allows you to combine different container runtimes with various networking solutions for greater flexibility.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Connecting Containers to Networks
&lt;/h4&gt;

&lt;p&gt;When you start a container, Docker automatically connects it to the default bridge network. However, you can create custom networks for specific purposes.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Example&lt;/strong&gt;: For a MySQL and PHP application, you can create a network called &lt;code&gt;sql_php_nwt&lt;/code&gt; and for MongoDB and PHP, a network called &lt;code&gt;mongo_nwt&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This ensures that the containers within each network can communicate with each other efficiently and securely.&lt;/p&gt;

&lt;h4&gt;
  
  
  Docker Commands for Networking and Communication
&lt;/h4&gt;

&lt;p&gt;Here are some essential Docker commands for managing and inspecting Docker networks and containers:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Start a container with port mapping&lt;/strong&gt;:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   docker container run &lt;span class="nt"&gt;-p&lt;/span&gt; &amp;lt;host_port&amp;gt;:&amp;lt;docker_port&amp;gt; &lt;span class="nt"&gt;-d&lt;/span&gt; &amp;lt;image&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command allows you to expose a port from the Docker container to the host machine, making the container's service accessible externally.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Inspect container ports&lt;/strong&gt;:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   docker port &amp;lt;container_id&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use this command to find the ports and protocols associated with a container.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Find the IP address of a container&lt;/strong&gt;:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   docker inspect &amp;lt;container_id&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command retrieves detailed information about a container, including its IP address.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Show all Docker networks&lt;/strong&gt;:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   docker network &lt;span class="nb"&gt;ls&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command lists all the networks available on the Docker host.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Filter networks by type&lt;/strong&gt;:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   docker network &lt;span class="nt"&gt;-f&lt;/span&gt; &lt;span class="nv"&gt;driver&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;bridge
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command filters and lists networks with the &lt;code&gt;bridge&lt;/code&gt; driver.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;List network IDs and drivers&lt;/strong&gt;:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   docker network &lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;--format&lt;/span&gt; &lt;span class="s2"&gt;"{{.ID}}: {{.Driver}}"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use this command to display the network ID and driver type for all available networks.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Inspect a specific Docker network&lt;/strong&gt;:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   docker network inspect &amp;lt;network_name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command provides detailed information about a particular network, including the containers connected to it.&lt;/p&gt;

&lt;h4&gt;
  
  
  DNS in Docker Containers
&lt;/h4&gt;

&lt;p&gt;Docker containers use DNS to communicate with each other, rather than relying on IP addresses. DNS makes it possible for containers to use easy-to-remember hostnames instead of complex IP addresses, simplifying container communication.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Docker automatically provides DNS functionality for containers by allowing containers to communicate with each other using the container name or the service name (if using Docker Compose).&lt;/li&gt;
&lt;li&gt;Containers in the same network can resolve each other’s names using Docker's built-in DNS service.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>docker</category>
    </item>
    <item>
      <title>Docker: Day 1 - Introduction</title>
      <dc:creator>Subham Nandi</dc:creator>
      <pubDate>Tue, 24 Dec 2024 05:49:03 +0000</pubDate>
      <link>https://dev.to/subham_nandi/docker-day-1-38a7</link>
      <guid>https://dev.to/subham_nandi/docker-day-1-38a7</guid>
      <description>&lt;h1&gt;
  
  
  Docker: Service Containers
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Why Are Containers Required?
&lt;/h2&gt;

&lt;p&gt;Containers are essential for modern application deployment and management because they provide:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Efficiency&lt;/strong&gt;: Containers consume fewer resources compared to virtual machines.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Consistency&lt;/strong&gt;: Ensures that applications behave the same way across different environments.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Portability&lt;/strong&gt;: Simplifies application migration between development, testing, and production environments.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scalability&lt;/strong&gt;: Enables easy scaling of applications to meet demand.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  What Is a Container Image?
&lt;/h2&gt;

&lt;p&gt;A &lt;strong&gt;container image&lt;/strong&gt; is a lightweight, standalone package that includes everything needed to run an application:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Code&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Runtime&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;System Tools&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Libraries&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Key Points:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A &lt;strong&gt;container&lt;/strong&gt; is a running instance of a container image.&lt;/li&gt;
&lt;li&gt;You can run multiple containers from the same image, enabling horizontal scaling and environment replication.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Docker Central Repository: Docker Hub
&lt;/h2&gt;

&lt;p&gt;Docker Hub is a central repository where container images are stored. Developers can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Download pre-built images.&lt;/li&gt;
&lt;li&gt;Publish custom images.&lt;/li&gt;
&lt;li&gt;Manage private and public container images.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Starting an Nginx Web Server in Docker
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Start Nginx Web Server:
&lt;/h3&gt;

&lt;p&gt;To run an open-source Nginx web server:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker container run &lt;span class="nt"&gt;--publish&lt;/span&gt; &amp;lt;host_port:container_port&amp;gt; &amp;lt;image_name&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;docker container run &lt;span class="nt"&gt;--publish&lt;/span&gt; 8080:80 nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Stop Container Foreground Process:
&lt;/h3&gt;

&lt;p&gt;Use the keyboard shortcut:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Ctrl + C
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Start Container in Background (Detach Mode):
&lt;/h3&gt;

&lt;p&gt;Run the container in the background:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker container run &lt;span class="nt"&gt;--publish&lt;/span&gt; &amp;lt;host_port:container_port&amp;gt; &lt;span class="nt"&gt;--detach&lt;/span&gt; &amp;lt;image_name&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;docker container run &lt;span class="nt"&gt;--publish&lt;/span&gt; 8080:80 &lt;span class="nt"&gt;--detach&lt;/span&gt; nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Listing and Managing Containers
&lt;/h2&gt;

&lt;h3&gt;
  
  
  List Running Containers:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Modern command:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;  docker container &lt;span class="nb"&gt;ls&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Old way:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;  docker ps
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  List All Containers (Running and Stopped):
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker container &lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-a&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Stop a Running Container:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker container stop &amp;lt;container_id&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Difference Between &lt;code&gt;run&lt;/code&gt; and &lt;code&gt;start&lt;/code&gt; Commands
&lt;/h2&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;run&lt;/code&gt;:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Always starts a &lt;strong&gt;new container&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;start&lt;/code&gt;:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Starts an &lt;strong&gt;existing container&lt;/strong&gt; that has been stopped.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Naming Containers
&lt;/h2&gt;

&lt;p&gt;Assigning a specific name to a container:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker container run &lt;span class="nt"&gt;--publish&lt;/span&gt; 80:80 &lt;span class="nt"&gt;--detach&lt;/span&gt; &lt;span class="nt"&gt;--name&lt;/span&gt; &amp;lt;name&amp;gt; &amp;lt;image_name&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;docker container run &lt;span class="nt"&gt;--publish&lt;/span&gt; 80:80 &lt;span class="nt"&gt;--detach&lt;/span&gt; &lt;span class="nt"&gt;--name&lt;/span&gt; my-nginx nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Viewing Logs and Processes in Containers
&lt;/h2&gt;

&lt;h3&gt;
  
  
  View Logs of a Specific Container:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker container logs &amp;lt;container_name&amp;gt;/&amp;lt;container_id&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  View Running Processes Inside a Container:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker container top &amp;lt;container_id&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Removing Unused Containers
&lt;/h2&gt;

&lt;p&gt;Remove unused containers by specifying their IDs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker container &lt;span class="nb"&gt;rm&lt;/span&gt; &amp;lt;space_separated_container_ids&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Containers vs. Virtual Machines
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;strong&gt;Feature&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Containers&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Virtual Machines (VMs)&lt;/strong&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Virtualization Layer&lt;/td&gt;
&lt;td&gt;Operating System (OS)&lt;/td&gt;
&lt;td&gt;Hardware&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Resource Allocation&lt;/td&gt;
&lt;td&gt;Lightweight and portable&lt;/td&gt;
&lt;td&gt;Resource-intensive&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Portability&lt;/td&gt;
&lt;td&gt;Highly portable&lt;/td&gt;
&lt;td&gt;Limited portability&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Key Takeaway:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Containers virtualize the &lt;strong&gt;OS&lt;/strong&gt;, while VMs virtualize the &lt;strong&gt;hardware&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Containers are ideal for modern, scalable applications.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Resource Management and Monitoring
&lt;/h2&gt;

&lt;h3&gt;
  
  
  View Resource Consumption of Containers:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker stats &lt;span class="o"&gt;[&lt;/span&gt;container_name or container_id]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Get Detailed Information About a Container:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker inspect &lt;span class="o"&gt;[&lt;/span&gt;container_name or container_id]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Interactive Containers
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Start a Container in Interactive Mode:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker run &lt;span class="nt"&gt;-it&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;image_name or image_id] &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;command&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Options:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;-i&lt;/code&gt;: Keeps STDIN open even if not attached.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-t&lt;/code&gt;: Allocates a pseudo-terminal (TTY).&lt;/li&gt;
&lt;/ul&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;docker run &lt;span class="nt"&gt;-it&lt;/span&gt; ubuntu bash
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Running Commands in Running Containers
&lt;/h2&gt;

&lt;p&gt;Execute commands inside a running container:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker &lt;span class="nb"&gt;exec&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;options] &lt;span class="o"&gt;[&lt;/span&gt;container_name or container_id] &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;command&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Parameters:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;[options]&lt;/code&gt;: Additional options (e.g., &lt;code&gt;-it&lt;/code&gt; for interactive mode).&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;[container_name or container_id]&lt;/code&gt;: The name or ID of the running container.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;[command]&lt;/code&gt;: The command to execute inside the container.&lt;/li&gt;
&lt;/ul&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;docker &lt;span class="nb"&gt;exec&lt;/span&gt; &lt;span class="nt"&gt;-it&lt;/span&gt; my-nginx bash
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






</description>
      <category>docker</category>
    </item>
    <item>
      <title>HashiCorp Packer</title>
      <dc:creator>Subham Nandi</dc:creator>
      <pubDate>Sun, 17 Nov 2024 11:32:04 +0000</pubDate>
      <link>https://dev.to/subham_nandi/hashicorp-packer-3h61</link>
      <guid>https://dev.to/subham_nandi/hashicorp-packer-3h61</guid>
      <description>&lt;p&gt;HashiCorp &lt;strong&gt;Packer&lt;/strong&gt; is an open-source tool that automates the creation of machine images for multiple platforms using a single source configuration. Packer ensures these images are portable, reproducible, and version-controlled, enabling seamless deployments across different environments. This not only improves efficiency but also ensures reliability in infrastructure management.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;Key Features of Packer&lt;/strong&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Automation&lt;/strong&gt;: Automates the process of building images, eliminating manual tasks.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Platform Independence&lt;/strong&gt;: Supports multiple platforms, including cloud providers (AWS, Azure, GCP), virtualization platforms (VMware, VirtualBox), and containerization systems (Docker).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Consistency&lt;/strong&gt;: Ensures uniformity across environments by generating identical images.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Flexibility&lt;/strong&gt;: Uses a declarative approach to define configurations and enables customization with variables, provisioners, and post-processors.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;Core Components of Packer&lt;/strong&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;1. Template&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;A &lt;strong&gt;Packer Template&lt;/strong&gt; is the starting point for creating images. It defines the desired configuration and settings, including builders, provisioners, and post-processors. Templates are written in JSON or HashiCorp Configuration Language (HCL).&lt;/p&gt;

&lt;h4&gt;
  
  
  Example:
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;HCL Template&lt;/strong&gt; for building an Ubuntu image:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="nx"&gt;source&lt;/span&gt; &lt;span class="s2"&gt;"amazon-ebs"&lt;/span&gt; &lt;span class="s2"&gt;"example"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;ami_name&lt;/span&gt;      &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"ubuntu-example-image-{{timestamp}}"&lt;/span&gt;
  &lt;span class="nx"&gt;instance_type&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"t2.micro"&lt;/span&gt;
  &lt;span class="nx"&gt;region&lt;/span&gt;        &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"us-west-2"&lt;/span&gt;
  &lt;span class="nx"&gt;source_ami&lt;/span&gt;    &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"ami-12345678"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;build&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;sources&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"source.amazon-ebs.example"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

  &lt;span class="nx"&gt;provisioner&lt;/span&gt; &lt;span class="s2"&gt;"shell"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;inline&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"sudo apt-get update -y"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"sudo apt-get install -y nginx"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;2. Variables&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Variables make templates reusable and customizable. There are two types of variables:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;User Variables&lt;/strong&gt;: Defined within the Packer template.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Environment Variables&lt;/strong&gt;: Passed from the operating system.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Example of Variables in HCL:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="nx"&gt;variable&lt;/span&gt; &lt;span class="s2"&gt;"aws_region"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;default&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"us-west-2"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;source&lt;/span&gt; &lt;span class="s2"&gt;"amazon-ebs"&lt;/span&gt; &lt;span class="s2"&gt;"example"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;ami_name&lt;/span&gt;      &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"ubuntu-example-image-{{timestamp}}"&lt;/span&gt;
  &lt;span class="nx"&gt;instance_type&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"t2.micro"&lt;/span&gt;
  &lt;span class="nx"&gt;region&lt;/span&gt;        &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;aws_region&lt;/span&gt;
  &lt;span class="nx"&gt;source_ami&lt;/span&gt;    &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"ami-12345678"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Values for variables can be passed:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Via command line&lt;/strong&gt;: &lt;code&gt;packer build -var 'aws_region=us-east-1' template.pkr.hcl&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Via a file&lt;/strong&gt;: &lt;code&gt;packer build -var-file=variables.pkrvars.hcl template.pkr.hcl&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;3. Builders&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Builders&lt;/strong&gt; are core components of Packer responsible for creating machine images. Each builder corresponds to a specific platform or infrastructure provider.&lt;/p&gt;

&lt;h4&gt;
  
  
  Example: Amazon EBS Builder
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="nx"&gt;source&lt;/span&gt; &lt;span class="s2"&gt;"amazon-ebs"&lt;/span&gt; &lt;span class="s2"&gt;"example"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;ami_name&lt;/span&gt;      &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"ubuntu-example-image-{{timestamp}}"&lt;/span&gt;
  &lt;span class="nx"&gt;instance_type&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"t2.micro"&lt;/span&gt;
  &lt;span class="nx"&gt;region&lt;/span&gt;        &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"us-west-2"&lt;/span&gt;
  &lt;span class="nx"&gt;source_ami&lt;/span&gt;    &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"ami-12345678"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Supported builders include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Cloud providers: AWS, Azure, Google Cloud.&lt;/li&gt;
&lt;li&gt;Virtualization platforms: VMware, VirtualBox.&lt;/li&gt;
&lt;li&gt;Containers: Docker.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;4. Provisioners&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Provisioners are used to configure the machine during the image-building process. They allow you to execute scripts, copy files, or use configuration management tools (e.g., Ansible, Chef, Puppet).&lt;/p&gt;

&lt;h4&gt;
  
  
  Example: Shell Provisioner
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="nx"&gt;provisioner&lt;/span&gt; &lt;span class="s2"&gt;"shell"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;inline&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="s2"&gt;"sudo apt-get update -y"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s2"&gt;"sudo apt-get install -y nginx"&lt;/span&gt;
  &lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Other supported provisioners:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;File provisioner to transfer files.&lt;/li&gt;
&lt;li&gt;Ansible provisioner for playbooks.&lt;/li&gt;
&lt;li&gt;Chef and Puppet provisioners for configuration management.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;5. Post-Processors&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Post-processors are optional steps that modify or handle artifacts after a build is complete. They can compress images, upload them to cloud storage, or convert them into different formats.&lt;/p&gt;

&lt;h4&gt;
  
  
  Example: Compressing an Image
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="nx"&gt;post-processor&lt;/span&gt; &lt;span class="s2"&gt;"compress"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;output&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"ubuntu-example-image.tar.gz"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  &lt;strong&gt;6. Communicators&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Communicators enable interaction with the instance during the build process. They allow scripts to be executed, files to be transferred, and logs to be fetched.&lt;/p&gt;

&lt;p&gt;Common communicators:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;SSH&lt;/strong&gt;: For Linux-based systems.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;WinRM&lt;/strong&gt;: For Windows-based systems.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Example: SSH Communicator
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="nx"&gt;source&lt;/span&gt; &lt;span class="s2"&gt;"amazon-ebs"&lt;/span&gt; &lt;span class="s2"&gt;"example"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;ssh_username&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"ubuntu"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  &lt;strong&gt;Packer Workflow&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Here’s how Packer works:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Define Template&lt;/strong&gt;: Specify the source, builders, provisioners, and post-processors.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Validate&lt;/strong&gt;: Use &lt;code&gt;packer validate&lt;/code&gt; to ensure the template is error-free.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Build&lt;/strong&gt;: Execute &lt;code&gt;packer build&lt;/code&gt; to start the image creation process.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Output&lt;/strong&gt;: Get the final machine or container image.&lt;/li&gt;
&lt;/ol&gt;




</description>
    </item>
    <item>
      <title>End-to-End Observability Project</title>
      <dc:creator>Subham Nandi</dc:creator>
      <pubDate>Tue, 05 Nov 2024 15:15:56 +0000</pubDate>
      <link>https://dev.to/subham_nandi/end-to-end-observability-project-1ffd</link>
      <guid>https://dev.to/subham_nandi/end-to-end-observability-project-1ffd</guid>
      <description>&lt;h2&gt;
  
  
  What is the Demo Application?
&lt;/h2&gt;

&lt;p&gt;The demo application we’ll be using was developed by top observability companies like Datadog, Dynatrace, Microsoft, Alibaba, and Grafana Labs. This open-source project contains various microservices written in different languages, each one using OpenTelemetry to emit metrics, logs, and traces. This setup is perfect for learning observability because:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It simulates a realistic, multi-service architecture typical in production applications.&lt;/li&gt;
&lt;li&gt;Each microservice supports OpenTelemetry, allowing you to learn how telemetry data is instrumented and collected.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Key Features of the Application
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Multi-microservice Architecture&lt;/strong&gt;: Similar to an e-commerce system, with services like Cart, Currency, Payment, Notification, Email, Recommendation, and Shipping.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Polyglot Setup&lt;/strong&gt;: Each service is written in a different language, such as Python, Go, and Java, enabling you to learn how OpenTelemetry works across multiple languages.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Documentation and Flexibility&lt;/strong&gt;: The application comes with instructions for deploying on Docker and Kubernetes, using Helm charts, and setting up on Kind or EKS clusters.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Understanding OpenTelemetry and Its Role
&lt;/h2&gt;

&lt;p&gt;Observability involves collecting, processing, and analyzing telemetry data (logs, metrics, and traces) from applications. OpenTelemetry, a CNCF project, standardizes this data collection process and is designed to work with any observability tool (like Datadog, Grafana, or Jaeger). It provides SDKs and APIs for developers to instrument telemetry data in a tool-agnostic manner.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why Use OpenTelemetry?
&lt;/h3&gt;

&lt;p&gt;In modern DevOps, switching from one observability tool to another is common. Without OpenTelemetry, applications hardcode SDKs for specific tools (e.g., Prometheus or Nagios), making switching tools cumbersome and expensive. With OpenTelemetry:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Developers instrument their code using a standard API.&lt;/li&gt;
&lt;li&gt;A configuration file determines which observability tool the data will be exported to, making it easy to change backends without modifying application code.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Components of OpenTelemetry
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Receiver&lt;/strong&gt;: Collects metrics, logs, and traces from applications.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Processor&lt;/strong&gt;: Processes telemetry data as needed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Exporter&lt;/strong&gt;: Exports telemetry data to the specified backend (e.g., Prometheus, Jaeger).&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  Reviewing the Application’s Telemetry Instrumentation
&lt;/h2&gt;

&lt;p&gt;In this application:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Each microservice emits metrics, logs, and traces using OpenTelemetry SDKs.&lt;/li&gt;
&lt;li&gt;For instance, the &lt;strong&gt;Recommendation&lt;/strong&gt; service, written in Python, uses OpenTelemetry SDK to define and export traces and metrics.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can explore the codebase to see how different OpenTelemetry SDKs are used for each microservice. This will help you understand how telemetry data is implemented and structured within an application.&lt;/p&gt;




&lt;p&gt;the observability backend (e.g., Prometheus for metrics, Jaeger for traces).&lt;/p&gt;

&lt;p&gt;In this application, these configurations are defined in an &lt;strong&gt;exporter configuration file&lt;/strong&gt;, where you specify your telemetry backend (Prometheus, Jaeger, etc.).&lt;/p&gt;




&lt;h3&gt;
  
  
  Step 1: Set Up an EKS Cluster
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Prerequisites&lt;/strong&gt;: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Ensure you have &lt;code&gt;eksctl&lt;/code&gt; installed. You can check by running &lt;code&gt;eksctl version&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;You’ll also need AWS CLI and &lt;code&gt;kubectl&lt;/code&gt; installed and configured.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Create an EKS Cluster&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Open a terminal and use the following commands to set up your EKS cluster:
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; eksctl create cluster &lt;span class="nt"&gt;--name&lt;/span&gt; observability-demo &lt;span class="nt"&gt;--region&lt;/span&gt; &amp;lt;your-region&amp;gt; &lt;span class="nt"&gt;--nodegroup-name&lt;/span&gt; standard-workers &lt;span class="nt"&gt;--node-type&lt;/span&gt; t3.medium &lt;span class="nt"&gt;--nodes&lt;/span&gt; 3 &lt;span class="nt"&gt;--nodes-min&lt;/span&gt; 1 &lt;span class="nt"&gt;--nodes-max&lt;/span&gt; 4 &lt;span class="nt"&gt;--managed&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Configure IAM for EKS&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Attach the IAM OIDC provider to your EKS cluster, which is required for OpenTelemetry setup:
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; eksctl utils associate-iam-oidc-provider &lt;span class="nt"&gt;--region&lt;/span&gt; &amp;lt;your-region&amp;gt; &lt;span class="nt"&gt;--cluster&lt;/span&gt; observability-demo &lt;span class="nt"&gt;--approve&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Step 2: Deploy the Demo Application with OpenTelemetry on Kubernetes
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Clone the Demo Application&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Clone the GitHub repository that contains the OpenTelemetry demo application. This project will allow us to learn observability through a microservice-based setup.
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; git clone https://github.com/open-telemetry/opentelemetry-demo.git
 &lt;span class="nb"&gt;cd &lt;/span&gt;opentelemetry-demo
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Install Helm&lt;/strong&gt; (if not installed):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Install Helm, which is used for managing Kubernetes applications.
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Add Helm Chart for the Demo Application&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The demo application has a Helm chart for easy deployment. Add the Helm repo:
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; helm repo add open-telemetry https://open-telemetry.github.io/opentelemetry-helm-charts
 helm repo update
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Deploy the Demo Application&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Deploy the application to your EKS cluster:
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; helm &lt;span class="nb"&gt;install &lt;/span&gt;otel-demo open-telemetry/opentelemetry-demo
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Verify Deployment&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;After deployment, check if all pods are running. This demo has multiple microservices, so expect to see several pods.
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; kubectl get pods
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Step 3: Expose the Demo Application
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Port Forwarding for Accessing the Application&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;For local testing, port forward the front-end service of the demo application:
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; kubectl port-forward svc/frontend 8080:8080
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;Access the application at &lt;code&gt;http://localhost:8080&lt;/code&gt;. Add some products to the cart to generate traffic.&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Alternative for Cloud-Based Access&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If you are using a cloud instance, you can port forward like this:
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; kubectl port-forward svc/frontend 8080:8080 &lt;span class="nt"&gt;--address&lt;/span&gt; 0.0.0.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;Use your cloud instance’s public IP to access the application.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Step 4: Setting Up OpenTelemetry Components
&lt;/h3&gt;

&lt;p&gt;OpenTelemetry uses a receiver, processor, and exporter to handle telemetry data. Let’s configure these to collect metrics, traces, and logs.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Install OpenTelemetry Collector&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Deploy the OpenTelemetry collector, which will process and export telemetry data.
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; kubectl apply &lt;span class="nt"&gt;-f&lt;/span&gt; https://raw.githubusercontent.com/open-telemetry/opentelemetry-operator/main/config/crd/bases/opentelemetry.io_opentelemetrycollectors.yaml
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Configure the OpenTelemetry Collector&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Define a configuration file that will export traces and metrics to Jaeger and Prometheus.&lt;/li&gt;
&lt;li&gt;Create an &lt;code&gt;otel-collector.yaml&lt;/code&gt; file:
&lt;/li&gt;
&lt;/ul&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;opentelemetry.io/v1alpha1&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;OpenTelemetryCollector&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;otel-collector&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;config&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;|&lt;/span&gt;
     &lt;span class="s"&gt;receivers:&lt;/span&gt;
       &lt;span class="s"&gt;otlp:&lt;/span&gt;
         &lt;span class="s"&gt;protocols:&lt;/span&gt;
           &lt;span class="s"&gt;grpc:&lt;/span&gt;
           &lt;span class="s"&gt;http:&lt;/span&gt;
     &lt;span class="s"&gt;exporters:&lt;/span&gt;
       &lt;span class="s"&gt;prometheus:&lt;/span&gt;
       &lt;span class="s"&gt;jaeger:&lt;/span&gt;
         &lt;span class="s"&gt;endpoint: "http://jaeger:14250"&lt;/span&gt;
     &lt;span class="s"&gt;service:&lt;/span&gt;
       &lt;span class="s"&gt;pipelines:&lt;/span&gt;
         &lt;span class="s"&gt;metrics:&lt;/span&gt;
           &lt;span class="s"&gt;receivers: [otlp]&lt;/span&gt;
           &lt;span class="s"&gt;exporters: [prometheus]&lt;/span&gt;
         &lt;span class="s"&gt;traces:&lt;/span&gt;
           &lt;span class="s"&gt;receivers: [otlp]&lt;/span&gt;
           &lt;span class="s"&gt;exporters: [jaeger]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Deploy this configuration:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; kubectl apply &lt;span class="nt"&gt;-f&lt;/span&gt; otel-collector.yaml
&lt;/code&gt;&lt;/pre&gt;

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

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Install Jaeger and Prometheus&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use Helm to install Jaeger and Prometheus.
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; helm &lt;span class="nb"&gt;install &lt;/span&gt;jaeger open-telemetry/jaeger &lt;span class="nt"&gt;--namespace&lt;/span&gt; observability
 helm &lt;span class="nb"&gt;install &lt;/span&gt;prometheus prometheus-community/prometheus &lt;span class="nt"&gt;--namespace&lt;/span&gt; observability
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Set Up Grafana for Visualization&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Install Grafana, which will visualize the metrics data.
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; helm &lt;span class="nb"&gt;install &lt;/span&gt;grafana grafana/grafana &lt;span class="nt"&gt;--namespace&lt;/span&gt; observability
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Step 5: Access Observability Tools
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Access Jaeger&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Forward Jaeger’s UI port and open it in your browser to view traces.
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; kubectl port-forward svc/jaeger-query 16686:16686 &lt;span class="nt"&gt;-n&lt;/span&gt; observability
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;Visit &lt;code&gt;http://localhost:16686&lt;/code&gt; and search for traces generated by the demo application.&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Access Prometheus&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Forward Prometheus’s UI port to view metrics.
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; kubectl port-forward svc/prometheus-server 9090:80 &lt;span class="nt"&gt;-n&lt;/span&gt; observability
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;Access Prometheus at &lt;code&gt;http://localhost:9090&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Access Grafana&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Forward Grafana’s UI port and set up dashboards for visualizing metrics and traces.
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; kubectl port-forward svc/grafana 3000:3000 &lt;span class="nt"&gt;-n&lt;/span&gt; observability
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;Access Grafana at &lt;code&gt;http://localhost:3000&lt;/code&gt;. The default login is &lt;code&gt;admin/admin&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;In Grafana, add Prometheus as a data source and create dashboards for visualizing application metrics.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Step 6: Observing Telemetry Data
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Simulate Traffic&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;To generate more telemetry data, interact with the demo application by adding products to the cart, removing items, and checking out.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Monitor Metrics in Grafana&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use Grafana’s Prometheus dashboards to view metrics like CPU usage, memory, and request rates.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Trace Requests with Jaeger&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use Jaeger to trace the requests across microservices. Look for spans related to services like &lt;code&gt;checkout&lt;/code&gt; or &lt;code&gt;recommendation&lt;/code&gt;, and check the time spent in each service.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Step 7: Customize and Extend Observability
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Add Additional Metrics or Traces&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Edit the source code of a microservice (e.g., the recommendation service in Python) to add custom metrics or trace points using OpenTelemetry SDKs.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Deploy the Updated Code&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Rebuild and redeploy the application to observe your new metrics or trace points in action.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Configure Alerts&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Set up alerts in Prometheus or Grafana to notify you if certain metrics exceed thresholds (e.g., high latency or CPU usage).&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;




</description>
    </item>
    <item>
      <title>Day 6 - Distributed Tracing with Jaeger</title>
      <dc:creator>Subham Nandi</dc:creator>
      <pubDate>Sat, 02 Nov 2024 07:33:22 +0000</pubDate>
      <link>https://dev.to/subham_nandi/day-6-distributed-tracing-with-jaeger-5dh4</link>
      <guid>https://dev.to/subham_nandi/day-6-distributed-tracing-with-jaeger-5dh4</guid>
      <description>&lt;h3&gt;
  
  
  Distributed Tracing
&lt;/h3&gt;

&lt;p&gt;When requests flow through a system composed of many microservices, tracing helps observe how each component contributes to the overall processing time of that request. Distributed tracing works by tracking the path and timing of a request across various services, allowing developers to pinpoint where delays or errors might be happening.&lt;/p&gt;

&lt;h4&gt;
  
  
  Why Tracing is Important in Microservices
&lt;/h4&gt;

&lt;p&gt;In a monolithic application, debugging and performance optimization are relatively straightforward since everything is in one place. But in a microservices environment, a single user request may pass through multiple services—each service potentially running on a different server, written in a different language, and managed by a different team. Distributed tracing offers the following benefits:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Pinpointing Latency&lt;/strong&gt;: When a request takes longer than expected, tracing can show which services or stages in the process are responsible for the delay.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Understanding Dependencies&lt;/strong&gt;: Tracing maps the dependencies between services, providing visibility into how they interact.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Error Tracking&lt;/strong&gt;: By capturing each step in a request’s journey, tracing can reveal where errors or failures occur and what dependencies may have contributed.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  How Tracing Works
&lt;/h4&gt;

&lt;p&gt;To set up tracing, two primary steps are necessary: &lt;strong&gt;instrumenting code&lt;/strong&gt; and &lt;strong&gt;deploying tracing infrastructure&lt;/strong&gt;.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Instrumentation&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Instrumentation&lt;/strong&gt; is the process of adding code that captures trace data (such as latency and request flow) within the application. This code generates "spans" and assigns them unique IDs to trace requests as they flow between different services.&lt;/li&gt;
&lt;li&gt;Spans are essential units in tracing; they represent individual operations within a request. For example, a request passing through three services will have three spans, each corresponding to a service.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;OpenTelemetry&lt;/strong&gt; is a popular, vendor-neutral standard for implementing tracing. It supports various programming languages and integrates well with different tracing backends.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Tracing Infrastructure&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Jaeger&lt;/strong&gt; is an open-source tool often used to collect, store, and visualize trace data.&lt;/li&gt;
&lt;li&gt;The infrastructure for Jaeger typically involves:

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Agent&lt;/strong&gt;: Deployed with the application to collect traces. The agent receives trace data from the application and forwards it to the collector.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Collector&lt;/strong&gt;: Aggregates traces from multiple agents and processes them.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Storage Backend&lt;/strong&gt;: Stores the processed traces. Jaeger supports different storage backends, such as Elasticsearch or Cassandra, for high performance.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;User Interface (UI)&lt;/strong&gt;: Allows users to query, visualize, and analyze traces.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  An Example Scenario: Implementing Tracing in a Microservices Application
&lt;/h3&gt;

&lt;p&gt;Let’s say you have an e-commerce application built using a microservices architecture, where each major function (login, payment, catalog, etc.) is a separate service. Consider the following request flow:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Login Service&lt;/strong&gt; authenticates a user.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Catalog Service&lt;/strong&gt; fetches items for the user.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Payment Service&lt;/strong&gt; processes the payment.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In this flow, tracing would capture each service's performance and highlight any delays. For instance, if users are experiencing delays in the checkout process, tracing can help you determine if the delay is happening in the payment service, the catalog service, or in the network between these services.&lt;/p&gt;

&lt;h3&gt;
  
  
  Jaeger: Architecture and Setup
&lt;/h3&gt;

&lt;p&gt;Jaeger’s architecture is designed to handle and manage traces efficiently in a scalable environment. Here’s a breakdown of its components:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Agent&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The Jaeger agent is typically deployed as a daemon on the same host as the application.&lt;/li&gt;
&lt;li&gt;It listens for spans emitted by the application’s instrumented code and forwards them to the collector.&lt;/li&gt;
&lt;li&gt;By placing the agent close to the application, Jaeger reduces network latency for sending trace data.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Collector&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The collector receives traces from the agents and processes them.&lt;/li&gt;
&lt;li&gt;It aggregates, filters, and prepares the trace data for storage in a database.&lt;/li&gt;
&lt;li&gt;Collectors can handle high volumes of traces, which is useful in large distributed systems with numerous microservices.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Storage Backend&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Jaeger relies on external storage for long-term data retention and query support.&lt;/li&gt;
&lt;li&gt;Elasticsearch is commonly used as it allows for fast retrieval of trace data, though other options like Cassandra and Apache Kafka are also supported.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;User Interface (UI)&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Jaeger’s UI allows users to view traces, understand request paths, and identify performance bottlenecks.&lt;/li&gt;
&lt;li&gt;Through the UI, users can visualize how requests flow through the system, view latency at each step, and spot any anomalies.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Implementing Tracing: Example with OpenTelemetry and Jaeger
&lt;/h3&gt;

&lt;p&gt;Suppose you have a Node.js application with two services: &lt;code&gt;Service A&lt;/code&gt; and &lt;code&gt;Service B&lt;/code&gt;. Here’s how you’d implement tracing:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Instrument the Application&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In &lt;code&gt;Service A&lt;/code&gt; and &lt;code&gt;Service B&lt;/code&gt;, you would install OpenTelemetry’s SDK.&lt;/li&gt;
&lt;li&gt;Use OpenTelemetry’s APIs to capture spans. For example:
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;trace&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@opentelemetry/api&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
 &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;tracer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;trace&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getTracer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;service-a&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

 &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;processRequest&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;span&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;tracer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;startSpan&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;process-request&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
   &lt;span class="c1"&gt;// Perform operations&lt;/span&gt;
   &lt;span class="nx"&gt;span&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;end&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
 &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Deploy Jaeger on Kubernetes&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You could deploy Jaeger using Helm, a popular Kubernetes package manager, which simplifies installation.&lt;/li&gt;
&lt;li&gt;Example Helm command:
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; helm &lt;span class="nb"&gt;install &lt;/span&gt;jaeger jaegertracing/jaeger
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;Configure your services to send trace data to the Jaeger agent deployed in the Kubernetes cluster.&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Set Up the Storage Backend&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Configure Jaeger to use Elasticsearch for storing traces. This can be specified in the configuration settings.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;View and Analyze Traces&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Access Jaeger’s UI to analyze traces. You can view each request’s journey through &lt;code&gt;Service A&lt;/code&gt; and &lt;code&gt;Service B&lt;/code&gt; and observe latency at each step.&lt;/li&gt;
&lt;li&gt;If &lt;code&gt;Service B&lt;/code&gt; takes longer than expected, you can investigate further by looking at detailed trace data.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Benefits of Distributed Tracing in Observability
&lt;/h3&gt;

&lt;p&gt;Distributed tracing is invaluable in modern observability as it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Reveals Dependencies&lt;/strong&gt;: Shows how services interact and depend on each other.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Improves User Experience&lt;/strong&gt;: Reduces response times by identifying bottlenecks and optimizing performance.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Facilitates Root Cause Analysis&lt;/strong&gt;: Enables teams to pinpoint where failures occur in complex distributed systems.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Here's a detailed, step-by-step walkthrough of the demo based on the transcript provided. This demo covers setting up observability with Elasticsearch and Jaeger on a Kubernetes (EKS) cluster and integrating the Jaeger tracing tool to visualize application traces.&lt;/p&gt;




&lt;h3&gt;
  
  
  Step-by-Step Demo for Setting up Jaeger Tracing with Elasticsearch on EKS
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Prerequisites
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Kubernetes Cluster&lt;/strong&gt;: Ensure you have a Kubernetes cluster set up on Amazon EKS.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;kubectl and eksctl&lt;/strong&gt;: Tools for interacting with your EKS cluster.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;IAM Role and OIDC&lt;/strong&gt;: Ensure that your EKS cluster has OIDC integration enabled for IAM role-based access to EKS.&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  Part 1: Verify Kubernetes Cluster and Node Configuration
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Check Kubernetes Nodes&lt;/strong&gt;:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   kubectl get nodes
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;This command verifies that the EKS cluster and nodes are properly configured and accessible.&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Access EKS Cluster ReadMe&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;If needed, follow instructions from the Day2 README file to set up an EKS cluster, including adding node groups.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  Part 2: Setup Elasticsearch for Log Storage
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Create a Service Account for EBS Access&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a service account to allow Elasticsearch in EKS to access an EBS volume:
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; eksctl create iamserviceaccount &lt;span class="se"&gt;\&lt;/span&gt;
   &lt;span class="nt"&gt;--name&lt;/span&gt; elasticsearch-sa &lt;span class="se"&gt;\&lt;/span&gt;
   &lt;span class="nt"&gt;--namespace&lt;/span&gt; logging &lt;span class="se"&gt;\&lt;/span&gt;
   &lt;span class="nt"&gt;--cluster&lt;/span&gt; &amp;lt;your-cluster-name&amp;gt; &lt;span class="se"&gt;\&lt;/span&gt;
   &lt;span class="nt"&gt;--attach-policy-arn&lt;/span&gt; arn:aws:iam::aws:policy/AmazonEBSCSIDriverPolicy &lt;span class="se"&gt;\&lt;/span&gt;
   &lt;span class="nt"&gt;--approve&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;This setup includes an IAM role that allows EKS to interact with EBS for storage.&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Install EBS CSI Driver&lt;/strong&gt;:
&lt;/li&gt;
&lt;/ol&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;-k&lt;/span&gt; &lt;span class="s2"&gt;"github.com/kubernetes-sigs/aws-ebs-csi-driver/deploy/kubernetes/overlays/stable/ecr/?ref=master"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;This driver enables EKS to use EBS volumes as persistent storage.&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Create a Namespace for Logging&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Separate resources for easier management and debugging:
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; kubectl create namespace logging
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Install Elasticsearch via Helm&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use Helm to install Elasticsearch in the &lt;code&gt;logging&lt;/code&gt; namespace:
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; helm repo add elastic https://helm.elastic.co
 helm &lt;span class="nb"&gt;install &lt;/span&gt;elasticsearch elastic/elasticsearch &lt;span class="nt"&gt;-n&lt;/span&gt; logging
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;Note down the generated username and password, as they will be used later when configuring Jaeger.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Part 3: Set Up Jaeger for Tracing
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Create Namespace for Tracing&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Isolate Jaeger components in a separate namespace:
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; kubectl create namespace tracing
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Configure Elasticsearch Certificate&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Extract and save the Elasticsearch certificate to ensure secure communication between Jaeger and Elasticsearch.&lt;/li&gt;
&lt;li&gt;Create a ConfigMap in Kubernetes to store the certificate:
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; kubectl create configmap elasticsearch-cacert &lt;span class="nt"&gt;--from-file&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;ca.crt&lt;span class="o"&gt;=&lt;/span&gt;&amp;lt;path-to-certificate&amp;gt; &lt;span class="nt"&gt;-n&lt;/span&gt; tracing
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Store Elasticsearch Credentials in Kubernetes Secret&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Store Elasticsearch credentials as a Kubernetes secret:
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; kubectl create secret generic elasticsearch-credentials &lt;span class="se"&gt;\&lt;/span&gt;
   &lt;span class="nt"&gt;--from-literal&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;username&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&amp;lt;your-username&amp;gt; &lt;span class="se"&gt;\&lt;/span&gt;
   &lt;span class="nt"&gt;--from-literal&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;password&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&amp;lt;your-password&amp;gt; &lt;span class="se"&gt;\&lt;/span&gt;
   &lt;span class="nt"&gt;-n&lt;/span&gt; tracing
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Install Jaeger via Helm&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use Helm to install Jaeger in the &lt;code&gt;tracing&lt;/code&gt; namespace:
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; helm repo add jaegertracing https://jaegertracing.github.io/helm-charts
 helm &lt;span class="nb"&gt;install &lt;/span&gt;jaeger jaegertracing/jaeger &lt;span class="nt"&gt;-n&lt;/span&gt; tracing
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;Before installation, update the &lt;code&gt;values.yaml&lt;/code&gt; file with the Elasticsearch credentials:

&lt;ul&gt;
&lt;li&gt;Set the storage username, password, and Elasticsearch URL.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Troubleshoot Jaeger Installation&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If the Jaeger pod is in a crash loop, check for configuration issues, particularly with the liveness and readiness probes. Describe the pod to identify possible issues:
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; kubectl describe pod &amp;lt;jaeger-pod-name&amp;gt; &lt;span class="nt"&gt;-n&lt;/span&gt; tracing
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;If issues are found, double-check the ConfigMap, Secret, and &lt;code&gt;values.yaml&lt;/code&gt; configurations for errors or missing values.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Part 4: Access Jaeger User Interface
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Port Forward Jaeger UI&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Forward the Jaeger UI port to access it locally:
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; kubectl port-forward svc/jaeger-query 16686:16686 &lt;span class="nt"&gt;-n&lt;/span&gt; tracing
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;If accessing from an EC2 instance, add &lt;code&gt;--address 0.0.0.0&lt;/code&gt; to the port forward command:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; kubectl port-forward svc/jaeger-query 16686:16686 &lt;span class="nt"&gt;-n&lt;/span&gt; tracing &lt;span class="nt"&gt;--address&lt;/span&gt; 0.0.0.0
&lt;/code&gt;&lt;/pre&gt;

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

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Load Jaeger UI in Browser&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;Open &lt;code&gt;http://localhost:16686&lt;/code&gt; in your browser to access Jaeger’s user interface.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  Part 5: Deploy a Sample Application with Tracing
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Deploy Instrumented Applications&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Download and deploy a sample application (Service A and Service B) instrumented with OpenTelemetry:
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; kubectl apply &lt;span class="nt"&gt;-k&lt;/span&gt; &amp;lt;path-to-manifest&amp;gt;/day4
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Verify that the applications have been deployed:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; kubectl get pods &lt;span class="nt"&gt;-n&lt;/span&gt; &amp;lt;namespace&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

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

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Trigger Application Endpoints&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Test application endpoints to generate traces that can be viewed in Jaeger:
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; curl http://&amp;lt;load-balancer-url&amp;gt;/healthy
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;Other endpoints (like &lt;code&gt;/serviceB&lt;/code&gt; or &lt;code&gt;/serverError&lt;/code&gt;) can be used to generate different traces.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Part 6: View Traces in Jaeger
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Locate Traces in Jaeger UI&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Go to the Jaeger UI, select the application service (e.g., Service A), and click “Find Traces.”&lt;/li&gt;
&lt;li&gt;Examine traces and spans, which represent points in the journey of each request.&lt;/li&gt;
&lt;li&gt;Each span shows specific operation details, including duration, which can be used to identify performance bottlenecks.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Analyze Trace Details&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Click on individual spans to view deeper information, such as:

&lt;ul&gt;
&lt;li&gt;Start and end times&lt;/li&gt;
&lt;li&gt;Time taken by each operation&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Use this data to identify any latency issues, allowing you to pinpoint and optimize inefficient code or configuration.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  Additional Tips for Optimization
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Adjust Probes&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If liveness or readiness probes are causing issues, adjust the timeouts or parameters in the Helm &lt;code&gt;values.yaml&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Namespace Organization&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Separate namespaces for logging, monitoring, and tracing make it easier to troubleshoot and manage access controls (RBAC).&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Load Balancer and Security&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Consider exposing Jaeger via a Kubernetes Ingress or LoadBalancer with appropriate security settings for production environments.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;




</description>
    </item>
  </channel>
</rss>
