title: Asp.net Core get "Back-off restarting failed container" on AKS
body: <p>I am trying to deploy my very first and simple ASP.net Core Web Api on the AKS (ref to <a href="https://docs.microsoft.com/en-us/dotnet/architecture/containerized-lifecycle/design-develop-containerized-apps/build-aspnet-core-applications-linux-containers-aks-kubernetes" rel="nofollow noreferrer">this article</a>)</p>
  <p>Here is my yaml file</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>apiVersion: apps/v1
  kind: Deployment
  metadata:
    name: aexp
    labels:
      app: aexp
  spec:
    replicas: 1
    selector:
      matchLabels:
        service: aexp
    template:
      metadata:
        labels:
          app: aexp
          service: aexp
      spec:
        containers:
          - name: aexp
            image: f2021.azurecr.io/aexp:v1
            imagePullPolicy: Always
            ports:
              - containerPort: 80
                protocol: TCP
            env:
              - name: ASPNETCORE_URLS
                value: http://+:80
  ---
  apiVersion: v1
  kind: Service
  metadata:
    name: aexp
    labels:
      app: aexp
      service: aexp
  spec:
    ports:
      - port: 80
        targetPort: 80
        protocol: TCP
    selector:
      service: aexp</code></pre>
  </div>
  </div>
  </p>
  <p>It looks simple and straightforward, but I couldn't figure out why my pod gets Back-off restarting failed container. Any advice a clue to prevent the error? thanks in advance.</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>Name:         aexp-5b5b7b6464-5lfz4
  Namespace:    default
  Priority:     0
  Node:         aks-nodepool1-38572550-vmss000000/10.240.0.4
  Start Time:   Wed, 20 Jan 2021 10:01:52 +0700
  Labels:       app=aexp
                pod-template-hash=5b5b7b6464
                service=aexp
  Annotations:  &lt;none&gt;
  Status:       Running
  IP:           10.244.0.14
  IPs:
    IP:           10.244.0.14
  Controlled By:  ReplicaSet/aexp-5b5b7b6464
  Containers:
    aexp:
      Container ID:   docker://25ffdb3ce92eeda465e1971daa363d6f532ac73ff82df2e9b3694a8949f50615
      Image:          f2021.azurecr.io/aexp:v1
      Image ID:       docker-pullable://f2021.azurecr.io/aexp@sha256:bf6aa2a47f5f857878280f5987192f1892e91e365b9e66df83538109b9e57c46
      Port:           80/TCP
      Host Port:      0/TCP
      State:          Waiting
        Reason:       CrashLoopBackOff
      Last State:     Terminated
        Reason:       Completed
        Exit Code:    0
        Started:      Wed, 20 Jan 2021 10:33:47 +0700
        Finished:     Wed, 20 Jan 2021 10:33:47 +0700
      Ready:          False
      Restart Count:  11
      Environment:
        ASPNETCORE_URLS:  http://+:80
      Mounts:
        /var/run/secrets/kubernetes.io/serviceaccount from default-token-g4ks9 (ro)
  Conditions:
    Type              Status
    Initialized       True
    Ready             False
    ContainersReady   False
    PodScheduled      True
  Volumes:
    default-token-g4ks9:
      Type:        Secret (a volume populated by a Secret)
      SecretName:  default-token-g4ks9
      Optional:    false
  QoS Class:       BestEffort
  Node-Selectors:  &lt;none&gt;
  Tolerations:     node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                   node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
  Events:
    Type     Reason     Age                  From               Message
    ----     ------     ----                 ----               -------
    Normal   Scheduled  36m                  default-scheduler  Successfully assigned default/aexp-5b5b7b6464-5lfz4 to aks-nodepool1-38572550-vmss000000
    Normal   Pulled     35m (x4 over 36m)    kubelet            Successfully pulled image "f2021.azurecr.io/aexp:v1"
    Normal   Created    35m (x4 over 36m)    kubelet            Created container aexp
    Normal   Started    35m (x4 over 36m)    kubelet            Started container aexp
    Normal   Pulling    34m (x5 over 36m)    kubelet            Pulling image "f2021.azurecr.io/aexp:v1"
    Warning  BackOff    62s (x166 over 36m)  kubelet            Back-off restarting failed container</code></pre>
  </div>
  </div>
  </p>
  <p>And here is my az snippet to create AKS cluster</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>az aks create \
    --location $REGION \
    --resource-group $AKS_RG \
    --name $AKS_NAME \
    --ssh-key-value ./.ssh/id_rsa.pub \
    --service-principal "xxxxxxxx-b8d1-4206-8a8a-xxxxx66c086c" \
    --client-secret "xxxx.xxxxeNzq25iJeuRjWTh~xxxxxUGxu" \
    --network-plugin kubenet \
    --load-balancer-sku basic \
    --outbound-type loadBalancer \
    --node-vm-size Standard_B2s \
    --node-count 1 \
    --tags 'ENV=DEV' 'SRV=EXAMPLE'  \
    --generate-ssh-keys</code></pre>
  </div>
  </div>
  </p>
  <p>Update 1:
  I try with VS2019, start Debug using “Bridge to Kubernetes”, then it works, the same docker image, same deployment and same service.</p>
  <p>Update 2: add docker file</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
  
  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
  WORKDIR /src
  COPY ["Aexp/Aexp.csproj", "Aexp/"]
  RUN dotnet restore "Aexp/Aexp.csproj"
  COPY . .
  WORKDIR "/src/Aexp"
  RUN dotnet build "Aexp.csproj" -c Release -o /app/build
  
  FROM build AS publish
  RUN dotnet publish "Aexp.csproj" -c Release -o /app/publish
  
  FROM base AS final
  WORKDIR /app
  COPY --from=publish /app/publish .
  ENTRYPOINT ["dotnet", "Aexp.dll"]</code></pre>
  </div>
  </div>
  </p>
  <p>Update 3 [Jan 27] : I figured out the issue doesn't relate to my code or my yaml, at all. I have 02 <strong>azure subscriptions</strong>, one got the issue, one is working just fine with the same code, same deployment.yaml and configuration.</p>