k8s_Job - harishgorla5/K8S-HINTechnologies GitHub Wiki

Table of Contents

What is a Kubernetes Job?

A Kubernetes Job ensures that a specified number of pods complete successfully. Once the task completes, the Job tracks the pod status and retries on failure based on the restart policy.

Features

1. One-off task: Run once and exit.
2. Retry on failure: Automatically retries if a pod fails (based on the <code>backoffLimit</code>).
3. Parallelism: Can run multiple pods in parallel (e.g., for data processing).

Use Case

This example demonstrates a complete pipeline where a user uploads an image, and a Kubernetes Job processes it using ImageMagick.

Steps

1. Create PersistentVolumeClaim:

kubectl apply -f https://raw.githubusercontent.com/harishgorla5/K8S-HINTechnologies/refs/heads/main/job-pvc.yaml

2. Frontend (HTML Upload UI via Nginx): A ConfigMap is used to serve the HTML.

kubectl apply -f https://raw.githubusercontent.com/harishgorla5/K8S-HINTechnologies/refs/heads/main/job-config.yaml

3. Nginx Pod and NodePort Service:

kubectl apply -f https://raw.githubusercontent.com/harishgorla5/K8S-HINTechnologies/refs/heads/main/job-pod-nodeport.yaml

4. Backend (Flask container):

kubectl apply -f https://raw.githubusercontent.com/harishgorla5/K8S-HINTechnologies/refs/heads/main/job-deployment.yaml

5. Open the frontend in browser: http://nodeip:30080

6. Upload an image.

7. The backend saves the image to PVC and creates a Kubernetes Job.

8. The Job runs ImageMagick to resize the image.

9. Output is saved as: /data/thumb_&lt;filename&gt; on the PVC.

10. Check that the Job has been created:

kubectl get jobs

11. Check the Job Pod:

kubectl get pods

12. View logs from the Job Pod:

kubectl logs &lt;job-pod-name&gt;

13. Check Job status in detail:

kubectl describe job &lt;job-name&gt;

14. Debugging a failed Job:

kubectl get pods
kubectl logs <failing-job-pod>
kubectl describe pod <failing-job-pod>
⚠️ **GitHub.com Fallback** ⚠️