Stars die complicated deaths. Even low-mass stars like the one we circle every year don't just cough in Act 1 and die in Act 3. It's a complex process that in some cases takes millions of years to play out. But in general, and way boiled down, it goes like this: a star runs out of hydrogen to fuse into helium in its core. The core heats up, and the outer layers puff up (like a balloon expands when the air inside is heated). The star swells up and cools off, becoming a red giant. The outer layers eventually blow off entirely, exposing the extremely hot, dense core. The heat and light from this glowing cinder excites the gas expanding into space that used to be the star's outer layers, and it glows like a neon sign. We call that object a planetary nebula (because they sometimes look like planets through a telescope: small, bright, and greenish).
That last bit doesn't take long, only a few thousand years before the gas expands so much it becomes too thin to get lit up and be seen. What's even shorter is the time between the star shedding those outer layers into space, and when they get lit up in the first place. That phase is called the proto-planetary nebula, and is so short that only a few of these objects are known. One of them is IRAS 13208-6020, seen here in a Hubble image. The gas there isn't glowing on its own just yet; it's simply reflecting the light from its star. Very soon, perhaps in the next millennium or two, the star you can see in the center will shed those last bits of gas on top of it, exposing it fully to space, and the weird lobes of material will glow far more brightly, becoming a planetary nebula proper.
Nebulae like this come in all sorts of shapes, from almost perfectly round to extremely elongated like this one. We suspect that this may be due to planets orbiting the star getting swallowed up as the star expands; the orbiting planets whip it up like an eggbeater and focus the gas into these fantastic shapes. So oddly, planets do have something to do with planetary nebulae. It's funny; sometimes art imitates nature, which then turns righ around and imitates art.
Image credit: ESA/Hubble & NASA