1
votes

I upgraded my .Net Core 2.1 to 3.1. After upgrade Liveness and Readiness probe to pods failed. Below is my docker file snippet:

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
ENTRYPOINT ["dotnet", "Web.dll"]

When I check logs of the pod I get below errors:

Unable to bind to http://localhost:5000 on the IPv6 loopback interface: 'Cannot assign requested address'

Liveness probe failed: Get http://yyyy:80/: dial tcp yyyy:80: connect: connection refused

Here is my Deployment.yaml file:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "staging.fullname" . }}
  namespace: staging
  labels:
    app.kubernetes.io/name: {{ include "staging.name" . }}
    helm.sh/chart: {{ include "staging.chart" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      app.kubernetes.io/name: {{ include "staging.name" . }}
      app.kubernetes.io/instance: {{ .Release.Name }}
  template:
    metadata:
      labels:
        app.kubernetes.io/name: {{ include "staging.name" . }}
        app.kubernetes.io/instance: {{ .Release.Name }}
    spec:
      imagePullSecrets:
        - name: {{ .Values.image.pullSecret }}
      containers:
        - name: {{ .Chart.Name }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          ports:
            - name: http
              containerPort: 80
              protocol: TCP
          env:
            - name: ASPNETCORE_ENVIRONMENT
              value: "Staging"
          livenessProbe:
            httpGet:
              path: /
              port: http
          readinessProbe:
            httpGet:
              path: /
              port: http
            initialDelaySeconds: 10  
          resources:
            {{- toYaml .Values.resources | nindent 12 }}
      {{- with .Values.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
    {{- with .Values.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
    {{- end }}
    {{- with .Values.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
    {{- end }}
1
provide complete deployment file with service and podArghya Sadhu
@ArghyaSadhu Added deployment.yaml file contentUser3250
try binding to 127.0.0.1 instead of localhostMatt
@HelloWorld Which place should I make that change? Just FYI now where I've mentioned in project to use url "localhost:5000".User3250
ok, so your app is working on port 5000 not 80. So first of all bind your app to 0.0.0.0:5000 and not to localhost:5000 so that its accessible from outside of the pod and also set your healthcheck to port 5000, not port 80Matt

1 Answers

4
votes

The issue was that kestrel server for .NET Core 3.1 was pointing to localhost instead of 0.0.0.0. Hence, wasn't accessible from outside. Which is why liveness and readiness probes were failing.

To change url from localhost to 0.0.0.0 I needed to add below section in appsettings.json:

"Kestrel": {
    "EndPoints": {
      "Http": {
        "Url": "http://0.0.0.0:5000"
      }
    }
  }

Note: UseUrl() method or setting environment variable ASPNETCORE_URLS doesn't work for .NET Core 3.1.