Kubernetes - Scaling the resource failed with: Job.batch is invalid:

1/11/2018

I'm trying to delete an existent job using

kubectl delete job/job-name -n my-namespace

But this error is displayed

caling the resource failed with: Job.batch "kong-loop" is invalid:
spec.template: Invalid value: api.PodTemplateSpec{...}: field is
immutable; Current resource version 12189833
-- Bruno Quaresma
jobs
kubectl
kubernetes

2 Answers

2/9/2018

kubectl does an HTTP PUT to the job during the delete process. This PUT fails because the Job has gotten itself into an invalid state. We must DELETE without PUTing.

Try

kubectl proxy curl -X DELETE localhost:8001/apis/batch/v1/namespaces/<namespace>/jobs/<jobname>

Then kill the kubectl proxy process. namespace is typically default

-- esnible
Source: StackOverflow

4/27/2018

The solution posted by @esnible does work in this scenario, but it is simpler do these steps:

  1. Delete job with cascade false

kubectl delete job/jobname -n namespace --cascade=false

  1. Delete any pod that exists

kubectl delete pod/podname -n namespace

Solution found at in this google groups discussion https://groups.google.com/forum/#!topic/kubernetes-users/YVmUgktoqtI

-- moose1089
Source: StackOverflow