Device-to-device (D2D) underlay massive multipleinput multiple-output (MIMO) is a notable technology to improve spectrum efficiency by using the same frequency among both cellular user equipments (CUEs) and D2D user equipments (DUEs). In terms of communication resources, it is required to avoid assigning orthogonal pilot sequences to all CUEs and DUEs. Although sharing the same pilot sequences among user equipments (UEs) can save the communication resources, interference arises among the same pilot sequences, which is known as pilot contamination. Because the impact of this interference is still large in the conventional pilot reuse, it is highly demanded to mitigate the effect of pilot contamination. In this paper, we propose a novel pilot reuse scheme based on a graph coloring technique to mitigate the effect of pilot contamination. By leveraging the fact that the interference is alleviated when the number of antennas is large and the angle of arrivals (AOAs) of the same pilot sequences does not overlap, our method assigns the same pilot sequences so that they are not overlapped. Furthermore, to improve the channel estimation accuracy between D2D pairs, our scheme restricts reusable pilot sequences by constructing an interference graph based on graph coloring. In this graph, the nodes near to each other are connected and assigned orthogonal pilot sequences. Simulation results show that the proposed scheme outperforms the conventional one in terms of channel estimation accuracy for UEs and spectral efficiency of the system.