<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Koilraj on Medium]]></title>
        <description><![CDATA[Stories by Koilraj on Medium]]></description>
        <link>https://medium.com/@koilrajjee?source=rss-09744215c59c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*fyyfy3QhFyGW3m8QC_lPzQ.jpeg</url>
            <title>Stories by Koilraj on Medium</title>
            <link>https://medium.com/@koilrajjee?source=rss-09744215c59c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 06:10:50 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@koilrajjee/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Setting Up Amazon EKS Cluster Using Terraform]]></title>
            <link>https://blog.devops.dev/setting-up-amazon-eks-cluster-using-terraform-11c11072d414?source=rss-09744215c59c------2</link>
            <guid isPermaLink="false">https://medium.com/p/11c11072d414</guid>
            <category><![CDATA[tfstate]]></category>
            <category><![CDATA[elastickubernetesservice]]></category>
            <category><![CDATA[infrastructure-as-code]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Koilraj]]></dc:creator>
            <pubDate>Mon, 02 Dec 2024 16:11:33 GMT</pubDate>
            <atom:updated>2024-12-02T18:42:54.551Z</atom:updated>
            <content:encoded><![CDATA[<p>Managing Kubernetes clusters can be challenging, particularly when using tools like kOps or Kubeadm, which require a lot of administrative work. Amazon Elastic Kubernetes Service (EKS) simplifies this process by automating the creation and maintenance of clusters, so we can focus on deploying applications instead. This guide will walk you through provisioning an EKS cluster with Terraform.</p><blockquote><strong>Why Use Amazon EKS?</strong></blockquote><ol><li><strong>Ease of Management:</strong> EKS eliminates the need for system administration by handling control plane updates and cluster health.</li><li><strong>Scalability:</strong> Adjust the cluster’s capacity effortlessly to match your workload.</li><li><strong>Integration: </strong>Use the Kubernetes kubeconfig file to manage your cluster, just as with any Kubernetes setup.</li><li><strong>Cost Considerations:</strong> EKS pricing includes control plane and worker node charges.</li></ol><blockquote><strong>Prerequisites:</strong></blockquote><ol><li><strong>Install Terraform</strong></li></ol><p>Refer: <a href="https://developer.hashicorp.com/terraform/tutorials/aws-get-started/install-cli">Install Terraform | Terraform | HashiCorp Developer</a></p><p>2. <strong>Install AWS CLI</strong></p><p>Refer: <a href="https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html">Installing or updating to the latest version of the AWS CLI — AWS Command Line Interface</a></p><p>3. <strong>Create IAM with AdministratorAccess and configure it on local system using AWS CLI.</strong></p><p>Refer: <a href="https://docs.aws.amazon.com/cli/latest/userguide/cli-authentication-user.html">Authenticating using IAM user credentials for the AWS CLI — AWS Command Line Interface</a></p><p>4. <strong>Create a s3 bucket to store terraform tfstate file — to keep track of the infrastructure.</strong></p><p>Using an <strong>S3 bucket</strong> to store the <strong>tfstate</strong> file offers benefits like centralized access, versioning, state locking, and high durability, making it the ideal choice for managing and tracking infrastructure state in Terraform.</p><blockquote><strong>Setting Up EKS with Terraform</strong></blockquote><ol><li><strong>Clone the repository below.</strong></li></ol><p>The repository has ready-to-use IaC for deploying EKS on AWS</p><p><a href="https://github.com/Koil-raj/terraform-eks.git">GitHub - Koil-raj/terraform-eks: Provisioning terraform using EKS</a></p><p>2. <strong>Update the newly created s3 bucket name under “terraform.tf”</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/834/1*jgH4_EuGKdrFpPpdnyxV4g.png" /></figure><p>3. <strong>Run “terraform init”</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1020/1*_AkMVx-B3yd_Ga95Hy7WaQ.png" /></figure><ul><li>This initializes the Terraform working directory. This command downloads necessary provider plugins, modules, and sets up the backend s3 bucket (where terraform state is stored).</li></ul><p>4. <strong>Run “terraform validate” and “terraform fmt”</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/923/1*9fp1QRbFoAe7o1qgMdMGMw.png" /></figure><ul><li><strong>terraform validate: </strong>Validates the syntax and structure Terraform configuration files. This step ensures that the code is syntactically correct and internally consistent.</li><li><strong>terraform fmt: </strong>Automatically formats the Terraform configuration files to ensure consistent and readable code style.</li></ul><p>5. <strong>Run “terraform plan”</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UraAemqLZylu8BpcdaIJAQ.png" /></figure><ul><li><strong>terraform plan: </strong>Creates an execution plan, which shows Terraform’s proposed changes to your infrastructure based on the current configuration and state.</li><li>It compares your Terraform configuration (.tf files) with the current state of your infrastructure (saved in the state file). It checks what resources are managed by Terraform and which need to be created, updated, or destroyed.</li></ul><p>6. <strong>Run “terraform apply”</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6ucG5Wx7lhCW-25qVnQC4A.png" /></figure><ul><li>This command actually applies the changes described in the execution plan to create, modify, or destroy resources in your cloud provider or infrastructure.</li><li>This will take 5–10 mins to provision the EKS cluster and node groups.</li><li>In our case once the execution is complete, it will share the output with VPC endpoint, EKS cluster name and region where the EKS has been created.</li></ul><blockquote><strong>Validation</strong></blockquote><ol><li>EKS cluster (control plane) created</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Nx9B-5bL6VVMYqh4X5BJNw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Idi6_uBKv_59z30qD_sijQ.png" /></figure><p>2. Two node groups with the mentioned AMI settings have been created. Where <strong>nodegroup-1 creates 2 EC2 instance</strong> and <strong>nodegroup-2 creates 1 desired node</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KuAb38KHEJB_dCQK8IQQQQ.png" /></figure><p>3.<strong> </strong>As mentioned under VPC.tf file, 3 private and 3 public subnets created</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sRO0WG3cBMZsGU4zakLFGw.png" /></figure><blockquote><strong>Accessing EKS cluster from local machine</strong></blockquote><p>To configure the EKS cluster context under our local machine, we can run below command</p><pre>$ aws eks update-kubeconfig --region us-east-1 --name eks-cluster<br>Added new context arn:aws:eks:us-east-1:975050343338:cluster/eks-cluster to C:\Users\hp\.kube\config</pre><ul><li>This command will update the kubeconfig file to include the EKS cluster details</li></ul><p><strong>Note: </strong>Make sure, u change the cluster name and region according to your settings.</p><p>-Checking nodes, pods and default services created under the EKS</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/873/1*FzHI0kMzOTeC5zQJ8lZ-7g.png" /></figure><blockquote><strong>cleaning up</strong></blockquote><p>We can effortlessly remove this EKS cluster by running the simple command: <strong>terraform destroy</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MitxEHeFmY790f477xaXzg.png" /></figure><ul><li>This might take time another 5–10 minutes to remove EKS cluster and VPC</li></ul><blockquote><strong>Explanation: overview of the IaC code used to create the EKS cluster</strong></blockquote><ol><li><strong>vpc.tf (VPC creation):</strong></li></ol><pre>module &quot;vpc&quot; {<br>  source = &quot;terraform-aws-modules/vpc/aws&quot;<br>  version = &quot;3.14.2&quot;<br><br>  name = &quot;eks-cluster&quot;<br><br>  cidr = &quot;172.20.0.0/16&quot;<br>  azs = slice(data.aws_availability_zones.available.names, 0, 3)<br><br>  private_subnets = [&quot;172.20.1.0/24&quot;, &quot;172.20.2.0/24&quot;, &quot;172.20.3.0/24&quot;]<br>  public_subnets = [&quot;172.20.4.0/24&quot;, &quot;172.20.5.0/24&quot;, &quot;172.20.6.0/24&quot;]<br><br>  enable_nat_gateway = true<br>  single_nat_gateway = true<br>  enable_dns_hostnames = true<br><br>  public_subnet_tags = {<br>    &quot;kubernetes.io/cluster/${local.cluster_name}&quot; = &quot;shared&quot;<br>    &quot;kubernetes.io/role/elb&quot; = 1<br>  }<br><br>  private_subnet_tags = {<br>    &quot;kubernetes.io/cluster/${local.cluster_name}&quot; = &quot;shared&quot;<br>    &quot;kubernetes.io/role/internal-elb&quot; = 1<br>  }<br>}</pre><p>This Terraform code creates a <strong>Virtual Private Cloud (VPC)</strong> named <strong>“eks-cluster”</strong> in AWS using a module from the Terraform AWS Modules library. The module <strong>terraform-aws-modules/vpc/aws</strong> simplifies the VPC creation process by providing pre-configured and reusable infrastructure components.</p><ul><li>The CIDR block for the VPC is <strong>172.20.0.0/16</strong>, which means the VPC will have IP address space from <strong>172.20.0.0</strong> to <strong>172.20.255.255</strong>.</li><li>The <strong>azs</strong> variable is used to select the <strong>Availability Zones (AZs)</strong> where the <strong>subnets</strong> will be created. It uses the slice function to select the first three AZs from the list of available AZs fetched by the data.aws_availability_zones data source.</li><li><strong>private_subnets:</strong> This defines three private subnets within the VPC. Each subnet has a /24 CIDR block, providing 256 IP addresses per subnet.</li><li><strong>public_subnets:</strong> This defines three public subnets within the VPC. Each subnet also has a /24 CIDR block.</li></ul><p>2. <strong>eks-cluster.tf (EKS creation):</strong></p><pre>module &quot;eks&quot; {<br>  source = &quot;terraform-aws-modules/eks/aws&quot;<br>  version = &quot;19.0.4&quot;<br><br>  cluster_name = local.cluster_name<br>  cluster_version = &quot;1.27&quot;<br><br>  vpc_id = module.vpc.vpc_id<br>  subnet_ids = module.vpc.private_subnets<br>  cluster_endpoint_public_access = true<br><br>  eks_managed_node_group_defaults = {<br>    ami_type = &quot;AL2_x86_64&quot;<br><br>  }<br><br>  eks_managed_node_groups = {<br>    one = {<br>      name = &quot;node-group-1&quot;<br><br>      instance_types = [&quot;t3.small&quot;]<br><br>      min_size = 1<br>      max_size = 3<br>      desired_size = 2<br>    }<br><br>    two = {<br>      name = &quot;node-group-2&quot;<br><br>      instance_types = [&quot;t3.small&quot;]<br><br>      min_size = 1<br>      max_size = 2<br>      desired_size = 1<br>    }<br>  }<br>}</pre><p>This Terraform code is used to create an <strong>Amazon EKS (Elastic Kubernetes Service)</strong> cluster along with <strong>managed node groups</strong>. The module <strong>terraform-aws-modules/eks/aws </strong>simplifies the deployment of EKS clusters and their associated resources.</p><ul><li><strong>cluster_name = local.cluster_name</strong>: This sets the name of the EKS cluster. The value is dynamically fetched from the local.cluster_name variable (which should be defined elsewhere in your configuration)</li><li><strong>vpc_id = module.vpc.vpc_id</strong>: This associates the EKS cluster with a VPC (Virtual Private Cloud).</li><li><strong>subnet_ids = module.vpc.private_subnets</strong>: The EKS cluster will use private subnets within the VPC. The private_subnets are being fetched from the vpc module, ensuring the cluster is deployed in private subnets for security</li><li><strong>cluster_endpoint_public_access = true</strong>: This setting enables <strong>public access to the EKS cluster(control plane) endpoint</strong>. When set to true, the EKS control plane will be accessible from the internet.</li><li><strong>eks_managed_node_group_defaults</strong>: This block sets default settings like AMI type for all <strong>EKS managed node groups</strong>(worker nodes).</li><li><strong>eks_managed_node_groups:</strong> This section defines two <strong>EKS managed node groups</strong> with different configurations. Managed node groups allow EKS to manage the lifecycle of worker nodes (EC2 instances) in the cluster.</li></ul><p>3. <strong>terraform.tf </strong>(<strong>Defining dependencies):</strong></p><pre>terraform {<br>  required_providers {<br>    aws = {<br>      source = &quot;hashicorp/aws&quot;<br>      version = &quot;~&gt; 4.46.0&quot;<br>    }<br><br>    random = {<br>      source = &quot;hashicorp/random&quot;<br>      version = &quot;~&gt; 3.4.3&quot;<br>    }<br><br>    tls = {<br>      source = &quot;hashicorp/tls&quot;<br>      version = &quot;~&gt; 4.0.4&quot;<br>    }<br><br>    cloudinit = {<br>      source = &quot;hashicorp/cloudinit&quot;<br>      version = &quot;~&gt; 2.2.0&quot;<br>    }<br><br>    kubernetes = {<br>      source = &quot;hashicorp/kubernetes&quot;<br>      version = &quot;~&gt; 2.16.1&quot;<br>    }<br>  }<br><br>  backend &quot;s3&quot; {<br>    bucket         	   = &quot;eks-terraform1&quot;<br>    key              	   = &quot;state/terraform.tfstate&quot;<br>    region         	   = &quot;us-east-1&quot;<br>  }<br><br>  required_version = &quot;~&gt; 1.3&quot;<br>}</pre><ul><li><strong>terraform {}</strong>: This block is used to configure global settings related to Terraform and its providers, including the required providers and the backend configuration. It also specifies the version of Terraform itself.</li><li><strong>required_providers {}</strong>: This section specifies which providers Terraform should use for the infrastructure configuration, along with their versions. The providers are plugins that allow Terraform to interact with different services (like AWS, Kubernetes, etc.).</li><li><strong>backend “s3”</strong>: This block defines how Terraform’s state file will be managed. The state file tracks the current state of the infrastructure managed by Terraform. (S3bucket name — eks-terraform1)</li></ul><p>4. <strong>variables.tf </strong>(D<strong>efining AWS region and cluster name variables):</strong></p><pre>variable &quot;region&quot; {<br>  description = &quot;AWS region&quot;<br> type = string<br> default = &quot;us-east-1&quot;<br>}<br><br>variable &quot;clusterName&quot; {<br>  description = &quot;Name of the EKS cluster&quot;<br> type = string<br> default = &quot;eks-cluster&quot;<br>}</pre><p>This terraform code defines two <strong>variables</strong> which will be used in output.tf and main.tf terraform file.</p><ul><li><strong>variable “region”</strong>: This defines a variable called region. The variable is used to store a value, which will be used to specify AWS region.</li><li><strong>variable “clusterName”</strong>: This defines a variable called <strong>clusterName</strong>. The purpose of this variable is to store the name of the EKS (Elastic Kubernetes Service) cluster.</li></ul><p>5. <strong>main.tf</strong> (<strong>Defining Kubernetes and AWS provider for managing the EKS cluster):</strong></p><pre>provider &quot;kubernetes&quot; {<br>  host = module.eks.cluster_endpoint<br>  cluster_ca_certificate = base64decode(module.eks.cluster_certificate_authority_data)<br>}<br><br>provider &quot;aws&quot; {<br>  region = var.region<br>}<br><br>data &quot;aws_availability_zones&quot; &quot;available&quot; {}<br><br>locals {<br>  cluster_name = var.clusterName<br>}</pre><ul><li><strong>provider “kubernetes”{} </strong>: This defines the Kubernetes provider, which is used to interact with a Kubernetes cluster. This block configures the Kubernetes provider to interact with an EKS cluster by using the <strong>cluster endpoint</strong> and <strong>CA certificate</strong> from the eks module.</li><li><strong>host = module.eks.cluster_endpoint</strong>: This specifies the API server endpoint URL for the Kubernetes cluster. The value module.eks.cluster_endpoint is referring to the cluster_endpoint output from the eks module</li><li><strong>provider “aws”{}</strong>: This block configures the AWS provider to interact with resources in the AWS region specified by the region variable.</li></ul><p><strong>6. outputs.tf</strong> (<strong>Defining terraform output variables):</strong></p><pre>output &quot;cluster_name&quot; {<br>  description = &quot;Amazon Web Service EKS Cluster Name&quot;<br>  value = module.eks.cluster_name<br>}<br><br>output &quot;cluster_endpoint&quot; {<br>  description = &quot;Endpoint for Amazon Web Service EKS &quot;<br>  value = module.eks.cluster_endpoint<br>}<br><br>output &quot;region&quot; {<br>  description = &quot;Amazon Web Service EKS Cluster region&quot;<br>  value = var.region<br>}<br><br>output &quot;cluster_security_group_id&quot; {<br>  description = &quot;Security group ID for the Amazon Web Service EKS Cluster &quot;<br>  value = module.eks.cluster_security_group_id<br>}</pre><p>The above terraform code defines “output values” which are used to display specific information after Terraform has successfully applied the configuration. These outputs provide useful data related to the Amazon Web Services (AWS) Elastic Kubernetes Service (EKS) cluster.</p><ul><li>The <strong>cluster_name</strong> output will show the name of the EKS cluster when Terraform finishes applying the configuration.</li><li>The <strong>cluster_endpoint</strong> output will display the API endpoint URL for the Kubernetes cluster after Terraform completes the apply process.</li><li>The <strong>region</strong> output will display the AWS region where the EKS cluster is deployed, based on the value of the <strong>region variable</strong>.</li><li>The <strong>cluster_security_group_id</strong> output will display the ID of the security group that is attached to the EKS cluster, which can be used for network access control or troubleshooting.</li><li>These outputs provide key information that can be used after the Terraform deployment to access and manage the EKS cluster.</li></ul><blockquote><strong>Conclusion</strong></blockquote><p>When compared to creating an EKS cluster manually using the AWS Console, Terraform makes the process simpler for a number of reasons. Your infrastructure may be defined as code using Terraform, which makes it easy to distribute, repeatable, and version-controlled. By doing this, the possibility of human mistake that comes with manual steps is eliminated, guaranteeing consistency across contexts.</p><p>Additionally, Terraform’s declarative nature allows you to easily update your configuration files to make changes to the infrastructure, while manual terminal updates might be more laborious and prone to errors. To further improve scalability and save time and effort, Terraform makes it possible to automate every step of the deployment process, including network settings, node configurations, and security policies. In the end, Terraform offers a simplified, effective, and dependable method of managing infrastructure at scale when used to create EKS clusters.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=11c11072d414" width="1" height="1" alt=""><hr><p><a href="https://blog.devops.dev/setting-up-amazon-eks-cluster-using-terraform-11c11072d414">Setting Up Amazon EKS Cluster Using Terraform</a> was originally published in <a href="https://blog.devops.dev/">DevOps.dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploying a Multi-Tier Web Application on a Kubernetes Cluster with Kops]]></title>
            <link>https://blog.devops.dev/deploying-a-multi-tier-web-application-on-a-kubernetes-cluster-with-kops-0ee43c50198f?source=rss-09744215c59c------2</link>
            <guid isPermaLink="false">https://medium.com/p/0ee43c50198f</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[kops]]></category>
            <dc:creator><![CDATA[Koilraj]]></dc:creator>
            <pubDate>Thu, 21 Nov 2024 08:13:12 GMT</pubDate>
            <atom:updated>2024-11-22T14:48:12.737Z</atom:updated>
            <content:encoded><![CDATA[<blockquote><strong>Welcome to this exciting project!</strong></blockquote><p>Deploying programs to various environments can be a difficult undertaking in the software development industry. By bridging the gap between development and operations teams, DevOps approaches facilitate smooth cooperation and effective product delivery. In this DevOps Project, we will demonstrate the implementation of DevOps principles.</p><p>In this DevOps Project, we’ll deploy a multi-tier web application stack consisting of five services: Nginx, Apache Tomcat, RabbitMQ, Memcached, and MySQL on a Kubernetes cluster, leveraging its powerful orchestration capabilities for production environments. Let’s dive in and understand the context and approach.</p><blockquote><strong>Understanding the Situation</strong></blockquote><p>We have a multi-tier web application stack that is already containerized. For this project, we will use the <strong>vProfile web application</strong>, which is already containerized. The application has been tested and is production ready. Now, it’s time to host it in a way that ensures reliability and scalability.</p><blockquote><strong>Challenges of Running Containers for Production</strong></blockquote><p>Running containers in production introduces additional requirements:</p><ul><li><strong>High Availability</strong>: Containers and compute nodes must remain operational to avoid downtime.</li><li><strong>Fault Tolerance</strong>: If containers fail, they should auto-heal to maintain system reliability.</li><li><strong>Scalability</strong>: Both the containers and compute resources must scale seamlessly based on demand.</li><li><strong>Platform Independence</strong>: Containers should run on local environments, virtual machines, physical servers, and cloud platforms with ease.</li><li><strong>Flexibility and Agility</strong>: Deployments should adapt smoothly across development, QA, and production environments.</li></ul><p>To meet these demands, we’ll use <strong>Kubernetes</strong>, the leading container orchestration tool that provides a rock-solid platform for running containers in production.</p><blockquote><strong>Project Goals</strong></blockquote><p>In this project, we will:</p><ol><li>Deploy our <strong>Java-based vProfile application</strong> on a Kubernetes cluster for production.</li><li>Use <strong>Kops</strong> to launch a production-grade Kubernetes cluster.</li><li>Leverage Kubernetes features such as deployments, services, secrets, and persistent storage for seamless deployment.</li></ol><blockquote><strong>The Deployment Workflow</strong></blockquote><ol><li><strong>Set Up the Kubernetes Cluster</strong>: Use Kops to create a highly available cluster.</li><li><strong>Prepare the Persistent Storage</strong>: Configure EBS volumes for database persistence.</li><li><strong>Label Nodes</strong>: Match zones with specific nodes to align storage and compute resources.</li><li><strong>Define Kubernetes Manifests</strong>: Write YAML files for deployments, services, secrets, and volumes.</li></ol><p>Once everything is in place, we’ll deploy the vProfile application and test its functionality on the Kubernetes cluster.</p><p><strong>Note: Handling Persistent Data</strong></p><p>The vProfile application includes a <strong>MySQL container</strong>, which requires persistent storage for its data. Here’s the approach:</p><ul><li><strong>Create an EBS Volume</strong>: This ensures data persistence even if the MySQL container restarts.</li><li><strong>Node Labeling</strong>: Assign zone labels to nodes and ensure the MySQL pod runs in the same zone as the EBS volume.</li></ul><p>By strategically labeling nodes and deploying pods to specific zones, we ensure the application is tightly coupled with the necessary storage.</p><blockquote><strong>Architecture</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*9hnHao_cvOjsSwzKNcaSzQ.png" /></figure><p>Our application comprises multiple services, each deployed as a <strong>pod</strong> in Kubernetes. Here’s the breakdown:</p><ul><li><strong>Database (MySQL)</strong>: A pod hosting the MySQL container.</li><li><strong>Memcached and RabbitMQ</strong>: Each runs in its own pod using official Docker images.</li><li><strong>Tomcat</strong>: Hosts the application and runs in its dedicated pod.</li></ul><p>Instead of running these pods directly, we’ll define <strong>deployments</strong> for each service. Deployments provide a managed way to describe and maintain pods, including scaling and updates.</p><p><strong>-&gt; Internal Communication with Services</strong></p><p>In Kubernetes, pods don’t directly communicate with each other. Instead, we use <strong>services</strong> of type ClusterIP to enable internal communication. For example:</p><ul><li>The <strong>Tomcat pod</strong> communicates with the <strong>MySQL pod</strong> through a database service, which acts as a load balancer and routes requests to the correct database pod.</li></ul><p>This service-based approach ensures seamless communication between components without hardcoding dependencies.</p><p><strong>-&gt; Handling Stateful Applications</strong></p><p>The <strong>MySQL database</strong> is a stateful application because it stores and retrieves data at runtime. By default, MySQL stores data in the /var/lib/mysql directory. However, if a pod is deleted or recreated, its data will be lost. To prevent this, we use <strong>persistent storage</strong>.</p><p>Here’s how it works:</p><ol><li><strong>Persistent Volume Claim (PVC)</strong>: A PVC requests storage from a storage class, such as Amazon EBS in our case.</li><li><strong>Storage Class</strong>: Acts as a driver to connect Kubernetes with external storage.</li><li><strong>Pod Integration</strong>: The PVC is mapped to the database pod, ensuring data is stored persistently in /var/lib/mysql.</li></ol><p><strong>-&gt; Secrets for Sensitive Data</strong></p><p>To store sensitive information like passwords, we’ll use Kubernetes <strong>Secrets</strong>. For this setup, we need:</p><ul><li><strong>Database Password</strong>: Used by the MySQL service.</li><li><strong>RabbitMQ User Password</strong>: Required for secure communication.</li></ul><p>These secrets will be defined in a manifest file and injected into the relevant pods during runtime.</p><p><strong>-&gt; Services and External Access</strong></p><p><strong>Internal Services</strong>: All backend services (RabbitMQ, Memcached, MySQL, and Tomcat) will use ClusterIP services for internal communication. These services don’t expose public endpoints.</p><ul><li><strong>External Access via Ingress</strong>: To make the Tomcat application accessible externally, we’ll use an <strong>Ingress Controller</strong> with Nginx.</li><li>The ingress controller will create an <strong>Application Load Balancer</strong> (ALB) on AWS.</li><li>An ingress rule will define how requests are routed to the Tomcat service.</li><li>A DNS record will map the domain name to the ALB endpoint.</li></ul><p><strong>-&gt; Resource Manifest Files</strong></p><p>To implement this architecture, we need several Kubernetes manifest files:</p><ol><li><strong>Secrets</strong>: To store passwords for MySQL and RabbitMQ.</li><li><strong>Persistent Volume Claim</strong>: For database storage.</li><li><strong>Deployments</strong>: For MySQL, Memcached, RabbitMQ, and Tomcat.</li><li><strong>Services</strong>: ClusterIP services for backend communication.</li><li><strong>Ingress</strong>: To define routing rules for external access.</li></ol><p>This architecture ensures a scalable, resilient, and production-ready deployment of our application on Kubernetes.</p><blockquote><strong>Setting Up a Kubernetes Cluster with Cost Efficiency Using Kops</strong></blockquote><p>This involves several prerequisites and steps. I’ll walk you through the process using <strong>Kops</strong> (Kubernetes Operations) and AWS services. We’ll also explore how to minimize costs while ensuring an efficient setup.</p><p><strong>Prerequisites:<br>1. Domain Name: </strong>You’ll need a domain to manage Kubernetes DNS records. For testing purpose, I have created a free subdomain “koilraj.ip-ddns.com” from <a href="https://www.cloudns.net/">https://www.cloudns.net/</a>.<br><strong>2. Linux Virtual Machine (VM):</strong> This VM serves as the base machine to install necessary tools like Kops, kubectl, SSH keys, and AWS CLI. You can use:<br>-A Vagrant VM. (or)<br>-An AWS EC2 instance <br>This base VM will not be part of the Kubernetes cluster.</p><p><strong>(1) Setting Up the Base Machine (EC2 Instance)</strong></p><p>1.Launch an EC2 Instance:<br>2. Log in to the AWS Management Console.<br>3. Navigate to the EC2 section.<br>4. Choose: AMI: Ubuntu 24 (Free Tier Eligible).<br>5. Instance Type: t2.micro<br>6. Key Pair: Create a new key (e.g., kops-key).<br>7. Security Group: Allow SSH (port 22) access from your IP.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*t_L4QV9mB0qAsBbltnWigA.png" /></figure><p><strong>(2) Setting Up AWS Services:</strong></p><ol><li>Create an S3 Bucket:</li></ol><p>Go to the S3 dashboard and create a bucket (e.g., koilbucket12). This bucket will store cluster configuration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qGZTriruZyRXf6laE5bA8A.png" /></figure><p>2. Create an IAM User:</p><p>Navigate to the IAM service and create a user (e.g., kopsadmin) with <strong>Administrator Access</strong>.<br><strong>Generate access keys</strong> for this user and use them while configuring AWS CLI.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*O9m36xz3tWwXBbgzzGnYCw.png" /></figure><p>3. Set Up Route 53 Hosted Zone:</p><p><strong>Note: </strong>we need a domain to create kops cluster, i have created a free subdomain from <a href="https://www.cloudns.net/">https://www.cloudns.net/</a> for this project.</p><ul><li>Go to Route 53 and create a public hosted zone for your subdomain (e.g., kubevpro.koilraj.ip-ddns.com). You can create subdomain with whatever the name you like.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gtZ9e5xo3D0knneE-5Wvnw.png" /></figure><ul><li>Once the domain is added the AWS will share NS (Name Server) records for the subdomain.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2HXNGLedqm1KQ8hG59za8A.png" /></figure><ul><li>Update the NS records under your domain registrar’s DNS settings to point to these NS records.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Cyu6Mr2yYPlnVh6hIE8nEQ.png" /></figure><p>Note: When we run a kubectl command on our Kops cluster, the API request to the api.kubevpro.koilraj.ip-ddns.com server first goes to koilraj.ip-ddns.com. It retrieves the NS zone from ClouDNS for kubevpro.koilraj.ip-ddns.com, which then redirects to the AWS zone. Within the AWS zone, it fetches the A record IP (created by Kops during cluster bootstrapping), allowing the request to reach the control plane (API server).</p><p><strong>(3) Installing Required Tools:</strong></p><p>1. SSH into the EC2 base machine and update packages, Install AWS CLI and Configure AWS CLI.</p><pre>$ sudo apt update<br>$ sudo snap install aws-cli --classic<br>$ aws configure<br>#Enter the Access Key, Secret Key, Region Code (e.g., us-east-1), and output format (JSON).</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*JhoPDmdLZFtHwTNVKcNh5Q.png" /></figure><p>2. Generate SSH keys, Install Kops and kubectl.</p><pre>$ ssh-keygen<br><br>#installing kops<br>$ curl -Lo kops https://github.com/kubernetes/kops/releases/download/$(curl -s https://api.github.com/repos/kubernetes/kops/releases/latest | jq -r .tag_name)/kops-linux-amd64<br>$ chmod +x kops<br>$ sudo mv kops /usr/local/bin/<br><br>#installing kubectl<br>$ curl -LO &quot;https://dl.k8s.io/release/$(curl -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl&quot;<br>$ chmod +x kubectl<br>$ sudo mv kubectl /usr/local/bin/ <br>To install kops, refer &gt;&gt; https://kops.sigs.k8s.io/getting_started/install/<br>To install kubectl, refer &gt;&gt; https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*N4hyFR2qC0HyDfDw-8qn5g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*sdrfcypP_KEDloQYSS_H9Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*p8LcOcBP-RR0sp2yiT5-1g.png" /></figure><p>To install kops, refer: <a href="https://kops.sigs.k8s.io/getting_started/install/">https://kops.sigs.k8s.io/getting_started/install/</a><br>To install kubectl, refer: <a href="https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/">https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/</a></p><p><strong>(4) Creating the Kubernetes Cluster</strong></p><ol><li>Configure Cluster with below details:</li></ol><p>The Kubernetes cluster information will be saved under s3 bucket<strong>(s3://koilbucket12)</strong> from which we can initiate cluster easily.</p><p><strong>Cluster Name: </strong>kubevpro.koilraj.ip-ddns.com (<strong>note: </strong>should be an active subdomain)<br><strong>Bucket Name:</strong> s3://koilbucket12<br><strong>Node Count and Size:</strong> node count 2 and size t3.small (creating 2 node cluster with t3.small Ec2 instance)<br><strong>Control Plane Size:</strong> t3.medium<br><strong>SSH-key: </strong>generated from our base machine</p><pre>$ kops create cluster --name=kubevpro.koilraj.ip-ddns.com --state=s3://koilbucket12 --zones=us-east-1a,us-east-1b --node-count=2 --node-size=t3.small --control-plane-size=t3.medium --dns-zone=kubevpro.koilraj.ip-ddns.com --node-volume-size=12 --control-plane-volume-size=12 --ssh-public-key ~/.ssh/id_ed25519.pub</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WlSak_YQzJs2FSoeXIyHMg.png" /></figure><p>2. Bootstrapping Kubernetes cluster:</p><p>Creating the Kubernetes cluster with the below command</p><pre>$ kops update cluster - name=kubevpro.koilraj.ip-ddns.com - state=s3://koilbucket12 - yes –admin</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pHkkD0hIxcZU1G0Y6owzUQ.png" /></figure><p>This command applies the configuration saved in S3 bucket and starts creating the Kubernetes cluster. The process might take several minutes.</p><p>3. Validating the cluster:</p><p>Once the Kubernetes cluster is bootstrapped it will take 10–15 mins, and post that the cluster will be up and running fine.</p><p>We can verify whether all the services or created and cluster is up or not using below command.</p><pre>kops validate cluster - name=kubevpro.koilraj.ip-ddns.com - state=s3://koilbucket12</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xsQVU9szb6DB0l6LX1FExg.png" /></figure><p>Below are the default pods that will start running as soon as the cluster is initiated.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*iEnrrQHSGt3nGLhX-rEWrQ.png" /></figure><p>Based on our command:</p><ul><li>Three EC2 instances are created: one for the master node and two for the worker nodes.</li><li>Kops also Adds IPs for Kube API servers, creates VPC, and auto scaling group for the nodes.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eub3RK70V4ZMYyJVoM1Tsw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ay5mdHH7_BHrZRJUS71kqQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S2mjgVNp-7IX8lWDyN8Lfg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c04AVIIKsf2SxucfnwQ1hA.png" /></figure><blockquote><strong>Kubernetes Manifest files:</strong></blockquote><p>We have successfully set up a Kubernetes cluster using Kops, and now we will explore the manifest files required to deploy our multi-tier microservice web application on this cluster.</p><ol><li><strong>Secrets:</strong></li></ol><p>Stores environment variables like DATABASE_PASSWORD and — RABBITMQ_PASSWORD. We are encoding the password with base64 and storing it as secret.</p><pre>apiVersion: v1<br>kind: Secret<br>metadata:<br>  name: app-secret<br>type: Opaque<br>data:<br>  db-pass: dnByb2RicGFzcw== <br>  rmq-pass: Z3Vlc3Q=</pre><p>2. <strong>Persistent Volume Claim (PVC):</strong></p><p>Claims 3GB of storage for the application. This will create Elastic Block Storage (Persistent Volume)of size 3 GB, and from which we are going to claim 3GB for our database to persist the data, even if the database pod goes down or gets deleted.</p><pre>apiVersion: v1<br>kind: PersistentVolumeClaim<br>metadata:<br>  name: db-pv-claim<br>  labels:<br>    app: vprodb<br>spec:<br>  storageClassName: default<br>  accessModes:<br>    - ReadWriteOnce<br>  resources:<br>    requests:<br>      storage: 3Gi</pre><p>3. <strong>Deployments and Services (svc):</strong></p><p><strong>Tomcat vprofile app: (Depoyment manifest)</strong></p><ul><li>The Docker image for this application is already built and stored in a Docker Hub repository.</li><li>We added <strong>init containers</strong> to ensure backend services like databases, RabbitMQ, and Memcached are running before the Tomcat application starts.</li></ul><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: vproapp<br>  labels: <br>    app: vproapp<br>spec:<br>  replicas: 1<br>  selector:<br>    matchLabels:<br>      app: vproapp<br>  template:<br>    metadata:<br>      labels:<br>        app: vproapp<br>    spec:<br>      containers:<br>      - name: vproapp<br>        image: koilraj/vprofileapp<br>        imagePullPolicy: Always<br>        ports:<br>        - name: vproapp-port<br>          containerPort: 8080<br>      initContainers:<br>      - name: init-mydb<br>        image: busybox<br>        command: [&#39;sh&#39;, &#39;-c&#39;, &#39;until nslookup vprodb.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local; do echo waiting for mydb; sleep 2; done;&#39;]<br>      - name: init-memcache<br>        image: busybox<br>        command: [&#39;sh&#39;, &#39;-c&#39;, &#39;until nslookup vprocache01.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local; do echo waiting for mydb; sleep 2; done;&#39;]</pre><p><strong>Tomcat service: (Service manifest)</strong></p><ul><li>In Kubernetes, connecting application components like tomcat and services is not as straightforward as linking them via pod IPs. Pods, being ephemeral, cannot be relied upon for direct connections. This is where Kubernetes <strong>Services</strong> come into play, acting as internal load balancers to route traffic to the appropriate pods reliably.</li><li>We are creating the <strong>ClusterIP service</strong> on top of tomcat deployment to expose the application within the cluster with <strong>port 8080.</strong></li></ul><pre>apiVersion: v1<br>kind: Service<br>metadata:<br>  name: vproapp-service<br>spec:<br>  ports:<br>  - port: 8080<br>    protocol: TCP<br>    targetPort: 8080<br>  selector:<br>    app: vproapp<br>  type: ClusterIP</pre><p><strong>MySQL Database:</strong> <strong>(Depoyment manifest)</strong></p><ul><li>To persist database data, we’ll use a <strong>Persistent Volume Claim (PVC)</strong> and mount it to the pod.</li><li>A known issue with certain storage backends, like AWS EBS, is the presence of a lost+found folder. MySQL requires an empty directory for its /var/lib/mysql folder. To handle this, we use an <strong>init container</strong> to clean up the volume before the main container starts.</li></ul><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: vprodb<br>  labels:<br>    app: vprodb<br>spec:<br>  selector:<br>    matchLabels:<br>      app: vprodb<br>  replicas: 1<br>  template:<br>    metadata:<br>      labels:<br>        app: vprodb<br>    spec:<br>      containers:<br>      - name: vprodb<br>        image: koilraj/vprofiledb<br>        volumeMounts:<br>        - mountPath: /var/lib/mysql<br>          name: vpro-db-data<br>        ports:<br>        - name: vprodb-port<br>          containerPort: 3306<br>        env:<br>         - name: MYSQL_ROOT_PASSWORD<br>           valueFrom:<br>             secretKeyRef:<br>               name: app-secret<br>               key: db-pass<br>      volumes:<br>        - name: vpro-db-data<br>          persistentVolumeClaim:<br>            claimName: db-pv-claim <br><br>      initContainers:<br>        - name: busybox<br>          image: busybox:latest<br>          args: [&quot;rm&quot;, &quot;-rf&quot;, &quot;/var/lib/mysql/lost+found&quot;]<br>          volumeMounts:<br>            - name: vpro-db-data<br>              mountPath: /var/lib/mysql</pre><p><strong>MySQL database:(Service manifest)</strong></p><ul><li>We’ll create a ClusterIP service, an internal load balancer within the Kubernetes cluster, to route requests from tomcat pod to the MySQL pod on port 3306.</li><li>The name of the service is critical. In our example, it’s<strong> vprodb</strong>. This name is referenced in the <strong>application properties file</strong> of the Tomcat application to resolve the database IP dynamically.</li></ul><pre>apiVersion: v1<br>kind: Service<br>metadata:<br>  name: vprodb<br>spec:<br>  ports:<br>  - port: 3306<br>    targetPort: 3306<br>    protocol: TCP<br>  selector:<br>    app: vprodb<br>  type: ClusterIP</pre><p><strong>Memcached:(Deployment manifest)</strong></p><ul><li><strong>Memcached </strong>is used as an in-memory caching system that helps improve the performance and scalability of the app.</li></ul><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: vpromc<br>  labels:<br>    app: vpromc<br>spec:<br>  selector:<br>    matchLabels:<br>      app: vpromc<br>  replicas: 1<br>  template:<br>    metadata:<br>      labels:<br>        app: vpromc<br>    spec:<br>      containers:<br>      - name: vpromc<br>        image: memcached<br>        ports:<br>        - name: vpromc-port<br>          containerPort: 11211</pre><p><strong>Memcached: (Service manifest)</strong></p><ul><li>We’ll create a ClusterIP service for the memcache deployment exposed internally on port 11211.</li></ul><pre>apiVersion: v1<br>kind: Service<br>metadata:<br>  name: vprocache01<br>spec:<br>  ports:<br>  - port: 11211<br>    targetPort: 11211<br>    protocol: TCP<br>  selector:<br>    app: vpromc <br>  type: ClusterIP</pre><p><strong>RabbitMQ:(Deployment manifest)</strong></p><ul><li>RabbitMQ is a popular message broker, software that facilitates the communication between distributed applications or services by passing messages between them. It implements the <strong>Advanced Message Queuing Protocol (AMQP)</strong>, which is an open standard for messaging.</li><li>RabbitMQ helps decouple the sender (producer) of a message from the receiver (consumer), providing a reliable way to transfer data between different parts of a system, especially in microservices architectures or distributed systems.</li></ul><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: vpromq01<br>  labels:<br>    app: vpromq01<br>spec:<br>  selector:<br>    matchLabels:<br>      app: vpromq01<br>  replicas: 1<br>  template:<br>    metadata:<br>      labels:<br>        app: vpromq01<br>    spec:<br>      containers:<br>      - name: vpromq01<br>        image: rabbitmq<br>        ports:<br>        - name: vpromq01-port<br>          containerPort: 5672<br>        env: <br>         - name: RABBITMQ_DEFAULT_PASS<br>           valueFrom:<br>             secretKeyRef:<br>               name: app-secret<br>               key: rmq-pass<br>         - name: RABBITMQ_DEFAULT_USER<br>           value: &quot;guest&quot;</pre><p><strong>RabbitMQ:(Service manifest)</strong></p><pre>apiVersion: v1<br>kind: Service<br>metadata:<br>  name: vpromq01<br>spec:<br>  ports:<br>  - port: 5672<br>    targetPort: 5672<br>    protocol: TCP<br>  selector:<br>    app: vpromq01<br>  type: ClusterIP</pre><p><strong>4. Ingress</strong></p><ul><li>In Kubernetes, services of type <strong>ClusterIP</strong> are used for internal communication. They expose an endpoint for the pods within the cluster, and multiple replicas of a pod can be managed by a ClusterIP service, functioning like an internal load balancer.</li><li>However, when you want to expose an application, such as a Tomcat server, publicly, an <strong>external load balancer</strong> is required. This is where <strong>Ingress</strong> comes in.</li><li>Ingress is a Kubernetes resource that manages external access to services in the cluster, typically HTTP and HTTPS. It allows routing traffic from an external load balancer to your internal services based on specific rules, such as URL paths or hostnames.</li><li>In this project we are exposing this application with host vprofile.koilraj.ip-ddns.com</li></ul><pre>apiVersion: networking.k8s.io/v1<br>kind: Ingress<br>metadata:<br>  name: vpro-ingress<br>  annotations:<br>    nginx.ingress.kubernetes.io/use-regex: &quot;true&quot;<br>spec:<br>  ingressClassName: nginx<br>  rules:<br>  - host: vprofile.koilraj.ip-ddns.com<br>    http:<br>      paths:<br>      - path: /<br>        pathType: Prefix<br>        backend:<br>          service:<br>            name: vproapp-service<br>            port:<br>              number: 8080</pre><p>We’ll be using the <strong>NGINX Ingress Controller</strong> to manage this communication. The NGINX Ingress Controller will create an <strong>application load balancer</strong> for us and allow us to define <strong>Ingress rules</strong>.</p><p><strong>Steps to install nginx controller &gt;&gt; </strong><a href="https://kubernetes.github.io/ingress-nginx/deploy/#aws">https://kubernetes.github.io/ingress-nginx/deploy/#aws</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*DHoLs87srrDDJNGUkE4wlg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*FFvWNUcrva5QTOFPB7sS0g.png" /></figure><p>The Ingress controller will set up a load balancer in AWS to route external traffic from the domain <strong>“vprofile.koilraj.ip-ddns.com” to the Tomcat pod </strong>through the Kubernetes Ingress object.</p><blockquote><strong>Deploying the multi-tier application on the kops created Kubernetes nodes.</strong></blockquote><ol><li>Cloning github repo</li></ol><p>On our base machine, cd into the Kubernetes manifest files directory</p><pre>$ git clone https://github.com/Koil-raj/kubernetes-vprofile-proj.git<br>$ cd kubernetes-vprofile-proj/kubedefs</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1014/1*s1DLaUaHVD-8SPo0UsgaNA.png" /></figure><p>2. And run below kubectl command to create the kubernetes objects for the multi-tier application.</p><pre>$ kubectl apply -f .</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*2TJRloAGYwFE6YymzVW1kw.png" /></figure><p>The above command will create below services in AWS</p><ul><li>Persistentvolumeclaim — (EBS volume of size 3GB)</li><li>Deployments, services — Inside kubernetes cluster</li><li>Ingress controller will create a load balancer</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1_rFVzoqxRbjcbDPHixoxQ.png" /></figure><p>3. Verification:</p><ul><li>The pod IP and the service endpoint should be same for the microservices.</li><li>Only then the service will route the requests to the respective pods. this is mapped using selectors and labels.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*khe-ctg-SznoNSqzI3t_4A.png" /></figure><p>4. Updating CNAME record for the site “vprofile.koilraj.ip-ddns.com”</p><p>After deployment, to access the tomcat application hosted inside kubernetes cluster, we are going to check the ingress pod and get the ELB endpoint and map it to the domain “vprofile.koilraj.ip-ddns.com”.</p><p>We will map the domain and endpoint using CNAME record</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6lJGImbSu7HsH4jV1cHNdQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1012/1*JToJslqPMOEYuRoPFJuXdQ.png" /></figure><p>5. Testing the site:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*T6RoVNStjerjQ_rjxcsiAQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*XSx3OvQDIF0jkGbGfmGVxQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*OBzFGsCMJ4YBl2rUbOUJMQ.png" /></figure><p><strong>Note:</strong> If we directly access the load balancer endpoint, it will throw 404 error as we have set ingress rule to redirect the request from only the domain(host) <a href="http://vprofile.koilraj.ip-ddns.com/"><strong>vprofile.koilraj.ip-ddns.com</strong></a> with<strong> “/”</strong> to vprofile tomcat app.</p><p>-Inorder to access the website directly using ELB endpoint we can change the ingress rule from host-based routing to HTTP path-based routing. and apply</p><p><strong>Updated ingress manifest file:</strong></p><pre>apiVersion: networking.k8s.io/v1<br>kind: Ingress<br>metadata:<br>  name: vpro-ingress<br>  annotations:<br>    nginx.ingress.kubernetes.io/use-regex: &quot;true&quot;<br>spec:<br>  ingressClassName: nginx<br>  rules:<br>  - http:<br>      paths:<br>      - path: /<br>        pathType: Prefix<br>        backend:<br>          service:<br>            name: vproapp-service<br>            port:<br>              number: 8080</pre><pre>kubectl apply -f kubernetes-vprofile-proj/kubedefs/appingress.yaml</pre><blockquote>Cleanup</blockquote><ul><li>Deleting the Kubernetes objects:</li></ul><pre>$ kubectl delete -f kubernetes-vprofile-proj/kubedefs/.</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/969/1*tafw49w9JDA3aHr4RG2KhQ.png" /></figure><ul><li>Deleting ingress controller</li></ul><pre>kubectl delete -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.12.0-beta.0/deploy/static/provider/aws/deploy.yaml</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*UighXe8C5g8ckX-dlcdi7g.png" /></figure><ul><li>Deleting Kubernetes cluster</li></ul><pre>$ kops delete cluster - name=kubevpro.koilraj.ip-ddns.com - state=s3://koilbucket12</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*sj565VWiWjVSLZEFptH5yg.png" /></figure><p>This removes all resources, including VPCs, instances, and DNS records that was created by kops.</p><blockquote><strong>Conclusion</strong></blockquote><p>Setting up a multi-tier web application stack can be a complex task, but with the right approach, it becomes manageable. In this project, we covered the entire process of deploying a Kubernetes application with an Ingress Controller and integrating it with backend services like databases. The architecture includes a load balancer, ingress routing, service-to-pod communication, and persistent storage via EBS volumes. Additionally, we discussed the importance of understanding your Kubernetes manifests and how they align with the architecture.</p><p>As a best practice, always review your definitions, compare them with your architecture diagram, and document your setup. Finally, we wrapped up by demonstrating how to delete the created resources and clean up the environment, including the ingress controller, PVC, and Kubernetes cluster. This cleanup process ensures a tidy environment and is crucial when working with cloud resources like AWS. With this foundational knowledge, you are now well-equipped to containerize applications and manage them in Kubernetes.</p><p><strong>Reference:</strong></p><p><a href="https://www.udemy.com/share/104Tz63@G3e1SPXF274ejl-Q865K3hS9XEazBrKekum5eTSV9A2hVCI0IQTQu6ofxlxV05fafw==/">https://www.udemy.com/share/104Tz63@G3e1SPXF274ejl-Q865K3hS9XEazBrKekum5eTSV9A2hVCI0IQTQu6ofxlxV05fafw==/</a></p><p>Please feel free to contact me on LinkedIn for questions, critiques or suggestions <a href="https://www.linkedin.com/in/koil-raj/">https://www.linkedin.com/in/koil-raj/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0ee43c50198f" width="1" height="1" alt=""><hr><p><a href="https://blog.devops.dev/deploying-a-multi-tier-web-application-on-a-kubernetes-cluster-with-kops-0ee43c50198f">Deploying a Multi-Tier Web Application on a Kubernetes Cluster with Kops</a> was originally published in <a href="https://blog.devops.dev/">DevOps.dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>