How do I publish .NET Core to Digital Ocean Kubernetes

4/26/2019

I am trying to publish a .NET Core Web App and a .NET Core API.

I have been googling and can't find a way to deploy 1 let alone 2 .NET Core apps to a Digital Ocean Kubernetes Cluster, I have 2 nodes and have created a valid manifest and build a Docker image locally and it seems to pass the validation. But I can't actually deploy it. I'm new to Kubernetes and anything I find seems to be related to Google's Kubernetes or Azure Kubernetes.

I don't, unfortunately, have more information than this.

-- Max
.net-core
digital-ocean
kubernetes

1 Answer

8/4/2019

I have one. Weird thing is that DO is actually smart to not have docs since it doesn't have to. You can recycle Google's and Azure's K8 documentation to work on your DO cluster. The key difference is only in the namings I suppose, there could be more differentiations but so far, I haven't met a single problem while applying instructions from GCP's docs.

https://nozomi.one is running on DO's k8 cluster.

Here's an awesome-dotnetcore-digitalocean-k8 for you.

Errors you may/will face:

Push the secret file here (Recommended only for staging or below, unless you have a super secret way to deploy this):

kubectl create secret generic secret-appsettings --from-file=./appsettings.secrets.json

And then create a deployment configuration similar to this. Notice that we've added the appsettings at the last few lines:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: xxxxx
spec:
  replicas: 3
  template:
    metadata:
      labels:
        app: xxxxx
    spec:
      containers:
      - name: xxxxx
        image: xxxxx/xxxxxx:latest
        ports:
        - containerPort: 80
        env:
        - name: "ASPNETCORE_ENVIRONMENT"
          value: "Production"
        volumeMounts:
        - name: secrets
          mountPath: /app/secrets
          readOnly: true
      volumes:
      - name: secrets
        secret:
          secretName: secret-appsettings

Deploying this script is as simple as:

kubectl create -f deployment.yaml

And if you want to test locally in docker first:

docker run --rm -p 8080:8080 gcr.io/${PROJECT_ID}/test-app:v1

All in all, everything above will help you to deploy your pods.

You need to understand that deploying a new project/app works in this systematic way:

  1. Create a deployment, which is something that pulls the image for you and creates pods that will be deployed to the nodes.
  2. Create a service, that will point proper ports and more (Never tried to do more lol) to your app/s.

This is how a service looks like:

apiVersion: v1
kind: Service
metadata:
  name: nozweb
spec:
  type: LoadBalancer
  ports:
  - name: http
    port: 80
    protocol: TCP
    targetPort: 80
  - name: https
    port: 443
    protocol: TCP
    targetPort: 80
  selector:
    app: nozweb

Always ensure that spec:selector:app is specifically following:

spec:
  replicas: 3
  template:
    metadata:
      labels:
        app: xxxxx

In your deployment configuration. That's how they symlink.

  1. Create an ingress (Optional) that will help act as a reverse proxy to your .NET Core app/project. This is optional because we got kestrel running!
-- Nicholas
Source: StackOverflow