<?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"><channel><title><![CDATA[K8s Ingress Path Routing]]></title><description><![CDATA[Deployed a K8s cluster on AWS EC2, built and pushed custom Docker images, created manifests for microservices, set up NGINX Ingress with path-based routing, and]]></description><link>https://k8s-ingress-path-routing.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Wed, 18 Nov 2026 14:29:56 GMT</lastBuildDate><atom:link href="https://k8s-ingress-path-routing.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Kubernetes cluster on AWS EC2 with custom Docker images, microservices, NGINX Ingress path routing, and security group setup]]></title><description><![CDATA[Learn how to deploy multiple microservices on Kubernetes using NGINX Ingress with path-based routing, custom Docker images, and NodePort access.]]></description><link>https://k8s-ingress-path-routing.hashnode.dev/kubernetes-cluster-on-aws-ec2-with-custom-docker-images-microservices-nginx-ingress-path-routing-and-security-group-setup</link><guid isPermaLink="true">https://k8s-ingress-path-routing.hashnode.dev/kubernetes-cluster-on-aws-ec2-with-custom-docker-images-microservices-nginx-ingress-path-routing-and-security-group-setup</guid><category><![CDATA[#Kubernetes #Microservices #Docker #NGINXIngress #IngressController #PathBasedRouting #NodePort #EC2 #AWS #DevOps #Containerization #CloudComputing #K8s #KubernetesDeployment #CustomDockerImages #LoadBalancing #Networking #ClusterManagement #IngressRouting #DockerHub #BareMetalKubernetes]]></category><dc:creator><![CDATA[Abhishek Balaji]]></dc:creator><pubDate>Fri, 05 Sep 2025 08:36:57 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1756979628903/fea5d2b3-5686-4d45-9ac9-ee080e492960.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1756979986679/db9a1a31-1c76-4944-bca2-52f3bd62c8cd.png" alt class="image--center mx-auto" /></p>
<p>In this project, I designed and implemented a fully functional Kubernetes cluster on AWS EC2 instances to demonstrate scalable deployment and management of containerized microservices. The project involved creating custom Docker images tailored to specific web applications, which were then pushed to Docker Hub for easy version control and distribution.</p>
<p>Using Kubernetes manifest files, I defined and deployed multiple microservices, enabling a modular and maintainable architecture. To manage inbound traffic efficiently, I installed the NGINX Ingress Controller, which allowed me to configure path-based routing rules. This setup directs requests to different backend services based on URL paths, enabling multiple applications to be accessed under a single domain seamlessly.</p>
<p>Security was a key focus area; I configured AWS security groups to permit only necessary inbound traffic to the Kubernetes NodePort services, ensuring the cluster was protected from unauthorized access while maintaining functionality.</p>
<p>The core tools and technologies utilized in this project include AWS EC2 for cloud infrastructure, Docker for containerization, Docker Hub as the container registry, Kubernetes for orchestration, and the NGINX Ingress Controller for advanced routing capabilities. This project highlights practical skills in cloud infrastructure setup, container image management, Kubernetes resource configuration, and secure network traffic handling, making it a comprehensive showcase of modern DevOps and cloud-native practices.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1757058258939/4b888e73-ef9b-4cfb-a560-4e8eaf806a4d.png" alt class="image--center mx-auto" /></p>
<pre><code class="lang-plaintext">https://hub.docker.com/repository/docker/abhishekbalaji/apps/general
</code></pre>
<p>I have logged into my AWS account. Let's proceed to create a Kubernetes cluster using the EC2 service.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1756983363153/a15f5047-58c6-453d-9f2d-026fe4e6af58.png" alt class="image--center mx-auto" /></p>
<p>Before proceeding, I will create a security group that allows all traffic, but this is only for demonstration purposes.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1756983567204/f50b02e8-34e4-4c46-bb63-dec792b5899d.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1756983629762/5101d298-b497-423d-9b76-6b81ec60ee87.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1756983645476/bf1c367b-7536-4a5d-b92f-0d53b96390e8.png" alt class="image--center mx-auto" /></p>
<p>Click on create security group</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1756983672630/f979de76-9ca9-476a-91dd-470a5eb91fce.png" alt class="image--center mx-auto" /></p>
<p>Back to creating an EC2 instance</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1756983382893/f28cd19e-799e-4d7a-a79d-efa1a3a5b321.png" alt class="image--center mx-auto" /></p>
<p>Click on create “Launch Instances” button</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1756983456675/6ba62210-02fa-441f-a587-bbda7a8b12a0.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1756983472964/60c2c8e4-f1df-48c7-a269-dd80532b35a7.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1756983740015/26f537f1-099e-4a45-ba41-38dae8f61ea7.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1756983752457/83bfd070-16f8-4640-83b4-78aaca4b68d7.png" alt class="image--center mx-auto" /></p>
<p>Click on launch instance</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1756983785012/087290e6-fe56-4696-b999-dd7710ab9610.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1756983801345/cbe7a13d-04fe-4b6a-8efb-95677c0776ee.png" alt class="image--center mx-auto" /></p>
<p>Now, I will create two worker nodes: node-1 and node-2.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1756983867423/c5a70bee-a0e7-43a1-9f8c-9464d8aad021.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1756983888538/72b58cc1-f4e2-4914-9324-21e0c8e019bf.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1756983911833/ce2f5d90-b96b-4a96-8fe4-c7bddeaf941c.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1756983929614/69a11a26-fad8-4ffc-b9ae-7bc16c1dc76b.png" alt class="image--center mx-auto" /></p>
<p>Click on launch instances</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1756983983573/44746c3a-79e3-4bf7-94e5-678079349e87.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1756984015720/ac290a2a-7664-4580-b61f-b2700949cb07.png" alt class="image--center mx-auto" /></p>
<p>Now, we have a control plane, worker node 1, and worker node 2. Let's connect to them using the EC2 Instance Connect feature.</p>
<p>Once done, let us go ahead update and upgrade all of our instances</p>
<pre><code class="lang-plaintext">sudo apt update -y &amp;&amp; sudo apt upgrade -y
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1756984264688/d8a12eea-05fa-4061-8f78-310004fc74e5.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1756984316905/15ce6907-691e-407c-bd7f-e5f61e7dcac2.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1756984358132/163acb0d-08e0-4f3e-8f91-e556b7c03058.png" alt class="image--center mx-auto" /></p>
<p>Done</p>
<p>Now, install docker on all the nodes</p>
<pre><code class="lang-plaintext">sudo wget https://raw.githubusercontent.com/puneetgavri/kubernetes-world/main/installation/scripts/installDocker.sh -P /tmp
sudo chmod 755 /tmp/installDocker.sh
sudo bash /tmp/installDocker.sh
sudo systemctl restart docker.service
</code></pre>
<pre><code class="lang-plaintext">docker --version  # after successful installation
</code></pre>
<p>Now, install the container runtime interface.</p>
<pre><code class="lang-plaintext">sudo wget https://raw.githubusercontent.com/lerndevops/labs/master/scripts/installCRIDockerd.sh -P /tmp
sudo chmod 755 /tmp/installCRIDockerd.sh
sudo bash /tmp/installCRIDockerd.sh
sudo systemctl restart cri-docker.service
</code></pre>
<p>Install kudeadm, kublet, and kubectl</p>
<pre><code class="lang-plaintext">sudo wget https://raw.githubusercontent.com/puneetgavri/kubernetes-world/main/installation/scripts/installK8S.sh -P /tmp
sudo chmod 755 /tmp/installK8S.sh
sudo bash /tmp/installK8S.sh
</code></pre>
<p>Run this command only on the control-plane</p>
<pre><code class="lang-plaintext">sudo kubeadm init --cri-socket unix:///var/run/cri-dockerd.sock --ignore-preflight-errors=all
</code></pre>
<pre><code class="lang-plaintext"># Do not run this command yet
kubeadm join 172.31.43.125:6443 --token ia1pqz.w92s5dkqdpesu8p6 \
        --discovery-token-ca-cert-hash sha256:953d1c39e63882f793d5bbef170cde4737a74509139bc75c3290b182a111883c
