我使用io.fabric8.kubernetes-client,版本3.1.8来执行kubernetes资源的RollingUpdate . 它适用于部署 . 但我遇到StatefulSet的例外 . 但是如果我对StatefulSet使用'kubectl apply -f *** . yaml'也没关系 .
RollingUpdate部署代码:
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> deployments = client.extensions().deployments().inNamespace(namespace);
Deployment result = deployments.createOrReplace(deployment);
logger.info(String.format("Created/Replaced Deployment [%s].", result.getMetadata().getName()));
}
代码到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> statefulSets = client.apps().statefulSets().inNamespace(namespace);
StatefulSet result = statefulSets.createOrReplace(statefulSet);
logger.info(String.format("Created/Replaced StatefulSet [%s].", result.getMetadata().getName()));
}
执行StatefulSet的RollingUpdate时出现异常
执行失败:PUT at:https://kubernetes.default.svc/apis/apps/v1beta1/namespaces/itsma1/statefulsets/pro-rabbitmq . 消息:StatefulSet.apps“pro-rabbitmq”无效:spec:Forbidden:禁止对'replicas','template'和'updateStrategy'以外的字段更新statefulset规范 . 收到状态:状态(apiVersion = v1, code = 422,details = StatusDetails(cause = [StatusCause(field = spec,message = Forbidden:禁止对'replicas','template'和'updateStrategy'以外的字段更新statefulset规范 . ,reason = FieldValueForbidden,additionalProperties = {})],group = apps,kind = StatefulSet,name = pro-rabbitmq,retryAfterSeconds = null,uid = null,additionalProperties = {}),kind = Status,message = StatefulSet.apps“pro-rabbitmq”无效:spec:Forbidden:禁止对'replicas','template'和'updateStrategy'以外的字段更新statefulset规范 . ,metadata = ListMeta(resourceVersion = null,selfLink = null,additionalProperties = {}),reason = Invalid ,status = Failure,additionalProperties = {}) .
I am curious why the error happened and how to fix it.