Hello, I have mongodb deployed in Kubernetes as statefulset with 2 nodes (primary and reader - mongo-0 and mongo-1).
I am using ec2 as a jump host to connect to that mongodb database.
My mongodb service external ip points to classic load balancer in aws:
‘External IPs
<name>.us-east-1.elb.amazonaws.com’.
I am using this connection string with command:
‘mongosh mongodb://<user>:<password>@<ec2-jumphost-IP>:57057/?directConnection=true’.
I run it from my local machine. I have ssh key and security rule whitelisted so that jump host ec2 accepts my connection.
It works fine and I get connected to mongodb. However, after some time (from hour to few hours). I am starting to get error: ‘MongoServerSelectionError: Server selection timed out after 30000 ms’.
If I get such error, I restart my mongodb statefulset and try again with same command. This case repeats - I can access my mongodb. However, some time passes and I get same timeouts again.
Please help me identify the reason why could mongodb connection work and let me connect but without changes it stops working after some time. I can only revive connection by restarting mongodb statefulset.
Classic load balancer does not have sticky sessions enabled.