To improve the success rate of resource allocation for network function virtualization (NFV), we propose a virtual network function embedding (VNFE) algorithm based on the conditional anti-affinity degree to accomplish resource allocation for the NFV with high availability requirements of carrier networks. First, it defines the conditional anti-affinity degree to relax the constraints of anti-affinity for designing resource allocation for the NFV. Then, we construct a backup VNFE model to describe the resource allocation problem for the NFV of the carrier network. Finally, we use a particle swarm optimization algorithm to obtain the solution of VNFE to resolve the resource allocation problem for the NFV. Simulation results show that the proposed algorithm satisfies the user's availability request for the network, has a high resource utilization, and improves the success rate of resource allocation for the NFV by approximately 46%.