I have created MongoDB sharded cluster and exposed nodes using the following configuration in the cr.yaml:
expose:
enabled: true
exposeType: LoadBalancer
To expose nodes I am using aws-loadbalancer-controller and Network Load balancers.
When I change exposeType from LoadBalancer to ClusterIP I can see that the replicas kubernetes service type has been changed from LoadBalancer to ClusterIP. But when I check in the AWS console I can see that Load balancers still exist and are not removed.
Is this normal behavior or is something wrong with my environment?
I expect that Load balancers should be removed automatically.
By the way, I did also such testing, when I change the service type from LoadBalancer to ClusterIP directly on Kubernetes service manually, AWS Load balancers are removed automatically.
When I expose nodes using in-tree loadbalancer controller and Classic Load balancers, Load balancers are removed automatically in this case as I think is expected.
After changing in custom resource exposeType from LoadBalancer to ClusterIP, psmdb operator changed the replicas services type from LoadBalancer to ClusterIP accordingly:
But when checking in the AWS console we can see that Load balancers exist and are not removed.
In the same case but if I change the service type from LoadBalancer to ClusterIP directly on the replicas services by hand we can see in AWS console that Load balancers have been removed.
I expect that Load balancers should be removed automatically in AWS console in the case when psmdb operator changes the service type, but this doesn’t happen. What can be the reason for this?
On the other hand the possible workaround from operator side would maybe be if there is such a change from LB->ClusterIP to not just change the service, but instead delete and recreate, because if I’m not wrong in that case load balancer in the cloud would be deleted.
The referenced issue is quite outdated, as I mentioned in my first post, this issue does not exist with the legacy in-tree AWS cloud provider, it exists when AWS Load Balancer Controller manages Kubernetes Services.
I have opened the corresponding issue at the AWS Load Balancer Controller project but there have been no results so far.
I would appreciate it if you could provide more information on this question:
It looks like the reason for the issue is that psmdb operator is deleting the .metadata.finalizers section of the managed Service object when changing exposeType: LoadBalancer to ClusterIP, and aws-load-balancer-controller does not know that it has to remove the Load Balancer and other AWS resources. The aws-load-balancer-controller must remove the finalizers section after cleaning up AWS resources. psmdb operator should not do this.
Here is how one of the Kubernetes services created with psmdb operator looks like before updating the exposeType: LoadBalancer → ClusterIP
As we can see the finalizers section disappeared from the service object.
However, if to check in the AWS console, AWS Load Balancer and other AWS resources still exist.