The sensor of the cameras K-5, K-01, K-30, K-5II, K-5IIs and K-50 is practically the same, so their image quality will be very similar. The K-01 has a weak AA filter and is a little sharper, and the K-5IIs has no AA filter and is sharper (but can have moiree). The K-5 (II, IIs) also record 14 bit, while the others record 12 bits. That means there is more colour information in raw data, which might give you a slight boost in IQ when post processing. And also the K-5 series can go down as low as ISO 80, while the others do not go under ISO 100.
But the real differences between K-30 and K-5 is in the features. Many things were already mentioned. The K-5 is basically the more pro-tier body, with more controls and customization, while the K-30 is slightly more user friendly.
One advantage the K-30 has is focus peaking, its a nice little function if you use live view and manual lenses.
If this is your first DSLR, the K-30 might be a better choice. The K-5 has a steeper learning curve and requires more knowledge to squeeze all of its potential out. If you are experienced with cameras (or at least patient and will take the time to learn), then the K-5 is the better choice.
Also, you can check this link and look for features that are important to you:
https://www.pentaxforums.com/forums/pentax-cameras-compared/?c1=k5ii&c2=k30