12

Deploying an ASP.NET Core App on Google Kubernetes Engine

 4 years ago
source link: https://sahansera.dev/deploying-aspcore-gcp/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Deploying an ASP.NET Core App on Google Kubernetes Engine

2019-12-25google cloud platform 3 min read

I recently started playing around with the Google Cloud Platform. Since ASP.NET Core now runs on virtually any major OS, I wanted to give it a go with GCP’s Google Kubernetes Engine offering to see whether we can use it to host a .NET Core application.

So here are the steps we are going to follow:

  1. Create/Clone a sample ASP.NET Core app
  2. Build the docker image
  3. Push the containerized app to Google Container Registry (GCR)
  4. Deploy the app to Google Kubernetes Engine (GKE)

First things first, what are the prerequisites?

1. Create/Clone a sample ASP.NET Core app

You can grab the ASP.NET Sample app from my Github Repo:

ASP.NET Core Food App

This app has nothing to do with food though 😁 Let’s just say I was hungry when creating it.

You can clone the above repo into your local machine and navigate to the FoodApp folder and publish the app to app/ folder from a command line:

cd FoodAppCore/FoodApp
dotnet restore
dotnet publish -o app 

2. Build the docker image

Don’t forget to replace PROJ_ID with your GCP project’s ID

Let’s build the docker image:

docker build -t gcr.io/PROJ_ID/food-app .

If you want to test out your docker build locally, try it by doing so:

docker run --rm -p 8080:8080 gcr.io/PROJ_ID/food-app:latest

3. Push the containerized app to Google Container Registry (GCR)

Let’s push our image to GCR:

docker push gcr.io/PROJ_ID/food-app

If you haven’t configured gcloud CLI to authenticate to GCR you need to run the following command (you need to this only once):

gcloud auth configure-docker

4. Deploy the app to Google Kubernetes Engine (GKE)

Next, we need to create a cluster in GKE to deploy our app to:

gcloud container clusters create foodapp-cluster --num-nodes=3

Finally, let’s deploy it to GKE:

kubectl create deployment food-app --image=gcr.io/PROJ_ID/food-app:latest

If the above command gives you an error, don’t forget to install kubectl for gcloud:

gcloud components install kubectl

Wait, now the app is deployed, how can our clients access it? This final command will expose our app through a load balancer binding port 8080 to 80

kubectl expose deployment food-app --type="LoadBalancer" --port=80 --target-port=8080

Well, that’s it! you have your app running in GKE! If you are wondering how to access it, run a kubectl get service and grab its external IP and paste it in a browser.

GKE Cluster

References


Recommend

  • 98
    • beckjin.com 6 years ago
    • Cache

    ASP.NET Core Filters

    ASP.NET MVC 中的过滤器(Filter)是 AOP(面向切面编程) 思想的一种实现,供我们在执行管道的特定阶段执行代码,通过使用过滤器可以实现 短路请求、缓存请求结果、日志统一记录、参数合法性验证、异常统一处理、返回值格式化 等等,同时...

  • 107
    • news.cnblogs.com 6 years ago
    • Cache

    ASP.NET Core值得学吗?

    连发了几篇ASP.NETCore文章,果不其然接到各方询问:「喵的妈呀,微软又推新东西了?」「WebForm玩完了吗?」「我ASP.NETMVC还没开始玩耶,是不是不用学了?」先简单答复以上疑问:是的,ASP.NETCore 是下一代的ASP.NET,能跨平台执行,预期是

  • 60
    • www.tuicool.com 6 years ago
    • Cache

    NHibernate on ASP.NET Core

    NHibernate has been my favorite ORM for long time. Although it’s more complex for beginners than Entity Framework it’s more matured and many developers consider it to be practially an industry standard. NHibernate works w...

  • 66
    • beckjin.com 6 years ago
    • Cache

    ASP.NET Core JWT 认证

    JWT (JSON Web Token)是一种开放标准,它以 JSON 对象的方式在各方之间安全地传输信息。通俗的说,就是通过数字签名算法生产一个字符串,然后在网络请求的中被携带到服务端进行身份认证,功能上来说和 S...

  • 60
    • www.cnblogs.com 5 years ago
    • Cache

    ASP.NET Core Web Api之JWT(一) - Jeffcky

    最近沉寂了一段,主要是上半年相当于休息和调整了一段时间,接下来我将开始陆续学习一些新的技术,比如Docker、Jenkins等,都会以生活实例从零开始讲解起,到时一并和大家分享和交流。接下来几节课的内容将会讲解JWT,关于JWT的原理解析等等...

  • 12
    • www.dontpanicblog.co.uk 4 years ago
    • Cache

    Deploying to Google Kubernetes Engine

    Previously we looked at building a Spring Cloud Data Flow on Kubernetes. As a follow up, we’re now looking at deploying to

  • 15

    TL;DR If you want to use Helm, but not Azure Dev Spaces. You can do it manually following

  • 12

    Deploying Ruby apps to Google Cloud Kubernetes Engine continuously with CircleCI — Martian Chronicles, Evil Martians’ team blogI hadn’t had a chance to try Kubernetes for a long time, but finally a few wee...

  • 9

    Side-note: this may be one of the clumsiest titles I’ve ever written for a blog post. But it does what it says on the tin. Oh, and the space after “ASP” in “ASP .NET Core” everywhere it to avoid auto-linking. While I could use a different dot...

  • 11

    #AkkaDotNET #Kubernetes #DotNetOn .NET Live - Deploying Akka.NET to Containers and Kubernetes

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK