Introduction
In this article, we will discuss the basics and use cases of ingress. Also, step-by-step implementation and configuration of different services with the help of the .NET Core 8 Web API, Docker, Kubernetes, and Ingress.
Agenda
- What is NGINX Ingress?
- Use cases for NGINX Ingress
- Implementation of Services using the .NET Core 8 Web API
- Containerization of Services and NGINX Ingress Configuration.
Prerequisites
- Visual Studio 2022
- .NET Core 8 SDK
- Docker and Kubernetes
What is NGINX Ingress?
In simple terms, Nginx Ingress is a way to manage incoming internet traffic to your web applications or services. Think of it as a traffic cop for your web servers. It sits in front of your applications and directs traffic, like a router for web requests.

Fig Ref- docs.nginx.com
Nginx Ingress examines incoming requests and decides where to send them based on the rules you define. This could mean directing requests to different services based on the requested URL or other criteria. It can also handle things like load balancing, SSL termination (decrypting HTTPS traffic), and other tasks related to managing incoming web traffic.
Overall, Nginx Ingress helps you efficiently manage and route web traffic to your applications, improving performance, security, and scalability.
Use cases for NGINX Ingress
Following are a few use cases for Ingress
- Load Balancing: Spread incoming web traffic evenly across multiple servers to prevent overloading and ensure better performance.
- Routing: Direct web requests to different parts of your application based on factors like URLs or domain names.
- SSL Termination: Manage HTTPS encryption and decryption centrally to secure web traffic without burdening individual servers.
- Virtual Hosting: Host multiple websites or applications on the same servers, each with its own domain name.
- Authentication and Authorization: Control access to your applications based on user credentials or permissions before requests reach the servers.
- Rate Limiting: Limit the number of requests from individual clients or IP addresses to prevent abuse or overuse of services.
- Web Application Firewall (WAF): Protect applications from common web security threats by inspecting and filtering incoming traffic based on predefined security rules.
Implementation of Services using .NET Core 8 Web API
Step 1. Create a new Product class.
Product Service
namespace ProductAPI.Models
{
public class Product
{
public int Id { get; set; }
public string Name { get; set; }
public decimal Price { get; set; }
}
}
Step 2. Add a new product controller with different endpoints.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using ProductAPI.Models;
namespace ProductAPI.Controllers
{
[ApiController]
[Route("[controller]")]
public class ProductsController : ControllerBase
{
private static List<Product> _products = new List<Product>
{
new Product { Id = 1, Name = "Product 1", Price = 10.99m },
new Product { Id = 2, Name = "Product 2", Price = 20.49m }
};
private readonly ILogger<ProductsController> _logger;
public ProductsController(ILogger<ProductsController> logger)
{
_logger = logger;
}
[HttpGet]
public IEnumerable<Product> Get()
{
return _products;
}
[HttpGet("{id}")]
public ActionResult<Product> Get(int id)
{
var product = _products.FirstOrDefault(p => p.Id == id);
if (product == null)
{
return NotFound();
}
return product;
}
[HttpPost]
public ActionResult<Product> Post(Product product)
{
product.Id = _products.Count + 1;
_products.Add(product);
return CreatedAtAction(nameof(Get), new { id = product.Id }, product);
}
[HttpPut("{id}")]
public IActionResult Put(int id, Product product)
{
var existingProduct = _products.FirstOrDefault(p => p.Id == id);
if (existingProduct == null)
{
return NotFound();
}
existingProduct.Name = product.Name;
existingProduct.Price = product.Price;
return NoContent();
}
[HttpDelete("{id}")]
public IActionResult Delete(int id)
{
var product = _products.FirstOrDefault(p => p.Id == id);
if (product == null)
{
return NotFound();
}
_products.Remove(product);
return NoContent();
}
}
}
Step 3. Register the services and middleware in the program class.
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
// Configure the HTTP request pipeline.
app.UseSwagger();
app.UseSwaggerUI();
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();

User Service
Step 1. Create a new User class.
namespace UserAPI.Models
{
public class User
{
public int Id { get; set; }
public string Name { get; set; }
public string Email { get; set; }
}
}
Step 2. Add a new user controller with different endpoints.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using UserAPI.Models;
namespace UserAPI.Controllers
{
[ApiController]
[Route("[controller]")]
public class UsersController : ControllerBase
{
private static List<User> _users = new List<User>
{
new User { Id = 1, Name = "User 1", Email = "[email protected]" },
new User { Id = 2, Name = "User 2", Email = "[email protected]" }
};
private readonly ILogger<UsersController> _logger;
public UsersController(ILogger<UsersController> logger)
{
_logger = logger;
}
[HttpGet]
public IEnumerable<User> Get()
{
return _users;
}
[HttpGet("{id}")]
public ActionResult<User> Get(int id)
{
var user = _users.FirstOrDefault(u => u.Id == id);
if (user == null)
{
return NotFound();
}
return user;
}
[HttpPost]
public ActionResult<User> Post(User user)
{
user.Id = _users.Count + 1;
_users.Add(user);
return CreatedAtAction(nameof(Get), new { id = user.Id }, user);
}
[HttpPut("{id}")]
public IActionResult Put(int id, User user)
{
var existingUser = _users.FirstOrDefault(u => u.Id == id);
if (existingUser == null)
{
return NotFound();
}
existingUser.Name = user.Name;
existingUser.Email = user.Email;
return NoContent();
}
[HttpDelete("{id}")]
public IActionResult Delete(int id)
{
var user = _users.FirstOrDefault(u => u.Id == id);
if (user == null)
{
return NotFound();
}
_users.Remove(user);
return NoContent();
}
}
}











Arun RamaswamyPosted May 6, 2024, 3:32 PM
Informative indeed
Sarthak VarshneyPosted May 6, 2024, 11:50 AM
Nice Article :)