The Lucky Egg is a fairly traditional Pokemon item, though it's one that hasn't been all that prominent in the games. It's a useful late-game tool, but it's nowhere near as much a staple of regular gameplay as the item of the same name and same utility is in Pokemon Go.
The same is true in Pokemon Sun and Pokemon Moon (and their enhanced rereleases, Pokemon Ultra Sun and Pokemon Ultra Moon) - you won't be able to get yourself a lucky egg until much later in the game, but it'll still prove useful if you're training up teams for multiplayer battling or post-game content such as the battle tree, a location where you don't earn exp so your level going in is all the more important.
Some might be wondering when the earliest you can get an egg is and how you get it, though, so... let's talk about that.
How to get a lucky egg in Pokemon Ultra Sun & Moon and Pokemon Sun and Moon
The good news here is that regardless of if you're playing the regular Pokemon Sun & Moon or if you're playing the newly released Pokemon Ultra Sun & Moon, the method for getting the Lucky Egg and what it does is the same: the Lucky Egg swill make Pokemon gain experience more quickly.
The game isn't quite clear about how much extra experience you gain, but allow us to fill in where the game is vague: it's 50% faster than if you don't have the lucky egg. Alongside the Exp Share it's the most important item relating to leveling up and growing Pokemon in the whole game, espercially for that super-difficult post-game content.
The first thing you need to do in order to get your hands on a lucky egg is that you need to have finished the main part of Pokemon Sun & Moon. You'll know when you've done that - the game makes it pretty clear.
Once you've completed the game, load back in and head to Melemele Island. You want to head to the professor's house and lab - remember where? It's on the beach south of your house and just to the east of the entrance to Ten Carat Hill where there's a fly/fast travel point.
Inside, chat to the Professor. So long as you have 50 or more Pokemon in your Pokedex in full (which means you've caught 50 or more - just seeing them or scanning their QR codes doesn't count), he'll hand over a lucky egg after some chatting away.