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

<p>In the migration job, I have a section of bash in the following format:</p>

<pre><code>args:
        - |
          /cloud_sql_proxy -instances=xxxxxxxxxxx:europe-west1:xxxxxxxxxxx=tcp:5432 -credential_file=/secrets/cloudsql/credentials.json -log_debug_stdout=true &amp;
          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) &amp;
          wait 
          if [[ -f "/tmp/pod/main-terminated" ]]; then exit 0; echo "Job completed. Exiting..."; fi
</code></pre>

<p>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.</p>

David Essien
<p>I got the message <code>the job spec is invalid ... the field is immutable</code> for a different reason and wanted to briefly share it here.</p>

<p>I was trying to apply this yaml file:</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Deployment
spec:
  selector:
    matchLabels:
      app: application-name
...
</code></pre>

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

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

<p>Apparently the <code>spec.selector.matchLabels</code> 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.</p>
