0

I have a .Net Worker service that runs as a K8S Cronjob but when it starts up it is failing to mount the appsettings file. The pod remains stuck in CrashLoopBackoff error state and the logs have the following :

Error: failed to create containerd task: OCI runtime create failed: container_linux.go:380: starting container process caused: process_linux.go:545: container init caused: rootfs_linux.go:76: mounting "/var/lib/kubelet/pods/axxxxxx-1xxxx-4xxx-8xxx-4xxxxxxxxxx/volume-subpaths/secrets/ftp-client/1" 

to rootfs at "/app/appsettings.ftp.json" caused: mount through procfd: not a directory: unknown

In the deployment I have mounted the appsettings file as follows :

apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: ftp-client

spec:
  schedule: "*/6 * * * *" #Cron job everyday 6 minutes
  # startingDeadlineSeconds: 60
  concurrencyPolicy: Forbid
  successfulJobsHistoryLimit: 1
  failedJobsHistoryLimit: 1
  jobTemplate:
    spec:
      template:
        spec:
          affinity:
            podAffinity:
              requiredDuringSchedulingIgnoredDuringExecution:
                - labelSelector: 
                    matchLabels:
                      app.kubernetes.io/name: taat
                  topologyKey: "kubernetes.io/hostname"
          initContainers:
            - name: ftp-backup
              image: registry.xxx.com/xxx/xxx:latest-ftp
              imagePullPolicy: "Always"
              env:
                - name: WEB_URL
                  valueFrom: 
                    secretKeyRef:
                      key: url
                      name: web-url
              volumeMounts:
                - mountPath: /tmp
                  name:  datadir
              command: ['sh', '-c',"./myscript.sh"]
          containers:
            - name: ftp-client
              image: registry.xxx.com/xxx/xxx:latest-ftp
              imagePullPolicy: "Always" 
              resources:
                limits:
                  memory: 500Mi
                requests:
                  cpu: 100m
                  memory: 128Mi        
              volumeMounts:
                - mountPath: /tmp
                  name:  datadir
                - mountPath: /app/appsettings.ftp.json
                  subPath: appsettings.ftp.json
                  name: secrets
              env:
                - name: DOTNET_ENVIRONMENT
                  value: "Development"
                - name: DOTNET_HOSTBUILDER__RELOADCONFIGONCHANGE
                  value: "false"

          restartPolicy: OnFailure
          imagePullSecrets:
            - name: mycredentials
          volumes:
            - name: datadir
              persistentVolumeClaim:
                claimName: labs
            - name: secrets
              secret:
                secretName: ftp-secret

And Program.cs for the Worker Service

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using FtpClientCron;

IHost host = Host.CreateDefaultBuilder(args)
    .ConfigureServices(services =>
    {
        services.AddHostedService<Worker>();
    })
    .Build();

await host.RunAsync();

appsettings.ftp.json

{
"ApplicationSettings": {
  "UserOptions": {
    "Username": "xxxxxx",
    "Password": "xxxxxxxxx",
    "Url": "xxx.xxx.com",
    "Port": "xxxx"
  }
}

 }

appsettings.json

{
"Logging": {
  "LogLevel": {
    "Default": "Information",
    "Microsoft.Hosting.Lifetime": "Information"
  }
}

 }

Dockerfile

FROM mcr.microsoft.com/dotnet/runtime:6.0 AS base
WORKDIR /app
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /app
COPY ./publishh .
ENTRYPOINT ["dotnet", "SftpClientCron.dll"]

What am I missing ?

Golide
  • 835
  • 3
  • 13
  • 36
  • Does the docker image contain the dotnet sdk? Can you show all your appsettings files ? – Gaël James Jan 30 '23 at 11:44
  • Start your container and override the command to be your shell. Then verify that it contains the file in the expected location with appropriate permissions. – Stephen Cleary Jan 30 '23 at 12:56
  • @GaëlJames Check question I have updated. . btw the container has the SDK because the job has been running before. The only change is that I have pulled out some hardcoded values from the code into the appsettings file – Golide Jan 30 '23 at 13:10
  • @StephenCleary I assume you mean to say I should amend the EntryPoint command? I have added the corresponding Dockerfile. If so, what command is needed for the override – Golide Jan 30 '23 at 13:19

0 Answers0