Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to run an one-time task with K8s

Shulou Source: shulou.com Published: 2022-06-01 00:55:28 10月05日 Update

How to use k8s to run a one-time task, I believe many inexperienced people are helpless about this, for this reason this article summarizes the causes and solutions of the problem, through this article I hope you can solve this problem.

Containers can be divided into two categories according to their running time: service containers and work containers.

Service containers usually provide services continuously and need to be running all the time, such as http server, daemon, etc. Work-class containers are one-time tasks, such as batch programs, that exit after completion.

Kubernetes Deployment, ReplicaSet, and DaemonSet are all used to manage service class containers; for work class containers, we use Job.

Let's start with a simple Job profile myjob.yml:

batch/v1 is the apiVersion of the current Job.

2 indicates that the current resource type is Job.

restartPolicy specifies when the container needs to be restarted. For Job, it can only be set to Never or OnFailure. For other controllers (e.g. Deployment) it can be set to Always.

Start Job with kubectl apply -f myjob.yml.

DESIRED and SUCCESSFUL are both 1, indicating that a Pod started as expected and executed successfully. kubectl get pod Check the status of the Pod:

These are the cases where the Pod succeeds, but what happens if the Pod fails?

After reading the above, do you know how to run one-time quests with k8s? If you still want to learn more skills or want to know more related content, welcome to pay attention to the industry information channel, thank you for reading!

Tags: Container run service one-time task work success content situation method more problem helpless for this reason skill file time status Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS MariaDB Apple Shulou Tech Info MySQL