【问题标题】:kubernetes deploy Pod and python file startkubernetes 部署 Pod 和 python 文件启动
【发布时间】:2021-06-18 19:58:33
【问题描述】:
apiVersion: v1
kind: Pod
metadata:
  name: test
  labels:
    app: test-pod
spec:
  containers:
  - name: testserver
    image: test_server:2.5
    ports:
      - containerPort: 8080
      - containerPort: 5100
    env:
      - name: POD_NAME
        valueFrom:
          fieldRef:
            fieldPath: metadata.name
    volumeMounts:
      - name: testserver
        mountPath: /app/test/csv
#    command: ["/bin/bash"]
#    args: ["-c", "python /app/api/Python_Rest.py"]

  - name: testdb
    image: lev_test_db:1.4
    ports:
      - containerPort: 1433
    env:
      - name: POD_NAME
        valueFrom:
          fieldRef:
            fieldPath: metadata.name
    volumeMounts:
      - name: testdb
        mountPath: /var/opt/mssql/data

  volumes:
  - name: testserver
    hostPath:
      path: /usr/testhostpath/testserver
  - name: levmldb
    hostPath:
      path: /usr/testhostpath/testdb

如果按照我注释掉的方式进行的话,tomcat不能正常工作,因为python服务器在tomcat成功之前就已经运行了。

在kubernetes环境下使用yaml文件部署tomcat容器,如果tomcat正常成功,我想运行python文件。我该怎么办?

【问题讨论】:

  • 第一个想法:在python启动之前添加一个sleep命令......也许有更复杂的可能性让python 等待 for tomcat启动。
  • 您通常会在两个单独的部署中运行它们;然后 Python Pod 可以退出并重新启动,直到 Tomcat Pod 启动并运行。除了hostPath 卷之外,您还应该考虑其他一些存储,当 Pod 被安排在不同的节点上时,这些存储可能会错位。
  • python 和 tomcat 共享一个物理目录,它们试图在同一个 pod 中运行。谢谢你的回答

标签: kubernetes rancher kubernetes-deployment


【解决方案1】:

你可以使用 sleep 命令来延迟 testserver 的启动 可以有更花哨的解决方案

command:
  - "sleep"
  - "100"
lifecycle:
  postStart:
    exec:
      command: 
        - "sh"
        - "-c"
        - |
          python /app/api/Python_Rest.py
          

【讨论】:

  • 我试过了,但出现错误。命令:#args:["-c","python /app/levml/api/test_Rest.py"] #args:["-c","nohup python /app/levml/api/test_Rest.py&"] - sleep - 100 生命周期:postStart:exec:命令:-“sh”-“-c”-| "python /app/api/test_Rest.py"
  • 你这是什么意思?您仍然看到同样的错误吗?
猜你喜欢
  • 1970-01-01
  • 2020-07-20
  • 2020-07-27
  • 2017-08-24
  • 2018-08-30
  • 2017-06-19
  • 2021-09-21
  • 1970-01-01
相关资源
最近更新 更多