Deploying ASP.NET Core apps on Kubernetes/Container Engine

In my previous post, I talked about how to deploy a containerised ASP.NET Core app to App Engine (flex) on Google Cloud. App Engine (flex) is an easy way to run containers in production: Just send your container and let Google Cloud figure out how to run it at scale. It comes with some nice default features such as versioning, traffic splitting, dashboards and autoscaling. However, it doesn’t give you much control.

Sometimes, you need to create a cluster of containers and control how each container is deployed and scaled. That’s when Kubernetes come into play. Kubernetes is an open source container management platform that helps you to manage a cluster of containers and Container Engine is Kubernetes managed by Google Cloud.

In this cloud minute, I show how to deploy an ASP.NET Core app to Kubernetes running on Container Engine.

If you want to go through these steps yourself, we also have a codelab for you that you can access here.

Advertisements

Google Container Engine

Untitled drawing

Container Engine is the third and last component of the Compute layer of Google Cloud Platform that I want to explore.

What is Container Engine?

  • Google Container Engine is a Google-hosted version of Kubernetes running on Compute Engine. 
  • Kubernetes is an open source orchestration system for Docker containers.
  • Basically, Container Engine enables you to host Docker containers with Kubernetes very easily. For more details, on why containers makes sense, see: An introduction to containers, Kubernetes, and the trajectory of modern cloud computing.
  • Most useful command lines tools for Container Engine:
    • gcloud: used to push Docker images, create cluster.
    • kubectl: used to send requests to Kubernetes cluster manager (eg. to create Kubernetes pods, services, get cluster info and scale up/down pods).

Container Engine App Lifecycle

These are roughly the steps you need to follow in order to host the app in a Kubernetes backed cluster in Container Engine for the first time:

  1. Create your app.
  2. Create a Docker image containing your app.
  3. Build Docker image and run it locally to make sure it works as expected.
  4. Push the Docker image to Google Container Registry.
  5. Create a Kubernetes cluster: A cluster consists of a master API server hosted by Google and a set of worker nodes which are Compute Engine VMs.
  6. Create a Kubernetes pod: A pod is a group of containers for Kubernetes to manage together, from the Docker image pushed earlier.
  7. Expose the pod as a Kubernetes service to make it accessible to the outside world.

If you need to update an existing app:

  1. Make the needed changes to your app.
  2. Build and test a new docker image locally.
  3. Push the new image to Google Container Registry.
  4. Do a rolling-update using kubectl command.

Resources