Energy storage system (ESS) has been advocated as one of the key elements for the future energy system by the fast power regulation and energy transfer capabilities. In particular, for distribution networks with high penetration of renewables, ESS plays an important role in bridging the gap between the supply and demand, maximizing the benefits of renewables and providing various types of ancillary services to cope the intermittences and fluctuations, consequently improving the resilience, reliability and flexibility. To solve the voltage fluctuations caused by the high permeability of renewables in distribution networks, an optimal capacity allocation strategy of ESS is proposed in this paper. Taking the life cycle cost, arbitrage income and the benefit of reducing network losses into consideration, a bilevel optimization model of ESS capacity allocation is established, the coordination between active/reactive power of associate power conversion system is considered, and the large scale nonlinear programming problem is solved using genetic algorithm, simulated annealing and mixed integer second-order cone programming method. The feasibility and effectiveness of the proposed algorithm have been verified.