<p>I am facing a &quot;CrashLoopBackoff&quot; error when I deploy a .Net Core API with <code>helm upgrade --install flextoeco .</code> :</p>
<pre><code>NAME                            READY   STATUS             RESTARTS        AGE
flextoecoapi-6bb7cdd846-r6c67   0/1     CrashLoopBackOff   4 (38s ago)     3m8s
flextoecoapi-fb7f7b556-tgbrv    0/1     CrashLoopBackOff   219 (53s ago)   10h
mssql-depl-86c86b5f44-ldj48     0/1     Pending  
</code></pre>
<p>I have run <code>ks describe pod flextoecoapi-6bb7cdd846-r6c67</code> and part of the output is as below :</p>
<pre><code>Events:
Type     Reason     Age                     From               Message
  ----     ------     ----                    ----               -------
  Normal   Scheduled  5m4s                    default-scheduler  Successfully assigned default/flextoecoapi-6bb7cdd846-r6c67 to fbcdcesdn02
  Normal   Pulling    5m3s                    kubelet            Pulling image &quot;golide/flextoeco:1.1.1&quot;
  Normal   Pulled     4m57s                   kubelet            Successfully pulled image &quot;golide/flextoeco:1.1.1&quot; in 6.2802081s
  Normal   Killing    4m34s                   kubelet            Container flextoeco failed liveness probe, will be restarted
  Normal   Created    4m33s (x2 over 4m57s)   kubelet            Created container flextoeco
  Normal   Started    4m33s (x2 over 4m56s)   kubelet            Started container flextoeco
  Normal   Pulled     4m33s                   kubelet            Container image &quot;golide/flextoeco:1.1.1&quot; already present on machine
  Warning  Unhealthy  4m14s (x12 over 4m56s)  kubelet            Readiness probe failed: Get &quot;http://10.244.6.59:80/&quot;: dial tcp 10.244.0.59:80: connect: connection refused
  Warning  Unhealthy  4m14s (x5 over 4m54s)   kubelet            Liveness probe failed: Get &quot;http://10.244.6.59:80/&quot;: dial tcp 10.244.0.59:80: connect: connection refused
  Warning  BackOff    3s (x10 over 2m33s)     kubelet            Back-off restarting failed container
</code></pre>
<p>Taking from the suggestions <a href="https://stackoverflow.com/questions/56001352/accessing-the-deployed-service-using-helm-chart-in-kubernetes-cluster?noredirect=1#comment98718941_56001352">here</a> it appears I have a number of options to fix most notable being:
i) Add a command to the Dockerfile that will ensure there is some foreground process running
ii)Extend the LivenessProbe <strong>initialDelaySeconds</strong></p>
<p>I have opted for the first and edited my Dockerfile as below :</p>
<pre><code>FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env
WORKDIR /app
# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore
# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out
# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:3.1
WORKDIR /app
ENV ASPNETCORE_URLS http://+:5000
COPY --from=build-env /app/out .
ENTRYPOINT [&quot;dotnet&quot;, &quot;FlexToEcocash.dll&quot;]
CMD tail -f /dev/null
</code></pre>
<p>After this change I am still getting the same error.</p>
<p><strong>UPDATE</strong></p>
<p>Skipped : The deployment works perfectly <em><strong>when I am not using helm i.e I can do a kubectl apply for the deployment/service/nodeport/clusterip and the API is deployed without issues</strong></em>.</p>
<p>I have tried to update values.yaml and service.yaml as below,  but after redeploy the CrashLoopBackOff error persists :</p>
<p><strong>templates/service.yaml</strong></p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: {{ include &quot;flextoeco.fullname&quot; . }}
  labels:
    {{- include &quot;flextoeco.labels&quot; . | nindent 4 }}
spec:
  type: {{ .Values.service.type }}
  ports:
    - port: {{ .Values.service.port }}
      targetPort: http
      protocol: TCP
      name: http
  selector:
    {{- include &quot;flextoeco.selectorLabels&quot; . | nindent 4 }}
