This project demonstrates the deployment of a .NET 7 application on Kubernetes using AWS Elastic Kubernetes Service (EKS) and Docker. Follow the steps below to clone the repository, build and run the application, and deploy it to AWS.
- Git: Version control system
- GitHub Desktop: Git client for desktop
- Visual Studio: IDE for .NET development
- PowerShell: Command-line shell
- .NET 7 SDK: Development platform for building applications
git clone https://github.com/atulkamble/k8s-application-deployment-aws-eks-ecr.git
cd k8s-application-deployment-aws-eks-ecr
- Open the solution file within the
k8s-App-EKS
directory using Visual Studio. - Run the project from Visual Studio to ensure it works correctly.
- If you make any changes, commit them to the same repository:
git add .
git commit -m "Your commit message"
git push origin main
- If you encounter any issues, raise them in the repository's issue tracker.
- Reference: Build a .NET Core Docker Container
cd k8s-App-EKS
dotnet publish -c Release
- The following paths will be created:
k8s-App
->D:\GitHub\k8s-App-EKS\k8s-App\k8s-App\bin\Release\net7.0\k8s-App.dll
k8s-App
->D:\GitHub\k8s-App-EKS\k8s-App\k8s-App\bin\Release\net7.0\publish\
Navigate to the project directory and create a Dockerfile:
cd D:\GitHub\k8s-App-EKS\k8s-App\k8s-App
New-Item Dockerfile
code Dockerfile
Paste the following code into the Dockerfile:
# Use the official .NET SDK image to build the application
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build-env
WORKDIR /App
# Copy all files to the container
COPY . ./
# Restore dependencies
RUN dotnet restore
# Build and publish the application
RUN dotnet publish -c Release -o out
# Use the official ASP.NET runtime image for running the application
FROM mcr.microsoft.com/dotnet/aspnet:7.0
WORKDIR /App
COPY --from=build-env /App/out .
ENTRYPOINT ["dotnet", "k8s-App.dll"]
- Build the Docker image:
docker build -t counter-image -f Dockerfile .
- Start Docker Engine and list Docker images:
docker images
- Create a container from the image:
docker create --name core-counter counter-image
- List all containers:
docker ps -a
- Manage the container:
docker start core-counter
docker ps
- Stop the container:
docker stop core-counter
docker ps
- Connect to the container:
docker attach --sig-proxy=false core-counter
- Delete the container:
docker stop core-counter
docker rm core-counter
- Run the container interactively:
docker run -it --rm counter-image
- Sign in to AWS IAM, create a user, group, and assign policies.
- Configure AWS CLI:
aws configure
- Authenticate Docker with AWS ECR:
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 316290926278.dkr.ecr.us-east-1.amazonaws.com
- Tag the Docker image:
docker tag counter-image:latest 316290926278.dkr.ecr.us-east-1.amazonaws.com/counter-image:latest
- Push the Docker image to ECR:
docker push 316290926278.dkr.ecr.us-east-1.amazonaws.com/counter-image:latest
By following these steps, you will have successfully Dockerized your .NET 7 application, built a Docker image, and pushed it to AWS ECR for deployment on AWS EKS.