Kubernetes:将Pod STDOUT,STDERR和Pod终止日志重定向到PVC文件

时间:2019-02-26 07:11:21

标签: docker kubernetes kubernetes-pvc

我正在尝试将pod的STDOUT和STDERR写入PVC安装位置的文件中。

以下是我的部署的模板内容:


    "template": {
      "metadata": {
        "name": "python-stdout-app",
        "creationTimestamp": null,
        "labels": {
          "k8s-app": "python-stdout-app"
        }
      },
      "spec": {
        "volumes": [
          {
            "name": "task-pv-volume",
            "persistentVolumeClaim": {
              "claimName": "task-pv-claim"
            }
          }
        ],
        "containers": [
          {
            "name": "python-stdout-app",
            "image": "trideep/demo-stdout-app",
            "resources": {},
            "volumeMounts": [
              {
                "name": "task-pv-volume",
                "mountPath": "/usr/share"
              }
            ],
            "terminationMessagePath": "/usr/share/1fed8c03-bc30-4889-952e-46f4c19b6ac1.log",
            "terminationMessagePolicy": "File",
            "imagePullPolicy": "Always",
            "securityContext": {
              "privileged": false
            }
          }
        ],
        "restartPolicy": "Always",
        "terminationGracePeriodSeconds": 30,
        "dnsPolicy": "ClusterFirst",
        "securityContext": {},
        "schedulerName": "default-scheduler"
      }
    }

我可以看到文件在Pod中时正在写入。但是在安装的主机位置看不到输出。

以下是执行命令

python demo_stdout.py >> /usr/share/1fed8c03-bc30-4889-952e-46f4c19b6ac1.log 2>&1

我要做的一件事是输出文件,“ terminationMessagePath”与我希望在同一文件中使用pod终端占用空间和stdout / stderr相同。

Dockerfile如下:

FROM python:2.7.15-alpine3.9

WORKDIR /usr/src/app

COPY . .

CMD ["sh", "-c", "tail -f /dev/null"]

尝试了以下内容:

python demo_stdout.py >> /usr/share/test.log 2>&1

以上内容在PVC中生成日志。但是需要在同一文件中获取Pod终止日志。

有人可以帮我吗?

0 个答案:

没有答案
相关问题