How can I stop TCP connections on my pod via Loadbalancer?

Ritika Laddha 170 Reputation points
2024-08-02T04:31:04.4833333+00:00

Hello
I am receiving continuous TCP connection on 5432 port request on my Pod, because of load balancer. I have tried making this service type ClusterIP, after that I was not getting this logs. But I want to use load balancer for external connectivity. So, Is there any way to stop this, or divert it some other port?

I even exposed one more port, but I am still getting TCP connection on 5432

  ports:
    - name: database
      protocol: TCP
      port: 5432
      targetPort: 5432
      nodePort: 31217
    - name: http
      protocol: TCP
      port: 8080
      targetPort: 8080
      nodePort: 30232

pod logs:
Actually my application prints this log for every TCP connection made by user on 5432 port, but why loadBalancer is sending this connection request? Please help me stop this.

2024-08-01 13:06:20,071 INFO  [com.roc.pos.pga.TcpServer] (vert.x-eventloop-thread-0) New connection request
2024-08-01 13:06:20,278 INFO  [com.roc.pos.pga.TcpServer] (vert.x-eventloop-thread-0) New connection request
2024-08-01 13:06:20,468 INFO  [com.roc.pos.pga.TcpServer] (vert.x-eventloop-thread-0) New connection request
2024-08-01 13:06:20,719 INFO  [com.roc.pos.pga.TcpServer] (vert.x-eventloop-thread-0) New connection request
2024-08-01 13:06:20,944 INFO  [com.roc.pos.pga.TcpServer] (vert.x-eventloop-thread-0) New connection request

Below is my load balancer configuration.

kind: Service
apiVersion: v1
metadata:
  name: server
  annotations:
    service.beta.kubernetes.io/azure-load-balancer-internal: 'true'
  finalizers:
    - service.kubernetes.io/load-balancer-cleanup
spec:
  ports:
    - name: database
      protocol: TCP
      port: 5432
      targetPort: 5432
      nodePort: 30277
  selector:
    app.kubernetes.io/instance: server
    app.kubernetes.io/name: server
  type: LoadBalancer
  sessionAffinity: None
  externalTrafficPolicy: Cluster
  ipFamilies:
    - IPv4
  ipFamilyPolicy: SingleStack
  allocateLoadBalancerNodePorts: true
  internalTrafficPolicy: Cluster
status:
  loadBalancer:
    ingress:
      - ip: 

Azure Kubernetes Service
Azure Kubernetes Service
An Azure service that provides serverless Kubernetes, an integrated continuous integration and continuous delivery experience, and enterprise-grade security and governance.
2,458 questions
{count} votes

Accepted answer
  1. Prrudram-MSFT 28,281 Reputation points Microsoft Employee Moderator
    2024-08-07T14:17:19.31+00:00

    Hi @Ritika Laddha
    I am glad to know the issue has been fixed. I am reposting this as answer to the issue for the benefit of the community users. Please accept it as answer so that this can be beneficial to other community members for remediation for similar issues.

    Issue: How can I stop TCP connections on my pod via Loadbalancer?
    Resolution:
    The original poster Ritika Laddha confirmed that adding below annotation in service, worked for me

    service.beta.kubernetes.io/port_5432_no_probe_rule: 'true'
    
    

    https://github.com/kubernetes/cloud-provider-aws/issues/168

    Please Accept Answer and hit Yes for "was this answer helpful"

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.