Python3.11无法打开文件[Errno 2]没有这样的文件或目录

问题描述 投票:0回答:1

我在我的 cronjob yaml 中更新了 readOnlyRootFilesystem: true 但开始收到错误

OSError: [Errno 30] 只读文件系统: '/absolute/path/to/your/folder'

我还添加了一个空目录 体积安装: - 名称:tmp-卷 mountPath:绝对/路径/到/您的/文件夹 卷:

  • 名称:tmp-volume 空目录:{}

添加此后我开始得到

**python3.11: can't open file 'absolute/path/to/your/folder/text.py': [Errno 2] No such file or directory**

我已附上 cronjob yaml

           containers:
            - env:
              - name: ENV_VAR
                value: value
              - name: MAINTAIN_HA_POOL
                value: "true"
              - name: PROCESS_SCHEDULER_REQUESTS
                value: "true"
              - name: MAINTAIN_NODE_POOL
                value: "false"
              - name: ENABLE_LSV3
                value: "false"
              image: us.icr.io/nz-cloud/nzsaas-common-pool-cronjob:master-2.1.2.0-20240329-111245
              imagePullPolicy: Always
              name: common-machine-pool-cronjob-container
              resources: {}
              securityContext:
                privileged: true
                readOnlyRootFilesystem: true
              terminationMessagePath: /dev/termination-log
              terminationMessagePolicy: File
              volumeMounts:
              - mountPath: /opt/ibm/common-pool-cronjob/
                name: tmp-volume
            volumes:
            - emptyDir: {}
              name: tmp-volume  

仅供参考,我已将 CHMOD 777 赋予特定文件夹

python docker kubernetes cron yaml
1个回答
0
投票

根据我的评论,创建

emptyDir
会创建一个空文件夹。

您需要在

text.py
引用的文件夹中创建
emptyDir
,然后才能与其交互。

举例来说:

app.yaml

kind: Deployment
apiVersion: apps/v1
metadata:
  name: app
  labels:
    app: test
spec:
  selector:
    matchLabels:
      app: test
  template:
    metadata:
      labels:
        app: test
    spec:
      containers:
      - name: test
        image: docker.io/alpine:3.19
        args:
        - /bin/sh
        - -c
        - |
          # The emptyDir volume's mount path
          DIR="/absolute/path/to/your/folder"
          # Some file
          FILE="text.py"
          echo "Starting"
          if ! test -f ${DIR}/${FILE}
          then
            echo "${FILE} does **not** exist"
          fi
          echo "Creating ${DIR}/${FILE}"
          touch ${DIR}/${FILE}
          if test -f ${DIR}/${FILE}
          then
            echo "${FILE} exists"
          fi
          echo "Done" 
        volumeMounts:
        - name: tmp-volume
          mountPath: /absolute/path/to/your/folder
      volumes:
      - name: tmp-volume
        emptyDir:
          sizeLimit: 1Mi

并且:

NAMESPACE="78244509"
kubectl create namespace ${NAMESPACE}

kubectl create \
--filename=./app.yaml \
--namespace=${NAMESPACE}

kubectl logs deployment/app \
--namespace=${NAMESPACE}

产量:

Starting
Creating /absolute/path/to/your/folder/text.py
text.py exists
Done

和:

kubectl delete \
--filename=./app.yaml \
--namespacpe=${NAMESPACE}
© www.soinside.com 2019 - 2024. All rights reserved.