程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了如何通过 kubectl 运行 python 脚本?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决如何通过 kubectl 运行 python 脚本??

开发过程中遇到如何通过 kubectl 运行 python 脚本?的问题如何解决?下面主要结合日常开发的经验,给出你关于如何通过 kubectl 运行 python 脚本?的解决方法建议,希望对你解决如何通过 kubectl 运行 python 脚本?有所启发或帮助;

我最近被分配了在 Kubernetes 集群上安装 R 和 python 包的任务。我不知道什么是 Docker 和 Kubernetes 以及它是如何工作的。另外,我只是这个集群中的一个用户,没有任何 root 权限。我在过去 2 周内学习了这些主题并到达了这里,但仍然无法执行简单的 python 脚本。不明白在配置Dockerfile和kubectl的时候有什么问题。如果您有任何建议,请在评论中告诉我。

在集群中,我正在处理两个目录(RunScript 和 example_py)和以下文件:

ls /home/ext/gruenlab3/example_py
Dockerfile  requirements.txt

ls /home/ext/gruenlab3/RunScript
test.sh  test1.py  test1.yaml  

Dockerfile 的内容

FROM python:3.8-slim
RUN useradd --create-home --sHell /bin/bash app_user
workdir /home/app_user
copY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
USER app_user
copY . .
CMD ["bash"]

requirements.txt 的内容

numpy==1.19.2

test.sh 的内容

python test1.py

test1.py 的内容

f=open('Myoutput.dat','w')
for i in range(10):
    f.write(str(i)+'\n')
f.close() 

test1.yaml 文件的内容

  APIVersion: batch/v1
  kind: Job
  Metadata:
    name: test-py
  spec:
    BACkofflimit: 0      
    template:
      Metadata:
        name: test-py
      spec:
        restartPolicy: "Never"      
        priorityClassname: research-med
        # Volumes are declared by the pod. They share its lifecycle
        # and are communal across containers.
        volumes:
          # Volumes have a name and configuration based on the type of volume.
          # In this example,we use the emptyDir volume type
        - name: RunScript
          configMap:
            name: RunScript 
            defaultMode: 0777 
        containers:
          - name: test-py
            image: ls6-***/extgruenlab3/base_python
            imagePullPolicy: "IfNotPresent"
            env:
              - name: TEST
                value: "Hello"
              - name: MYDIR # example usage of env variable
                value: "/mydir"
            resources:
              limits:
                nvIDia.com/gpu: "1"
                cpu: "4"
                memory: "2Gi"
              requests:
                nvIDia.com/gpu: "1"
                cpu: "4"
                memory: "2Gi"
            #command:
            #  - sleep 10
            #  - infinity 
            volumeMounts:
              - mountPath: /RunScript/test.sh # directory IN the container
                name: localdir # matches volume-name from below
                subPath: test.sh 
        imagePullSecrets:
          - name: LSX-registry
        restartPolicy: "Never"
        volumes:
          - name: localdir
            cephfs:
              monitors:
                - 1320  # Not important for you,just copy along
              user: extgruenlab3  # <namespace>
              path: "/home/ext/gruenlab3/RunScript" # The path you want to mount
              secretRef: # The name of the secret for auth. Is always "ceph-secret"
                name: ceph-secret

我使用 fastbuildah 制作了 docker 镜像。命令“fastbuildah images”显示了这一点

 REPOSITORY                          TAG            IMAGE ID       CREATED          SIZE
 ls6-***/extgruenlab3/base_python    latest         d68aeaa49f58   37 minutes ago   182 MB 

然后我使用命令运行 yaml 文件

 kubectl -n extgruenlab3 create -f test1.yaml 

然后我使用“kubectl get pods”检查pods

 name            READY   STATUS      RESTARTS   AGE
 test-py-qvzbq   0/1     Completed   0          27m

但我在 RunScript 目录中没有看到任何输出文件名“Myoutput.dat”。我想我在 Dockerfile 或 yaml 文件中做错了什么。你能指出我的错误吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

大佬总结

以上是大佬教程为你收集整理的如何通过 kubectl 运行 python 脚本?全部内容,希望文章能够帮你解决如何通过 kubectl 运行 python 脚本?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。