<p>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:</p>

<pre><code>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"]
</code></pre>

<p>When I check logs of the pod I get below errors:</p>

<blockquote>
  <p>Unable to bind to <a href="http://localhost:5000" rel="nofollow noreferrer">http://localhost:5000</a> on the IPv6 loopback interface: 'Cannot assign requested address'</p>
  
  <p>Liveness probe failed: Get <a href="http://yyyy:80/" rel="nofollow noreferrer">http://yyyy:80/</a>: dial tcp yyyy:80: connect: connection refused</p>
</blockquote>

<p>Here is my <strong>Deployment.yaml</strong> file:</p>

<pre><code>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 }}
</code></pre>

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

<p>To change url from <code>localhost</code> to <code>0.0.0.0</code> I needed to add below section in <code>appsettings.json</code>:</p>

<pre><code>"Kestrel": {
    "EndPoints": {
      "Http": {
        "Url": "http://0.0.0.0:5000"
      }
    }
  }
</code></pre>

<p><strong>Note:</strong> <code>UseUrl()</code> method or setting environment variable <code>ASPNETCORE_URLS</code> doesn't work for .NET Core 3.1.</p>
