iMac occasionally gets very sluggish. Memory Pressure is high and its hard to use computer. Why is this? I have a mid-2010 iMac running High Sierra. It has started getting very sluggish several times a week. I have tracked it down to the memory pressure and the process kernal_task. Shown below is a screenshot of the activity monitor when this occurs.

As you can see the process kernal_task is using 9.43 GB of memory.  This usually lasts 20 or 30 minutes. The kernal_task will occasionally drop to 5.46 GB and then sometimes down to 1.6 GB at which time the memory pressure is small and it turns green and my machine will return to normal.
The next image is of the Activity Monitor showing CPU usage. Kernal_task is not using a lot of CPU but has been running for quite a while.

Does anyone have an idea of what is happening?
I've tried restarting my computer and quitting all open apps when it gets sluggish. Restarting the computer worked but eventually it gets sluggish again.  Restarting every time this happens is a real pain. Quitting the open apps seems to have no effect. The final image below shoes the memory pressure when things return to normal.
A dying a hard drive will actually cause this symptom as the system &quot;waits&quot; for read/write operations to complete.  It'll eventually get there, but often times, it will crash.
From the comments, you've confirmed this with the SMART status saying &quot;Failed&quot; which means that drive literally has one foot in the grave and slowly putting the other one in now.

I just hate putting money into my old computer.

I can't agree more.  However, this one might be worth an SSD upgrade. You can get a 120GB for under $20USD and a 250GB for under $40. Why go through the trouble?
Here's a little teaser....
This is a little side project I've been hacking away on... It's a white 2007 MacBook.

(Forgive the bezel, I'm dealing with an unscrupulous vendor in NJ who sent me a dead LCD and refused to exchange it due to COVID-19 and I'm waiting on a resolution from AMEX). I'm into this for about $40 (a little horse trading on ebay helps) and everything works - Ethernet, Bluetooth, external display, and even WiFi!  It's utterly useless, from a macOS perspective, but not for FreeBSD with the MATE DE. Even if all else fails, I still have a good SSD that I got for $20 that can go into another machine...
Your iMac is a tank, and I'd hate to see it meet an untimely demise.  ;-)