Kubernetes Ingress- Project- “MarketHub: Microservices Marketplace”

Nidhi Ashtikar
4 min readMay 1, 2024

Project Overview:

  • MarketHub consists of three main microservices: Product Catalog, User Authentication, and Order Management.
  • Each microservice is deployed as a separate backend service.
  • MarketHub hosts multiple stores for different sellers, each with its own domain name.
  • All communication between clients and the backend services is encrypted using TLS.
  • Incoming traffic is evenly distributed across backend services to ensure high availability and reliability.

Here’s a high-level architecture of the project:

                    Internet


[ Ingress ]
┌───────┴───────┴───────┐
│ │ │
[ Catalog Service ] [ Auth Service ] [ Order Service ]

Implementation:

1. Define Project Requirements and Architecture:

Define the architecture, services (Product Catalog, User Authentication, Order Management), and the decision to use Kubernetes for container orchestration.

2. Setup Kubernetes Cluster:

Choose a cloud provider or set up a local Kubernetes cluster using Minikube.

Install Minikube (if not already installed):

brew install minikube

Start Minikube cluster:

minikube start

3. Develop Microservices:

  • Develop microservices using your preferred programming language and framework (e.g., Node.js, Python, Java).
  • Dockerize each microservice by creating a Dockerfile.
  • Example Dockerfile for Product Catalog service:
FROM node:14

WORKDIR /usr/src/app

COPY package*.json ./

RUN npm install

COPY . .

EXPOSE 8080

CMD [ "npm", "start" ]

4. Deploy Microservices to Kubernetes:

Create Kubernetes Deployment resources for each microservice:

apiVersion: apps/v1
kind: Deployment
metadata:
name: product-catalog-deployment
spec:
replicas: 3
selector:
matchLabels:
app: product-catalog
template:
metadata:
labels:
app: product-catalog
spec:
containers:
- name: product-catalog
image: your-registry/product-catalog:latest
ports:
- containerPort: 8080

Create Kubernetes Service resources to expose each microservice:

apiVersion: v1
kind: Service
metadata:
name: product-catalog-service
spec:
selector:
app: product-catalog
ports:
- protocol: TCP
port: 80
targetPort: 8080

5. Configure Ingress Resource:

Define the Ingress resource to route traffic:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: markethub-ingress
spec:
rules:
- host: store1.markethub.com
http:
paths:
- path: /catalog
pathType: Prefix
backend:
service:
name: product-catalog-service
port:
number: 80
- host: store2.markethub.com
http:
paths:
- path: /catalog
pathType: Prefix
backend:
service:
name: product-catalog-service
port:
number: 80

Apply the Ingress resource:

kubectl apply -f ingress.yaml

6. Obtain TLS Certificates:

  • Acquire TLS certificates for each domain using Let’s Encrypt or a similar service.
  • Store the TLS certificates securely in Kubernetes Secrets:
kubectl create secret tls markethub-tls-secret --key=key.pem --cert=cert.pem

7. Deploy Ingress Controller:

Install NGINX Ingress Controller using Helm:

helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
helm install nginx-ingress ingress-nginx/ingress-nginx

8. Apply Kubernetes Manifests:

Apply Kubernetes manifests for Deployments, Services, and Ingress:

kubectl apply -f product-catalog-deployment.yaml
kubectl apply -f product-catalog-service.yaml
kubectl apply -f ingress.yaml

9. Test and Monitor:

  • Access the MarketHub platform using the configured domain names.
  • Monitor the performance and reliability of the platform using Kubernetes monitoring tools like Prometheus and Grafana.

To access the “MarketHub: Microservices Marketplace” application deployed on Kubernetes, you’ll need to follow these steps:

1. Configure DNS:

  • Ensure that the DNS records for the domain names (store1.markethub.com and store2.markethub.com) point to the external IP address of your Kubernetes cluster.
  • You can do this by setting up DNS records with your domain registrar or DNS provider.

2. Obtain External IP Address:

Get the external IP address of your Kubernetes cluster. You can do this by running the following command:

kubectl get svc -n ingress-nginx
  • Look for the EXTERNAL-IP field of the service named nginx-ingress-controller. This IP address is where your Ingress controller is exposed.

3. Edit Hosts File (Optional):

  • If you don’t have DNS configured or want to test locally, you can edit your local hosts file to map the domain names to the external IP address. On Unix-based systems (like Linux or macOS), you can edit the /etc/hosts file. Add the following lines:
<EXTERNAL_IP> store1.markethub.com
<EXTERNAL_IP> store2.markethub.com

Replace <EXTERNAL_IP> with the actual external IP address obtained from the previous step.

4. Access the Application:

  • Open a web browser and navigate to store1.markethub.com/catalog or store2.markethub.com/catalog to access the Product Catalog for the respective stores.
  • You should see the MarketHub application with the product listings, and you can interact with the services such as browsing products, authenticating users, and placing orders.

5. TLS Encryption:

  • If TLS is enabled (which it should be for production environments), the connection to the application will be encrypted using HTTPS. Ensure that you’re accessing the application via https://store1.markethub.com/catalog or https://store2.markethub.com/catalog.

6. Testing and Troubleshooting:

  • Perform thorough testing to ensure that all functionalities work as expected.
  • If you encounter any issues, such as DNS resolution problems or errors in accessing the application, double-check your DNS settings, Ingress configurations, and networking setup.

If you found this guide helpful then do click on 👏 the button.

Follow for more Learning like this 😊

If there’s a specific topic you’re curious about, feel free to drop a personal note or comment. I’m here to help you explore whatever interests you!

Thanks for spending your valuable time learning to enhance your knowledge!

--

--

Nidhi Ashtikar

Experienced AWS DevOps professional with a passion for writing insightful articles.