'Kafka in Python on Kubernetes - perform Heathcheck

I use Kafka with the Python SDK and run the Code in a Kubernetes Cluster. The "main" consumer function looks like this:

def consume(self):
    logger.info("Consumer starting listening.")
    try:
        while True:
            msg = self.consumer.poll(timeout=0.1)
            if msg is None:
                continue
            if msg.error():
                if msg.error().code() == KafkaError._PARTITION_EOF:
                    continue
                continue
            try:
                received_message = self.json_deserialize(msg.value())
            except ValidationError as err:  
                self.consumer.commit(message=msg)
                continue
            processed_message = self.processor(received_message)
            self.producer.send_object(
                processed_message,
                topic=self.producer.topics[0],  # Success topic (aus config)
                trace_id=processed_message.header.trace_id,
            )
            self.consumer.commit(message=msg)

    except KeyboardInterrupt:
        logger.info("Received keyboard interrupt signal")
    finally:
        self.stop()

So the code performs a while loop and processes the message.

I have researched the following options:

  1. Perform a HTTP request => does not work with Kafka
  2. Process the LAST log message and check the date. => does not work, since I don´t know when the next message will be processed.

My colleagues gave me the following probes, but in my Opinion they do absolutly nothing?!

          readinessProbe:
            exec:
              command: [ '/bin/bash' ]
              args: [ '-c', 'echo readinessProbe erfolgreich' ]
            initialDelaySeconds: ${{READINESS_INITIAL_DELAY_SECONDS}}
            timeoutSeconds: ${{READINESS_TIMEOUT}}
          livenessProbe:
            exec:
              command: [ '/bin/bash' ]
              args: [ '-c', 'echo livenessProbe erfolgreich' ]
            initialDelaySeconds: ${{LIVENESS_INITIAL_DELAY_SECONDS}}
            timeoutSeconds: ${{LIVENESS_TIMEOUT}}

So my main Questions are:

  1. Am I right and the readinessprobe and livenessProbe do absolutely nothing?
  2. If yes, what would be an option to perform these probs on my pods?


Solution 1:[1]

If your probes are meant to be checking your Python pod, it doesn't matter what Kafka supports. You can wrap your Python code in a simple web server.

You're correct that echoing something is useless for checking something is ready or healthy

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 OneCricketeer