Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

field is immutable k8s

I am trying to deploy an application to GCP on kubernetes, however, the deployment fails with the error the job spec is invalid ... the field is immutable.

In the migration job, I have a section of bash in the following format:

args:
        - |
          /cloud_sql_proxy -instances=xxxxxxxxxxx:europe-west1:xxxxxxxxxxx=tcp:5432 -credential_file=/secrets/cloudsql/credentials.json -log_debug_stdout=true &
          CHILD_PID=$!
          (while true; do echo "waiting for termination file"; if [[ -f "/tmp/pod/main-terminated" ]]; then kill ; echo "Killed  as the main container terminated."; fi; sleep 1; done) &
          wait 
          if [[ -f "/tmp/pod/main-terminated" ]]; then exit 0; echo "Job completed. Exiting..."; fi

but when the file is executed, in the yaml on GCP I see that the command has been enclosed in quotes and then it returns the above mention error.

like image 852
David Essien Avatar asked May 22 '19 20:05

David Essien


People also ask

Are Kubernetes jobs immutable?

Kubernetes Jobs are designed to run and then terminate, but they stick around in the namespace after completion. Because job objects are immutable, this can cause conflicts and errors when attempting to update the job later.

Are pods immutable?

OpenShift Online treats pods as largely immutable; changes cannot be made to a pod definition while it is running. OpenShift Online implements changes by terminating an existing pod and recreating it with modified configuration, base image(s), or both.

Are Kubernetes pods immutable?

One of the developers has raised some concerns about some Pods that were created in the dev namespace that are not implementing good security practices. Specifically, some of these Pods are not configured so that their containers are immutable.

Is K8s declarative?

Kubernetes is usually described as a declarative system. Most of the time you work with YAML that defines what the end state of the system should look like.


1 Answers

I got the message the job spec is invalid ... the field is immutable for a different reason and wanted to briefly share it here.

I was trying to apply this yaml file:

apiVersion: extensions/v1beta1
kind: Deployment
spec:
  selector:
    matchLabels:
      app: application-name
...

Turns out that this yaml was going to replace a previous version of the same Deployment. When I ran kubectl get deployment application-name -o yaml I saw this:

apiVersion: extensions/v1beta1
kind: Deployment
spec:
  selector:
    matchLabels:
      app: application-name
      track: stable
...

Apparently the spec.selector.matchLabels is currently an array, and I was trying to replace that with a single string. My fix was deleting the deployment and re-deploying it.

like image 162
Lukasvan3L Avatar answered Sep 18 '22 18:09

Lukasvan3L