Recent proposals leverage emerging programmable switches to implement high-throughput and low-latency load balancers in the datacenter. However, most of them store per-connection states in programmable switches to ensure consistent load balancing decisions, which is costly due to the limited on-chip memory. Other proposals avoid storing per-connection states but have difficulty in large-scale deployment due to the modification of running applications. We present CDLB, a cost-effective and deployment-friendly Layer-4 load balancer based on programmable switches in the datacenter. To be cost-effective, CDLB leverages an improved hash-based algorithm that can maintain per-connection consistency in a static environment. To be easier in deployment, we introduce a small state table and design a protocol between load balancers and the controller to maintain per-connection consistency in a dynamic environment without modifying running applications. The state table stores small amounts of connection states temporarily to ensure consistent load balancing decisions under device variations. We implemented CDLB with bmv2 in the mininet environment. The evaluation results show that CDLB greatly reduces overhead and achieves better performance compared with stateful load balancers which store per-connection states in programmable switches, and CDLB maintains per-connection consistency well in a dynamic environment.