Costly defense traits in structured populations