Deploying .NET Core APIs Locally with Kubernetes and Helm

Deploy .NET Core APIs with Kubernetes & Helm - Step-by-Step Guide

Kubernetes (K8s) is an open-source container orchestration platform that automates the deployment, scaling, and management of containerized applications. Helm is a package manager for Kubernetes that helps define, install, and upgrade applications efficiently.

In this guide, we will:

✅ Install Kubernetes and Helm on a local cluster
✅ Deploy .NET Core APIs using Helm charts
✅ Monitor services with K9s and Prometheus


1. Installing Kubernetes and Helm on a Local Cluster

1.1 Prerequisites

Ensure you have the following installed on your system:

  • Docker (for running containers)
  • Minikube or Kind (for local Kubernetes cluster setup)
  • Kubectl (command-line tool for Kubernetes)
  • Helm (package manager for Kubernetes)

1.2 Setting Up Kubernetes Locally with Minikube

To install Minikube:

curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube

Start a Minikube cluster:

minikube start --cpus 2 --memory 4096

Verify the installation:

kubectl cluster-info

1.3 Installing Helm

Download and install Helm:

curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash

Verify Helm installation:

helm version

2. Deploying .NET Core APIs Using Helm Charts

2.1 Creating a Sample .NET Core API

Create a new .NET Web API project:

dotnet new webapi -n SampleApi
cd SampleApi

Build the Docker image:

docker build -t sample-api .

Push the image to a local registry or Docker Hub:

docker tag sample-api localhost:5000/sample-api

2.2 Writing a Helm Chart for Deployment

Create a new Helm chart:

helm create sample-chart
cd sample-chart

Modify values.yaml to configure the container image:

image:
  repository: localhost:5000/sample-api
  tag: latest
service:
  type: ClusterIP
  port: 80

Deploy the API using Helm:

helm install sample-api ./sample-chart

Check the deployment:

kubectl get pods

3. Monitoring Services with K9s and Prometheus

3.1 Installing K9s

K9s is a terminal-based UI for managing Kubernetes clusters:

curl -sS https://webinstall.dev/k9s | bash

Run K9s:

k9s

3.2 Installing Prometheus for Monitoring

Add the Prometheus Helm repository:

helm repo add prometheus-community https://prometheus-community.github.io/helm-charts

Install Prometheus:

helm install prometheus prometheus-community/kube-prometheus-stack

Access Prometheus:

kubectl port-forward svc/prometheus-kube-prometheus-stack-prometheus 9090

Conclusion

In this guide, we covered:

✅ Setting up Kubernetes and Helm locally
✅ Deploying a .NET Core API using Helm charts
✅ Monitoring services with K9s and Prometheus

Using Kubernetes and Helm, developers can easily deploy and manage .NET Core APIs locally before moving them to production environments. 🚀

Sandip Mhaske

I’m a software developer exploring the depths of .NET, AWS, Angular, React, and digital entrepreneurship. Here, I decode complex problems, share insightful solutions, and navigate the evolving landscape of tech and finance.

Post a Comment

Previous Post Next Post