Kubectl apply command for updating existing service resource

12/18/2018

Currently I'm using Kubernetes version 1.11.+. Previously I'm always using the following command for my cloud build scripts:

- name: 'gcr.io/cloud-builders/kubectl'
  id: 'deploy'
  args:
  - 'apply'
  - '-f'
  - 'k8s'
  - '--recursive'
  env:
  - 'CLOUDSDK_COMPUTE_ZONE=${_REGION}'
  - 'CLOUDSDK_CONTAINER_CLUSTER=${_CLUSTER_NAME}'

And the commands just working as expected, at that time I'm using k8s version 1.10.+. However recently I got the following error:

  • spec.clusterIP: Invalid value: "": field is immutable
  • metadata.resourceVersion: Invalid value: "": must be specified for an update

So I'm wondering if this is an expected behavior for Service resources?

Here's my YAML config for my service:

apiVersion: v1
kind: Service
metadata:
  name: {name}
  namespace: {namespace}
  annotations:
    beta.cloud.google.com/backend-config: '{"default": "{backend-config-name}"}'
spec:
  ports:
   - port: {port-num}
     targetPort: {port-num}
  selector:
    app: {label}
    environment: {env}
type: NodePort
-- irvifa
google-cloud-build
google-cloud-platform
google-kubernetes-engine
kubernetes

2 Answers

12/19/2018

You need to set the spec.clusterIP on your service yaml file with value to be replaced with clusterIP address from service as shown below:

spec:
  clusterIP:

Your issue is discuused on the following github there as well a workaround to help you bypass this issue.

-- Alioua
Source: StackOverflow

12/19/2018
-- Jordan Liggitt
Source: StackOverflow