Pulumi infrastructure as code — Dockerize .netcore Web API app and deploy to EKS by Pulumi CSharp

Ha Doan
2 min readJan 8, 2020

--

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

  1. 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

curl http://localhost/api/todoquery/getsummary

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.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

No responses yet

Write a response