</code></pre>
<p>The code above is for <code>kubeadm join</code>, which allows worker-node-1 and worker-node-2 to join the Kubernetes cluster.</p>
<pre><code class="lang-plaintext">sudo mkdir -p $HOME/.kube
   sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
   sudo chown $(id -u):$(id -g) $HOME/.kube/config
</code></pre>
<p>Install network drivers</p>
<pre><code class="lang-plaintext">kubectl apply -f https://raw.githubusercontent.com/projectcalico/calico/v3.24.1/manifests/calico.yaml
</code></pre>
<pre><code class="lang-plaintext">kubectl get nodes
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1756984988453/1c8de208-4f42-4b55-8ff1-9ef7d6678e36.png" alt class="image--center mx-auto" /></p>
<pre><code class="lang-plaintext"># Run this code on worker-node-1 &amp; 2

sudo kubeadm join 172.31.43.125:6443 --token ia1pqz.w92s5dkqdpesu8p6 \
        --discovery-token-ca-cert-hash sha256:953d1c39e63882f793d5bbef170cde4737a74509139bc75c3290b182a111883c --cri-socket unix:///var/run/cri-dockerd.sock --ignore-preflight-errors=all
</code></pre>
<pre><code class="lang-plaintext">kubectl get nodes # check the status of the cluster
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1756985202123/3938b32b-9b87-40a8-aac9-c9ad35c25e40.png" alt class="image--center mx-auto" /></p>
<pre><code class="lang-plaintext">nano deploy-microservices.yaml
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1756985264352/638835d3-ee3d-4ca0-bf54-8ecddeb0573a.png" alt class="image--center mx-auto" /></p>
<pre><code class="lang-plaintext">apiVersion: apps/v1
kind: Deployment
metadata:
  name: welcome-page
  labels:
    author: abhishek-balaji
