Hooking up an optocoupler in a 24V Machine, is a 2 kOhm resistor sufficient? I am going to buy an inductive probe for my Creality Ender 3 to enable ABL (Automatic Bed Leveling). And now, I have one last question left on my mind:

I am going to buy a Vishay Optokoppler Phototransistor SFH610A-1 DIP-4 Transistor DC.

Is it sufficient to put a 2&nbsp;-&nbsp;2.2&nbsp;k&Omega; resistor between the input of the octocouplers LED side and the 24&nbsp;V Output of the probe, to lower the current and voltage enough to work with the octocoupler? Or do I need something else?

On the transistor side, I will simply attach the 2 wire Z-endstop cable, +5&nbsp;V on Collector and GND on Emitter.
TL;DR
Yes, a 2 kΩ resistor is sufficient to limit the current to about 12 mA through the optocoupler. With a maximum current specification of 60 mA you require at least 400 Ω; any resistor in between the values should be suitable for this optocoupler component when used at 24 V. More information is found below.

Having a glass bed and using an inductive probe may not work optimally. In such cases a 3D touch sensor is a very good alternative. For inductive sensors, remember that these sensors optimally detect steel, aluminium is harder to detect (about 60 % less than iron; a glass sheet in between the bed and the sensor requires you to acquire a sensor with a large detection range, e.g. 8 mm or more. To optimize the detection distance such sensors need to be powered to the maximum voltage they can handle (usually 36 V) or the highest voltage you have available (e.g. power supply 12 or 24 V). To protect the board, that is only allowed to receive up to 5 V, an optocoupler is an excellent way to guarantee the separation of voltage levels.
Considering your questions, it is fair to assume you are not an experienced electronics tinkerer, purchasing an optocoupler module is the best alternative, you just screw the wires into the respective input screw terminals as shown in this answer.
As the optocoupler separates two circuits, you can safely use 24 V on the one side and the 5 V on the other side, you do not need an additional resistor when you use a module board. If you plan to buy separate components to build your own circuit, you need to look at the maximum current that the optocoupler can handle on the input side (that will be 24 V). From the documentation from the optocoupler one reads that it is limited to 60 mA. A maximum current would therefore require a resistor of:
$$ R=\frac{U}{I}=\frac{24}{60\times10^{-3}}=400\ \Omega $$
My 12 V optocoupler module uses a 1 kΩ resistor implying a 12 mA current. In your case allowing 12 mA of current yields a 2 kΩ resistor.