How can I attach a pipe to a flat surface?
I haven't seen one for a small diameter pipe, but what you're looking for is some type of drain flange:



The top is wider to hold it in the opening, the rubber washer is below to seal the connection, and then you use a metal washer and a nut to tighten it to the surface.

With a small diameter pipe, you can improvise this with a threaded pipe and a second nut (pardon the ascii art, this is a cross section view):

                        |     |
                nut  ===|     |===
      rubber washer ....|     |....
  surface --------------|     |--------------
       metal washer ....|     |....
                nut  ===|     |===
                        |drain|
                        |     |


The downside of the improvised version is the nut and threaded pipe will sit up a bit from the bottom, so this doesn't work as well if you need it to drain completely to the bottom.