spec:
  replicas: 3
  selector:
    matchLabels:
      app: app1
  template:
    metadata:
      labels:
        app: app1
    spec:
      containers:
        - name: app1
          image: abhishekbalaji/apps:app1
          ports:
            - containerPort: 80

---

apiVersion: v1
kind: Service
metadata:
  name: app1-svc
  labels:
    author: abhishek-balaji
spec:
  type: ClusterIP
  selector:
    app: app1
  ports:
    - port: 80
      targetPort: 80

---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: second-page
  labels:
    author: abhishek-balaji
spec:
  replicas: 3
  selector: 
    matchLabels:
      app: app2
  template:
    metadata:
      labels:
        app: app2
    spec: 
      containers:
        - name: app2
          image: abhishekbalaji/apps:app2
          ports:
            - containerPort: 80

---

apiVersion: v1
kind: Service
metadata:
  name: app2-svc
  labels:
    author: abhishek-balaji
spec:
  type: ClusterIP
  selector:
    app: app2
  ports:
    - port: 80
      targetPort: 80

---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: third-page
  labels:
    author: abhishek-balaji
spec:
  replicas: 3
  selector:
    matchLabels:
      app: app3
  template:
    metadata:
      labels:
        app: app3
    spec:
      containers:
        - name: app3
          image: abhishekbalaji/apps:app3
          ports:
            - containerPort: 80

---

apiVersion: v1
kind: Service
metadata:
  name: app3-svc
  labels:
    author: abhishek-balaji
spec:
  type: ClusterIP
  selector: 
    app: app3
  ports:
    - port: 80
      targetPort: 80
</code></pre>
<pre><code class="lang-plaintext"># run this command

kubectl apply -f deploy-microservices.yaml
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1756986925447/2875eebd-3290-4687-a2d3-7bee1d2fc14a.png" alt class="image--center mx-auto" /></p>
<pre><code class="lang-plaintext">kubectl get all
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1756986964176/87194107-5b24-40c6-ba07-6ba95e1b4883.png" alt class="image--center mx-auto" /></p>
<p>Now, let's install the ingress-nginx-controller.</p>
<pre><code class="lang-plaintext">kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.3.0/deploy/static/provider/baremetal/deploy.yaml
</code></pre>
<pre><code class="lang-plaintext">nano ingress-nginx-rules.yaml
</code></pre>
<pre><code class="lang-plaintext">apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-rules
  labels:
    author: abhishek-balaji
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
    - http:
        paths:
          - path: /app1
            pathType: Prefix
            backend:
              service:
                name: app1-svc
                port:
                  number: 80
          - path: /app2
            pathType: Prefix
            backend:
              service:
                name: app2-svc
                port:
                  number: 80
          - path: /app3
            pathType: Prefix
            backend:
              service: 
                name: app3-svc
                port:
                  number: 80
