Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

createOrReplace with the same yaml file will be got error like ' provided port is already allocated' #2630

Closed
guisense opened this issue Nov 25, 2020 · 9 comments

Comments

@guisense
Copy link

guisense commented Nov 25, 2020

steps:
1.the first time to deploy a service to k8s by service.yaml file, success
2.the next deploy the same service.yaml file (unchanged) , failed

code

try{
    File file = new File(filePath);
    is = new FileInputStream(file);
    List<HasMetadata> list = client.load(is).createOrReplace();
} catch(Exception){
   ……
}

logs like these

io.fabric8.kubernetes.client.KubernetesClientException: Failure executing: POST at: https://10.152.xx.xx/api/v1/namespaces/app-app-echo-v1-0-0/services. Message: Service "app-echo" is invalid: spec.ports[0].nodePort: Invalid value: 30081: provided port is already allocated. Received status: Status(apiVersion=v1, code=422, details=StatusDetails(causes=[StatusCause(field=spec.ports[0].nodePort, message=Invalid value: 30081: provided port is already allocated, reason=FieldValueInvalid, additionalProperties={})], group=null, kind=Service, name=app-echo, retryAfterSeconds=null, uid=null, additionalProperties={}), kind=Status, message=Service "app-echo" is invalid: spec.ports[0].nodePort: Invalid value: 30081: provided port is already allocated, metadata=ListMeta(_continue=null, remainingItemCount=null, resourceVersion=null, selfLink=null, additionalProperties={}), reason=Invalid, status=Failure, additionalProperties={}).
        at io.fabric8.kubernetes.client.dsl.base.OperationSupport.requestFailure(OperationSupport.java:570)
        at io.fabric8.kubernetes.client.dsl.base.OperationSupport.assertResponseCode(OperationSupport.java:509)
        at io.fabric8.kubernetes.client.dsl.base.OperationSupport.handleResponse(OperationSupport.java:474)
        at io.fabric8.kubernetes.client.dsl.base.OperationSupport.handleResponse(OperationSupport.java:435)
        at io.fabric8.kubernetes.client.dsl.base.OperationSupport.handleCreate(OperationSupport.java:250)
        at io.fabric8.kubernetes.client.dsl.base.BaseOperation.handleCreate(BaseOperation.java:881)
        at io.fabric8.kubernetes.client.dsl.base.BaseOperation.create(BaseOperation.java:326)
        at io.fabric8.kubernetes.client.dsl.base.BaseOperation.create(BaseOperation.java:84)
        at io.fabric8.kubernetes.client.handlers.core.v1.ServiceHandler.create(ServiceHandler.java:39)
        at io.fabric8.kubernetes.client.handlers.core.v1.ServiceHandler.create(ServiceHandler.java:25)
        at io.fabric8.kubernetes.client.utils.CreateOrReplaceHelper.lambda$createOrReplaceItem$0(CreateOrReplaceHelper.java:74)
        at io.fabric8.kubernetes.client.utils.CreateOrReplaceHelper.createOrReplace(CreateOrReplaceHelper.java:53)
        at io.fabric8.kubernetes.client.utils.CreateOrReplaceHelper.createOrReplaceItem(CreateOrReplaceHelper.java:87)
        at io.fabric8.kubernetes.client.dsl.internal.NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableListImpl.createOrReplaceOrDeleteExisting(NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableListImpl.java:446)
        at io.fabric8.kubernetes.client.dsl.internal.NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableListImpl.createOrReplace(NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableListImpl.java:291)
        at io.fabric8.kubernetes.client.dsl.internal.NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableListImpl.createOrReplace(NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableListImpl.java:66)
        at com.delta.eda.service.YamlDeploymentService.applyResource(YamlDeploymentService.java:79)
        at com.delta.eda.service.ImageUploadService.deployService(ImageUploadService.java:1031)
        at com.delta.eda.controller.ImageUploadController.deployService(ImageUploadController.java:140)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190)
        at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138)
        at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:892)
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:797)
        at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1039)
        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942)
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005)
        at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:908)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
        at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:882)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:118)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:92)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:118)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:93)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:118)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:118)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
        at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
        at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
        at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:853)
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1587)
        at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        at java.lang.Thread.run(Thread.java:748)

Unlike 2454 ,
the log shows the POST METHOD, and msg "spec.ports[0].nodePort: Invalid value: 30081: provided port is already allocated."

Everything goes right in 4.10.3, and the problem occured only in 4.11.0+ , I know the createOrReplace had been refactored since 4.11.0, but i can not find any other issues like 'port already allocated'

@rohanKanojia
Copy link
Member

@guisense : Seems related to #2454 . Could you please try upgrading to v4.13.0 and see if it resolves your issue?

@guisense
Copy link
Author

@rohanKanojia thanks for your response.
Yes, but i feel a little confused since the error occured to me seems not described in #2454 .
I have tried to use v4.13.0, it would be same error.

I have debugged and found the version below 4.11.0 , the same service.yaml would firstly being compared to the one from the server, then it would call API
**[PUT] http://ip:port/api/v1/namespace/{namespace}/{app-name}.**
But in the version 4.11.0 above, it will directly called API
**[POST] https://ip:port/api/v1/namespace/{namespace}/{app-name}.**
Then it will give me response like "port already allocated".

By the way, unaltered file deployment.yaml goes right with duplicate deploying.

@rohanKanojia
Copy link
Member

Strange, I think it should fail with both client versions on second createOrReplace. Do you have a small reproducer for us? I marked this related to #2454 since client should ignore doing an update if nothing has changed(just like kubectl). But kubectl does it in an ugly way(you can find this in the discussion done in #2454)

@guisense
Copy link
Author

@rohanKanojia Ok.

service.yaml

apiVersion: v1
kind: Service
metadata:
  name: app-echo
  namespace: eda
spec:
  type: NodePort
  ports:
  - port: 8080
    targetPort: 8000
    nodePort: 30081
    protocol: TCP
  selector:
    app: app-echo

call service demo

try{
    //service.yaml filePath
    File file = new File(filePath);
    is = new FileInputStream(file);
    List<HasMetadata> list = client.load(is).createOrReplace();
} catch(Exception){
   ……
}

@stale
Copy link

stale bot commented Apr 8, 2021

This issue has been automatically marked as stale because it has not had any activity since 90 days. It will be closed if no further activity occurs within 7 days. Thank you for your contributions!

@stale stale bot added the status/stale label Apr 8, 2021
@stale stale bot closed this as completed May 6, 2021
@zjd0112
Copy link

zjd0112 commented Nov 12, 2022

same issue with v5.12.1

@shawkins
Copy link
Contributor

@zjd0112 this is under the same family of issues as #3896. Moving forward the recommendation will be to use server side apply, rather than trying to put additional compensation logic in the fabric8 client's replace operation.

@zjd0112
Copy link

zjd0112 commented Nov 13, 2022

@zjd0112 this is under the same family of issues as #3896. Moving forward the recommendation will be to use server side apply, rather than trying to put additional compensation logic in the fabric8 client's replace operation.

@shawkins Thank you for your reply. My Kubernetes cluster versions are from v1.13 to v1.22, it seems that the server side apply feature is supported from kubernetes 1.16. To solve this problem, I use replace api rather than createOrReplace when the svc resources exist in cluster, and the svc can be updated correctly.

@uklance
Copy link

uklance commented Mar 31, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants