0

Background

I am using Docker for Windows v20.10.6 (with Kubernetes enabled).

I have created two simple, out-of-the-box .NET 5.0 applications:

1. Web API (reaching through HTTP, listening on port 7070)

2. Web App (MVC) that shows a parsed table from the Web API (listening on port 80)

A. ✔️ Created a connection between the applications using Docker Swarm Mode

  1. Created a swarm using docker swarm init
  2. Created an 'overlay' driver network named personal-overlay.
  3. Created the Web API service using docker service create –-network personal-overlay --name api webapi
  4. Created the Web App service using docker service create --name web –-network personal-overlay -p 30080:80 webapp

B. ✔️ Created a generic NGINX deployment and service

  • deployment:
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    tier: frontend
spec:
  selector:
    matchLabels:
      app: myapp
  replicas: 1
  template:
    metadata:
      name: nginx
      labels:
        app: myapp
    spec:
      containers:
        - name: nginx
          image: nginx
  • service:
apiVersion: v1
kind: Service
metadata:
  name: nginx-service
spec:
  type: NodePort
  ports:
    - targetPort: 80
      port: 80
      nodePort: 30080
  selector:
    app: myapp

I could access the NGINX through http://localhost:30080 without an issue (using the web browser).

❌ The issue I'm currently facing

  1. Tagged the images test/api and test/web
  2. Created the same files using those Visual Studio images:
  • deployment:
apiVersion: apps/v1
kind: Deployment
metadata:
  name: test-deployment
  labels:
    tier: frontend 
spec:
  selector:
    matchLabels:
      app: myapp
  replicas: 1
  template:
    metadata:
      name: test-pod
      labels:
        app: myapp
    spec:
      containers:
        - name: api
          image: test/api
          imagePullPolicy: Never
        - name: web
          image: test/web
          imagePullPolicy: Never
  • service:
apiVersion: v1
kind: Service
metadata:
  name: test-service
spec:
  type: NodePort
  ports:
    - targetPort: 80
      port: 80
      nodePort: 30080
  selector:
    app: myapp

Yet, I can not access http://localhost:30080.

EDIT [1]:

I am trying to access it through the web browser, and I get an HTTP ERROR 500: "Failed to load resource: the server responded with a status of 500 (Internal Server Error)."

Whenever I am using curl -I http://localhost:30080 I get the following response:

HTTP/1.1 500 Internal Server Error
Date: Thu, 13 May 2021 08:20:25 GMT
Server: Kestrel
Content-Length: 0

EDIT [2]:

I even tried to scale it down into just this one pod (the web application).

  • pod:
apiVersion: v1
kind: Pod
metadata:
  name: consumer-pod
  labels:
    name: consumer-pod
    app: api-and-consumer
spec:
  containers:
    - name: consumer
      image: test/web
      imagePullPolicy: Never
      ports:
        - containerPort: 80
  • service:
apiVersion: v1
kind: Service
metadata:
  name: consumer-external-svc
  labels:
    name: consumer-external-svc
    app: api-and-consumer
spec:
  type: NodePort
  ports:
  - port: 80
    targetPort: 80
    nodePort: 30080
  selector:
    name: consumer-pod
    app: api-and-consumer

Yet it does not work (with nor without the ports section at the pod YAML file). These are the logs I get using the kubectl logs web-pod-<fullname> command (which says it is actually listening on port 80):

←[40m←[1m←[33mwarn←[39m←[22m←[49m: Microsoft.AspNetCore.DataProtection.Repositories.FileSystemXmlRepository[60]
      Storing keys in a directory '/root/.aspnet/DataProtection-Keys' that may not be persisted outside of the container. Protected data will be unavailable when container is destroyed.
←[40m←[1m←[33mwarn←[39m←[22m←[49m: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[35]
      No XML encryptor configured. Key {70ddc140-9846-4052-b869-8bcc5250d39e} may be persisted to storage in unencrypted form.
←[40m←[32minfo←[39m←[22m←[49m: Microsoft.Hosting.Lifetime[0]
      Now listening on: http://[::]:80
←[40m←[32minfo←[39m←[22m←[49m: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
←[40m←[32minfo←[39m←[22m←[49m: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Production
←[40m←[32minfo←[39m←[22m←[49m: Microsoft.Hosting.Lifetime[0]
      Content root path: /app

I should also mention that using kubectl cluster-info dump I get the following line (for the service though, not the pod itself):

time="2021-05-13T10:56:35Z" level=error msg="Port 30080 for service web-external-svc is already opened by another service"
Erelephant
  • 111
  • 9
  • you can't access `http://localhost:30080`. What error did you get? Timeout? Not found? How did you check it? With browser? Or maybe from terminal command - `curl`? Did you use Docker Desktop? Please clarify this by editing your question. – Mikołaj Głodziak May 12 '21 at 10:23
  • @MikołajGłodziak Thank you for clarifying that. I am using Docker for Windows (with Kubernetes enabled). I'm trying to access it using the web browser, getting `HTTP ERROR 500`. – Erelephant May 12 '21 at 12:34
  • thanks for adding more info. Did you check [container logs](https://kubernetes.io/docs/reference/kubectl/cheatsheet/#interacting-with-running-pods)? You may find there more information about the issue. Please edit your question again and paste output of logs from your deployment and service. – Mikołaj Głodziak May 13 '21 at 10:45
  • @MikołajGłodziak Edited accordingly (edit [2]). – Erelephant May 13 '21 at 10:56
  • If you want to access your app through `NodePort` you need to use: `http://{node ip}:{node port}`. [Here](https://stackoverflow.com/a/53105856/15407542) is the similar problem. Did you try to change `NodePort` to `LoadBalancer`? It is also possible that problem is in your .NET app. [Look here](https://stackoverflow.com/questions/64214061/500-internal-server-error-docker-hosted-asp-net-mvc-web-app-resolved). – Mikołaj Głodziak May 13 '21 at 14:31

0 Answers0