</code></pre>
<pre><code class="lang-plaintext">kubectl apply -f ingress-nginx-rules.yaml
</code></pre>
<pre><code class="lang-plaintext">kubectl get all  # get all kubernetes resources within default namespace

kubectl get all -n ingress-nginx  # get all kubernetes resources within ingress-nginx

kubectl get nodes -o wide  # get all nodes with additional details
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1757060885137/df842fdb-e593-482b-9f61-6ff85562982f.png" alt class="image--center mx-auto" /></p>
<pre><code class="lang-plaintext">curl http://172.31.20.171:32360/app1
curl http://172.31.20.171:32360/app2
curl http://172.31.20.171:32360/app3
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1757060981694/31bb91e8-355b-4274-aa3d-b620537c153a.png" alt class="image--center mx-auto" /></p>
<p>It works internally within the cluster. Now, I need to test it in the browser.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1757061021529/564e80a6-49bb-4836-bc6d-2bd9a9c07f43.png" alt class="image--center mx-auto" /></p>
<pre><code class="lang-plaintext">52.90.166.165
</code></pre>
<pre><code class="lang-plaintext">http://52.90.166.165:32360/app1
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1757061083401/324b0b8d-db1e-4744-a641-6c4e8654ebd8.png" alt class="image--center mx-auto" /></p>
<pre><code class="lang-plaintext">http://52.90.166.165:32360/app2
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1757061120107/f133532a-a7f7-4e98-ba78-93bb951690b9.png" alt class="image--center mx-auto" /></p>
<pre><code class="lang-plaintext">http://52.90.166.165:32360/app3
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1757061140905/f5c1be4b-4cc8-44f0-97c4-8ffb517f2fbb.png" alt class="image--center mx-auto" /></p>
<p>Done</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1757061294713/87d69d23-1a43-4832-844a-a2a755e0e641.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-important-networking-note"><strong>Important Networking Note</strong></h3>
<p>Since your <strong>Ingress Controller is of type NodePort</strong>, Kubernetes exposes it on a specific high-numbered port (e.g., <code>32360</code> in your case). To allow external access:</p>
<ol>
<li><p><strong>Update the Security Group</strong> for your EC2 instances:</p>
<ul>
<li><p><strong>Type:</strong> Custom TCP Rule</p>
</li>
<li><p><strong>Port Range:</strong> <code>32360</code> (or whatever your NodePort is)</p>
</li>
<li><p><strong>Source:</strong> <code>0.0.0.0/0</code> (for public access; adjust for security as needed)</p>
</li>
</ul>
</li>
</ol>
<h2 id="heading-conclusion"><strong>Conclusion</strong></h2>
<p>In this project, we successfully designed and deployed a <strong>three-microservice architecture</strong> on Kubernetes, exposing them through <strong>NGINX Ingress with path-based routing</strong>. By building custom Docker images for each service and correctly configuring Deployments, Services, and Ingress rules, we ensured that traffic is routed properly to the corresponding backend services.</p>
<p>Key takeaways from this project include:</p>
<ul>
<li><p><strong>Custom Docker Images:</strong> Simplified containerization using NGINX to serve static content for each microservice.</p>
</li>
<li><p><strong>Kubernetes Resources:</strong> Proper usage of Deployments and Services to manage replicas and internal traffic.</p>
</li>
<li><p><strong>Ingress Path-Based Routing:</strong> Correctly routing multiple services on the same host using paths (<code>/app1</code>, <code>/app2</code>, <code>/app3</code>).</p>
</li>
<li><p><strong>Avoiding 404 Errors:</strong> Using <code>spec.ingressClassName: nginx</code> and the rewrite-target annotation to ensure requests are correctly forwarded to backend containers.</p>
</li>
</ul>
<p>This setup provides a solid foundation for <strong>scalable microservices deployment</strong>, and it can be further enhanced with <strong>TLS, custom domains, health probes, and auto-scaling</strong>, making it production-ready on cloud platforms like AWS or on bare-metal clusters.</p>
<p>Thank you</p>
]]></content:encoded></item></channel></rss>