Key isn't the same thing as tonality, though it is a primary component of common-practice tonality—the primary musical style of Western Europe from 1650 to 1850, very generally. A key is in essence a hierarchy of pitches, in which some notes act like goals of melodic direction, and other notes act like pathways to those goals. One note, often called the tonic, is the ultimate goal and all compositions in this style will ultimately center on it (though often undergoing any number of byzantine and complex routes on the way). This tonic note will also be the note of the name of the key. So if G is the tonic note, we will call the key G Major or G minor.
In standard common-practice western music, there are seven notes that are primary (the technical term is "diatonic") to the key. There will be one version of each letter of the western musical alphabet: A, B, C, D, E, F and G. Different keys might be sharps or flats on some or all of these notes. Sharps raise a pitch by one half-step (one piano key or one guitar fret) and flats lower them by one half-step. For example, in D Major the As and Bs are natural, C is sharp, D and E are natural, F is sharp, and G is natural.
But remember, key defines a hierarchy for these pitches. The tonic of D Major is the note D, and it's important to know that because it should be the primary note of the composition and the ultimate goal of any melodic or harmonic progression. In D Major, A is the next most stable note, meaning it can often be used as a temporary goal. On the other end of the hierarchy, in D Major C# is the least stable note, and it desperately wants to resolve, or ease tension, by moving to D. G would also be a fairly unstable note in that key, and it generally wants to become a more stable note such as F#.
There are multiple ways to order to pitches of a key, but one of the most useful is as a scale. The notes of any key's scale should begin on the tonic, and then go up by alphabet (after G, go to A) until you get to a copy of the tonic one octave higher. Back to the D Major example, this would mean that we start on D—the tonic and name of the key—and move up alphabetically, like:
D E F# G A B C# D
If we number these scale degrees, then we can talk about the hierarchy of pitches just in terms of where they are in the scale. The 1st (and 8th) scale degree is the ultimate goal. The 5th (or dominant) is almost as stable, and the 3rd can be relatively stable as well. The 7th (usually called the leading tone) desperately wants to move to the tonic, and the 4th fairly strongly wants to move to the third. The 2nd wants to move down to the tonic and the 6th either wants to go down to 5 or up (via 7) to the tonic.
This is a big deal, because what it means is that once you know the key of a piece, you know exactly which notes will play these different roles. In F# major, the scale would be:
F# G# A# B C# D# E# F#
Using my earlier paragraph, you can now see that F# is the ultimate goal note, C# and A# can be temporary goals, E# will be the leading tone, etc. This is why it's important to know the key of a piece.
Think of major and minor as two different flavors of key. Major tends to be used for brighter, maybe happier or zanier music, while minor tends to be used for darker, maybe sadder or calmer music. But that's up to the composer. Objectively, they're just different scale patterns. Major, as you could probably deduce from the above examples is a scale where you start with the tonic and then go up like this (W=whole step, H=half step):
W W H W W W H
So if we start on G we get:
G -W- A -W- B -H- C -W- D -W- E -W- F# -H- G.
And then, again, we know which notes have which jobs to perform. For minor keys, the scale pattern is:
W H W W H W W
Although there are some complexities in minor that are beyond the scope of this answer involving variable sixth and seventh scale degrees. Most of the roles of the various scale degrees, however, are the same with only a few exceptions (although they are important)
In closing, it's important to note that these note roles I've been talking about are only tendencies. Individual composers, pieces and musical moments can shift them, change them and play with them in all kinds of fascinating ways. It's like knowing the letters of the DNA alphabet and how they can combine to form proteins. Useful, even necessary, info for someone studying biology, but it's not nearly enough to build a dog or a redwood tree.