[英]Run Kubernetes/Openshift cronjob with container user id
I am using Openshift to deploy a django application which uses pyodbc for connecting to external database.我正在使用 Openshift 部署一个 django 应用程序,该应用程序使用 pyodbc 连接到外部数据库。 Currently I wanted to schedule a cronjob in openshift using yaml file.目前我想使用 yaml 文件在 openshift 中安排一个 cronjob。 The cronjob gets created with no problem but throws this error when run: ('IM004', "[IM004] [unixODBC][Driver Manager]Driver's SQLAllocHandle on SQL_HANDLE_HENV failed (0) (SQLDriverConnect)")创建 cronjob 没有问题,但在运行时抛出此错误:('IM004', "[IM004] [unixODBC][Driver Manager]Driver's SQLAllocHandle on SQL_HANDLE_HENV failed (0) (SQLDriverConnect)")
This error occcured before as Openshift overrides uid when running a container.之前发生此错误,因为 Openshift 在运行容器时会覆盖 uid。 I overcame this error by following this workaround: https://github.com/VeerMuchandi/mssql-openshift-tools/blob/master/mssql-client/uid_entrypoint.sh我通过以下解决方法克服了这个错误: https : //github.com/VeerMuchandi/mssql-openshift-tools/blob/master/mssql-client/uid_entrypoint.sh
This error pops up again when the cronjob is run and this maybe due to same uid issue.运行 cronjob 时再次弹出此错误,这可能是由于相同的 uid 问题。 Following is my yaml file for scheduling cronjob:以下是我用于调度 cronjob 的 yaml 文件:
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: samplecron
spec:
securityContext:
runAsUser: 1001
runAsGroup: 0
schedule: "*/5 * * * *"
concurrencyPolicy: "Forbid"
startingDeadlineSeconds: 60
suspend:
successfulJobsHistoryLimit: 3
failedJobsHistoryLimit: 3
jobTemplate:
spec:
template:
metadata:
labels:
parent: "cronjobpi"
spec:
containers:
- name: samplecron
image: docker-registry.default.svc:5000/image-name
volumeMounts:
- mountPath: /path-to-mount
name: "volume-name"
command: [ "python3", "/script.py" ]
volumes:
- name: "vol-name"
restartPolicy: Never
Can someone suggest how I can provide same userid's information in yaml file of cronjob or any other way of solving this issue?有人可以建议我如何在 cronjob 的 yaml 文件中提供相同的用户 ID 信息或任何其他解决此问题的方法吗?
Was able to solve the issue using the entrypoint script I mentioned above and I included the the command to run the python script inside the .sh entrypoint script and instead of command: [ "python3", "/script.py" ] ["sh" , "/entrypoint.sh"] was used..The python script is used to connect to a DB server using pyodbc.能够使用我上面提到的入口点脚本解决这个问题,我在 .sh 入口点脚本中包含了运行 python 脚本的命令,而不是命令:["python3", "/script.py" ] ["sh " , "/entrypoint.sh"] 被使用..python 脚本用于使用 pyodbc 连接到数据库服务器。 pyodbc.connect() causes an issue if UID of container of is not written in etc/passwd which is done by entrypoint script mentioned above.如果容器的 UID 没有写在 etc/passwd 中,pyodbc.connect() 会导致问题,这是由上面提到的入口点脚本完成的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.