</code></pre>
<p><strong>values.yaml</strong><br />
I have explicitly specified the CPU and memory usage here</p>
<pre><code>replicaCount: 1
image:
  repository: golide/flextoeco
  pullPolicy: IfNotPresent
  # Overrides the image tag whose default is the chart appVersion.
  tag: &quot;1.1.2&quot;

imagePullSecrets: []
nameOverride: &quot;&quot;
fullnameOverride: &quot;&quot;

serviceAccount:
  
podAnnotations: {}

podSecurityContext: {}
  # fsGroup: 2000

securityContext: {}
 
service:
  type: ClusterIP
  port: 80

ingress:
  enabled: false
  className: &quot;&quot;
  annotations: {}
    # kubernetes.io/ingress.class: nginx
    # kubernetes.io/tls-acme: &quot;true&quot;
  hosts:
    - host: flextoeco.local
      paths:
        - path: /
          pathType: ImplementationSpecific
  tls: []
  #  - secretName: chart-example-tls
  #    hosts:
  #      - chart-example.local

resources:
  limits:
    cpu: 1
    memory: 1Gi
  requests:
    cpu: 100m
    memory: 250Mi

autoscaling:
  enabled: false
  minReplicas: 1
  maxReplicas: 100
  targetCPUUtilizationPercentage: 80
  # targetMemoryUtilizationPercentage: 80

nodeSelector: {}
</code></pre>
<p><strong>templates/deployment.yaml</strong></p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include &quot;flextoeco.fullname&quot; . }}
  labels:
    {{- include &quot;flextoeco.labels&quot; . | nindent 4 }}
spec:
  {{- if not .Values.autoscaling.enabled }}
  replicas: {{ .Values.replicaCount }}
  {{- end }}
  selector:
    matchLabels:
      {{- include &quot;flextoeco.selectorLabels&quot; . | nindent 6 }}
  template:
    metadata:
      {{- with .Values.podAnnotations }}
      annotations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      labels:
        {{- include &quot;flextoeco.selectorLabels&quot; . | nindent 8 }}
    spec:
      {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      serviceAccountName: {{ include &quot;flextoeco.serviceAccountName&quot; . }}
      securityContext:
        {{- toYaml .Values.podSecurityContext | nindent 8 }}
      containers:
        - name: {{ .Chart.Name }}
          securityContext:
            {{- toYaml .Values.securityContext | nindent 12 }}
          image: &quot;{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}&quot;
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          ports:
            - name: http
 labels:
        {{- include &quot;flextoeco.selectorLabels&quot; . | nindent 8 }}
    spec:
      {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      serviceAccountName: {{ include &quot;flextoeco.serviceAccountName&quot; . }}
      securityContext:
        {{- toYaml .Values.podSecurityContext | nindent 8 }}
      containers:
        - name: {{ .Chart.Name }}
          securityContext:
            {{- toYaml .Values.securityContext | nindent 12 }}
          image: &quot;{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}&quot;
          imagePullPolicy: {{ .Values.image.pullPolicy }}
            ports:
            - name: http
              containerPort: 80
              protocol: TCP
          livenessProbe:
            tcpSocket:
              port: 8085
            initialDelaySeconds: 300
            periodSeconds: 30
            timeoutSeconds: 20
          readinessProbe:
            tcpSocket:
              port: 8085
            initialDelaySeconds: 300
            periodSeconds: 30
          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 }}
        {{- toYaml . | nindent 8 }}
      {{- end }}
</code></pre>

Golide
<p>In the Deployment spec, I need to use port 5000 as the containerPort: value and also the port: in the probes. My application is listening on port 5000 :</p>
<pre><code>   - name: http
          containerPort: 5000
          protocol: TCP
      livenessProbe:
        tcpSocket:
          port: 5000
        initialDelaySeconds: 300
        periodSeconds: 30
        timeoutSeconds: 20
      readinessProbe:
        tcpSocket:
          port: 5000
        initialDelaySeconds: 300
        periodSeconds: 30
</code></pre>
<p>The configuration in service.yaml is correct : If the Deployment spec maps the name http to port 5000 then referring to targetPort: http in the Service is right.</p>
