Elimizde şöyle bash script içeren bir ConfigMap olsun
apiVersion: v1kind: ConfigMapmetadata:name: slim-shady-configmapdata:slim-shady.sh: |#!/bin/bashecho "Hi!"echo "My name is"echo "What?"echo "My name is"echo "Who?"echo "My name is"echo "Chika-chika"echo "Slim Shady"
Job şöyle olsun
apiVersion: batch/v1 kind: Job metadata: name: chicka-chicka-slim-shady spec: template: spec: containers: - name: shady image: centos command: ["/script/slim-shady.sh"] volumeMounts: - name: script mountPath: "/script" volumes: - name: script configMap: name: slim-shady-configmap defaultMode: 0500 restartPolicy: Never
Açıklaması şöyle
In the above Job manifest you can see that we create a new volume for the configmap. We then take that volume and mount it under the shady container at “/script” and then execute the script file slim-shady.sh which is the name of the file in our configmap.Two things I would like to point out here:A) Inside the volume, we must specify a defaultMode of atleast 0500 (read+execute to the user). This defines the file permissions inside the container when the pod is run. If we do not set this, we get permission denied errors. This is because as a default the configmap will be mounted with 0644 and you will end up with an error like below.Warning Failed 7s kubelet Error: failed to create containerd task: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "/script/slim-shady.sh": permission denied: unknownB) Here we were also able to use an existing and well known container image instead of creating our own. This takes less effort for us because we did not have to build a new image with new code etc… but instead only needed to deploy the configmap and a Job.
Örnek - Python
Şöyle yaparız
apiVersion: batch/v1 kind: Job metadata: name: promote-model-a spec: template: spec: containers: - name: promote image: wbassler/mlflow-utils:0.0.1 command: - python args: - /mlflow/promote.py env: - name: MODEL_NAME value: model-a volumeMounts: - name: promote mountPath: "/mlflow" volumes: - name: promote configMap: name: promote-model defaultMode: 0500 restartPolicy: Never
Hiç yorum yok:
Yorum Gönder