Britain's ambassador to the EU has resigned months before Brexit talks are set to start.