The framework of nuclear energy density functionals is applied to a study of the formation and evolution of cluster states in nuclei. The relativistic functional DD-ME2 is used in triaxial and reflection-asymmetric relativistic Hartree-Bogoliubov calculations of relatively light N = Z and neutron-rich nuclei. The role of deformation and degeneracy of single-nucleon states in the formation of clusters is analyzed, and interesting cluster structures are predicted in excited configurations of Be, C, O, Ne, Mg, Si, S, Ar and Ca N = Z nuclei. Cluster phenomena in neutron-rich nuclei are discussed, and it is shown that in neutron-rich Be and C nuclei cluster states occur that are characterized by molecular bonding of α-particles by the excess neutrons.