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

curl: (56) Recv failure: Connection reset by peer #2439

Closed
saparaj opened this issue Aug 25, 2020 · 4 comments
Closed

curl: (56) Recv failure: Connection reset by peer #2439

saparaj opened this issue Aug 25, 2020 · 4 comments

Comments

@saparaj
Copy link

saparaj commented Aug 25, 2020

Hi,

I am trying to create deployment and service using below code - This works first time, if I do curl on service external endpoint I get the reply back. If I update the yaml with updated docker image say: v2 and try curl again, I am getting this error: curl: (56) Recv failure: Connection reset by peer. If I check k8 service logs before and after 2nd deployment, NodePort and Service Endpoints are different. If I try this same scenario using kubectl CLI it works fine. Please let me know what I am doing wrong from code.

List<HasMetadata> allResources = client.load(stream).get(); client.resourceList(allResources).inNamespace("default").createOrReplaceAnd().waitUntilReady(5, TimeUnit.MINUTES);

apiVersion: apps/v1
kind: Deployment
metadata:
  name: helloworld-deployment
spec:
  selector:
    matchLabels:
      app: helloworld
  replicas: 1
  template:
    metadata:
      labels:
        app: helloworld
    spec:
      containers:
        - name: helloworld
          # enter the path to your image, be sure to include the correct region prefix
          image: iad.ocir.io/ax022wvgmjpq/helloworld:v1
          ports:
            - containerPort: 8888
---
apiVersion: v1
kind: Service
metadata:
  name: helloworld-service
spec:
  type: LoadBalancer
  ports:
    - port: 8080
      protocol: TCP
      targetPort: 8888
  selector:
    app: helloworld

Thanks,
Swarda

@rohanKanojia
Copy link
Member

After a discussion on Gitter, I think I understand the issue now. Problem is that client is doing PATCH with YAML object even after there are no new changes in Service, but while doing createOrReplace we compare object provided with object fetched from the server(which is always different since nodePort and clusterIP are dynamically allocated upon first creation). See below code:

try (KubernetesClient client = new DefaultKubernetesClient()) {
    Service svc = new ServiceBuilder()
            .withNewMetadata().withName("my-service").endMetadata()
            .withNewSpec()
            .withType("NodePort")
            .addToSelector("app", "MyApp")
            .addNewPort()
            .withPort(80)
            .withTargetPort(new IntOrString(80))
            .endPort()
            .endSpec()
            .build();

    Service svc1 = client.services().inNamespace("rokumar").createOrReplace(svc);
    // Output: 30614
    System.out.println(svc1.getSpec().getPorts().get(0).getNodePort());
    Service svc2 = client.services().inNamespace("rokumar").createOrReplace(svc);
    // Output: 32290
    System.out.println(svc2.getSpec().getPorts().get(0).getNodePort());
}

@saparaj
Copy link
Author

saparaj commented Aug 31, 2020

Hi @rohanKanojia,

Is there any timeline for this issue fix?

Thanks,
Swarda

@rohanKanojia
Copy link
Member

I would try to fix it along with #2399

@manusa
Copy link
Member

manusa commented Sep 14, 2020

Discussion for this issue is open in #2454. please share your thoughts there.
Closing this issue in favor of the other.

@manusa manusa closed this as completed Sep 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants