禁止:禁止更新除“副本",“模板"和"updateStrategy"以外的字段的有状态集规范 [英] Forbidden: updates to statefulset spec for fields other than 'replicas', 'template', and 'updateStrategy' are forbidden
问题描述
我使用io.fabric8.kubernetes-client版本3.1.8进行kubernetes资源的RollingUpdate.适合部署.但是我遇到了StatefulSet的例外.但是如果我对StatefulSet使用'kubectl apply -f ***.yaml'也很好.
I use io.fabric8.kubernetes-client, version 3.1.8 to do RollingUpdate of kubernetes resource. It is fine for Deployment. But I meet an exception for StatefulSet. But it is also fine if I use 'kubectl apply -f ***.yaml' for the StatefulSet.
RollingUpdate部署的代码:
Code to RollingUpdate Deployment:
public void createOrReplaceResourceByYaml(String namespace, KubernetesResource resource) {
KubernetesClient client = k8sRestClient.newKubeClient();
Deployment deployment = (Deployment) resource;
logger.info(String.format("Create/Replace Deployment [%s] in namespace [%s].", ((Deployment) resource).getMetadata().getName(), namespace));
NonNamespaceOperation<Deployment, DeploymentList, DoneableDeployment, ScalableResource<Deployment, DoneableDeployment>> deployments = client.extensions().deployments().inNamespace(namespace);
Deployment result = deployments.createOrReplace(deployment);
logger.info(String.format("Created/Replaced Deployment [%s].", result.getMetadata().getName()));
}
RollingUpdate StatefulSet的代码
Code to RollingUpdate StatefulSet
public void createOrReplaceResourceByYaml(String namespace, KubernetesResource resource) {
KubernetesClient client = k8sRestClient.newKubeClient();
StatefulSet statefulSet = (StatefulSet) resource;
logger.info(String.format("Create/Replace StatefulSet [%s] in namespace [%s].", statefulSet.getMetadata().getName(), namespace));
NonNamespaceOperation<StatefulSet, StatefulSetList, DoneableStatefulSet, RollableScalableResource<StatefulSet, DoneableStatefulSet>> statefulSets = client.apps().statefulSets().inNamespace(namespace);
StatefulSet result = statefulSets.createOrReplace(statefulSet);
logger.info(String.format("Created/Replaced StatefulSet [%s].", result.getMetadata().getName()));
}
RollingUpdate of StatefulSet时发生异常
Exception when do RollingUpdate of StatefulSet
执行失败:在以下位置放置PUT: https://kubernetes.default.svc/apis/apps/v1beta1/namespaces/itsma1/statefulsets/pro-rabbitmq .消息:StatefulSet.apps"pro-rabbitmq"无效:规范:禁止:禁止更新除"replicas","template"和"updateStrategy"以外的字段的statefulset规范..接收状态:Status(apiVersion = v1,代码= 422,详细信息= StatusDetails(原因= [StatusCause(field = spec,message = Forbidden:禁止更新除'replicas','template'和'updateStrategy'以外的字段的statefulset规范.,reason = FieldValueForbidden,AdditionalProperties = {}}],group = apps,kind = StatefulSet,名称= pro-rabbitmq,retryAfterSeconds = null,uid = null,additionalProperties = {}),kind = Status,message = StatefulSet.apps"pro-rabbitmq"无效:规范:禁止:禁止更新除副本",模板"和"updateStrategy"以外的字段的有状态集规范.元数据= ListMeta(resourceVersion = null,selfLink = null,additionalProperties = {}),原因=无效,状态=故障,AdditionalProperties = {}).
Failure executing: PUT at: https://kubernetes.default.svc/apis/apps/v1beta1/namespaces/itsma1/statefulsets/pro-rabbitmq. Message: StatefulSet.apps "pro-rabbitmq" is invalid: spec: Forbidden: updates to statefulset spec for fields other than 'replicas', 'template', and 'updateStrategy' are forbidden.. Received status: Status(apiVersion=v1, code=422, details=StatusDetails(causes=[StatusCause(field=spec, message=Forbidden: updates to statefulset spec for fields other than 'replicas', 'template', and 'updateStrategy' are forbidden., reason=FieldValueForbidden, additionalProperties={})], group=apps, kind=StatefulSet, name=pro-rabbitmq, retryAfterSeconds=null, uid=null, additionalProperties={}), kind=Status, message=StatefulSet.apps "pro-rabbitmq" is invalid: spec: Forbidden: updates to statefulset spec for fields other than 'replicas', 'template', and 'updateStrategy' are forbidden., metadata=ListMeta(resourceVersion=null, selfLink=null, additionalProperties={}), reason=Invalid, status=Failure, additionalProperties={}).
我很好奇为什么会发生错误以及如何解决该错误.
推荐答案
您可以尝试使用此方法来更新StatefulSet
You can try this to update the StatefulSet
client.apps().statefulSets().withName("repl1").rolling().withTimeout(5, TimeUnit.MINUTES).updateImage("");
client.apps().statefulSets().withName("repl1").rolling().withTimeout(5, TimeUnit.MINUTES).updateImage("");
如果只想缩放,可以尝试一下
If you want to only scale, you can try this
client.apps().statefulSets().withName("repl1").scale(5, true);
client.apps().statefulSets().withName("repl1").scale(5, true);
这篇关于禁止:禁止更新除“副本",“模板"和"updateStrategy"以外的字段的有状态集规范的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!