Pulumi infrastructure as code — Dockerize .netcore Web API app and deploy to EKS by Pulumi CSharp
- Get source from https://github.com/hadoan/handon-blogs/tree/master/CqrsTodo
- Create Dockerfile by visual studio

- Create a repository in Amazon ECR https://aws.amazon.com/ecr/
- Build and push Docker container to AWS ECR
docker build -t cqrstodo .
docker tag cqrstodo your-account-id.dkr.ecr.ap-southeast-1.amazonaws.com/your-repo-name:cqrstodo
docker push your-account-id.dkr.ecr.ap-southeast-1.amazonaws.com/your-repo-name
The docker push command will ask you to log in to Amazon ECR if you didn’t log in from command line, in order to login you need to install aws-cli https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html and run a command
aws ecr get-login — no-include-email
- If you push docker successfully, you can see this image when you log in to your repository

- Create new Pulumi CSharp by command
pulumi new kubernestes-csharp
- Install Pulumi.Aws package by run command
dotnet add package Pulumi.Aws
pulumi plugin install resource aws v1.18.0-alpha.1578054313+gef1c8dd3
Steps to deploy to EKS by Pulumi CSharp
- Get existed cluster from EKS, if you don’t have EKS cluster you can create a new one from https://docs.aws.amazon.com/eks/latest/userguide/create-cluster.html
var existedCluster = Pulumi.Aws.Eks.Cluster.Get(“your-eks-cluster”, “your-eks-cluster”);
2. Create new deployment
https://gist.github.com/hadoan/8e27fbecc139ab32dc4c47efcba6d9f8
4. Run deployment by pulumi up command

Pulumi ask for confirmation, select Yes to deploy and you get this result

4. To check deployment run command
kubectl get pods

Then remote into the running pod by this command
kubectl exec -it cqrstodo-deployment-58bfb68d76-vlvmm — /bin/bash
Inside pod’s shell, run this command to test webapi app
You can access source-code at https://github.com/hadoan/handon-blogs/tree/master/pulumi-k8s
That’s all for Pod deployment, in the next blog I’ll demo how to and NGINX Ingress controller and expose API to the internet.