My knock sensor is just knocking endlessly without any knocks to trigger it

Now, in the tutorial it says I should wire a 1-megohm resistor in parallel to the Piezo element, is this necessary?

Yes.

So when you said

I followed the tutorial, everything is connected properly.

You were not right.