This trick is traditionally done with a metal bottlecap, but those are pretty scarce these days. Plastic caps work almost as well, plus there is less risk of cutting up your fingers.
You can do it with any closed round object.
1) The key to the whistle is to form a perfect 60 degree angle with your thumbs. It will form a 60 degree triangle with the edge of the round object. Adjust your thumbs until the triangle is about 3/16″ (4.7mm) on a side. Your thumbs must create a perfect air seal with the rest of the round object. If there is a little gap between your thumbs that can be sealed up with your chin when you press your lips against your thumb knuckles.
2) Blow gently across the top edge of the triangle and you should hear a whistle. The pitch will change as you adjust the size of the triangle. The sharper the edge on the object, the better it will whistle. The more volume there is below the circular rim, the louder it will be.
3) Only your bottom lip touches your thumb knuckles. That requires you to tilt the bottle cap away from you slightly so you are blowing right across the edge of the cap. Too high and you miss the cap, too low and you blow into the cap.