[英]Kubectl apply command for updating existing service resource
Currently I'm using Kubernetes version 1.11.+.目前我使用的是 Kubernetes 版本 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.+.命令按预期工作,当时我使用的是 k8s 版本 1.10.+。 However recently I got the following error:
但是最近我收到以下错误:
- spec.clusterIP: Invalid value: "": field is immutable
spec.clusterIP:无效值:“”:字段不可变
- metadata.resourceVersion: Invalid value: "": must be specified for an update
metadata.resourceVersion:无效值:“”:必须为更新指定
So I'm wondering if this is an expected behavior for Service resources?所以我想知道这是否是服务资源的预期行为?
Here's my YAML config for my service:这是我的服务的 YAML 配置:
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
This is due to https://github.com/kubernetes/kubernetes/issues/71042这是由于https://github.com/kubernetes/kubernetes/issues/71042
https://github.com/kubernetes/kubernetes/pull/66602 should be picked to 1.11 https://github.com/kubernetes/kubernetes/pull/66602应该选到1.11
I sometimes meet this error when manually running kubectl apply -f somefile.yaml
.手动运行
kubectl apply -f somefile.yaml
时,我有时会遇到此错误。 I think it happens when someone have changed the specification through the Kubernetes Dashboard instead of by applying new changes through kubectl apply
.我认为当有人通过 Kubernetes 仪表板更改规范而不是通过
kubectl apply
应用新更改时,就会发生这种情况。
To fix it, I run kubectl edit services/servicename
which opens the yaml specification in my default editor.为了修复它,我运行
kubectl edit services/servicename
,它在我的默认编辑器中打开了 yaml 规范。 Then remove the fields metadata.resourceVersion
and spec.clusterIP
, hit save and run kubectl apply -f somefile.yaml
again.然后删除字段
metadata.resourceVersion
和spec.clusterIP
,点击保存并再次运行kubectl apply -f somefile.yaml
。
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:您需要在服务 yaml 文件中设置 spec.clusterIP,并将其值替换为服务中的 clusterIP 地址,如下所示:
spec:
clusterIP:
Your issue is discuused on the following github there as well a workaround to help you bypass this issue.您的问题在下面的github 上有讨论,还有一个解决方法可以帮助您绕过这个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.