Skip to main content

A Python exception that provides metadata to Kubernetes Pods when they have a catastrophic failure

Project description

python-k8s-pod-fatal

A Python exception that provides metadata to Kubernetes Pods when they have a catastrophic failure.

Description

Your Pod requires environment variables, but one of them is missing and you're tired to go over the logs from the respective container just to figured that out?

The package python_k8s_pod_fatal provides a customized Python exception that can help developers to provide an appropriated error message to be logged when the application inside a Kubernetes Pod (one or more Docker containers) has a error which is impossible to recover, thus the Pod must be terminated.

This error message will be available when you describe the Pod with a kubectl describe or kubectl get, which greatly helps with troubleshooting.

Usage of this module with a microsservice external dependencies failures is even more interesting.

How to use

Install the module from Pypi:

pip install --upgrade python_k8s_pod_fatal

Then, anywhere some module from your application:

import requests
from kubernetes.pod.exceptions import Fatal

r = requests.get('https://api.github.com/user', auth=('user', 'pass'))

if r.status_code != 200:
    raise Fatal('HTTP request to GitHub failed')

When the exception is raised, the error message will be available not only in the respective container log, but also in the pod.status.message from the Kubernetes API.

Customized log file

You can also use a customized log file (see References), but in order to do you will need to pass an additional parameter to the Fatal constructor, which defaults to /dev/termination-log. If this file is not available (the default file does exist), the instance won't try to write to it.

In this case, you probably want to change the configuration of the Pod and also pass the same value as an environment variable to your code, better defined in a single place.

See the tests of this module for an example.

References

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python_k8s_pod_fatal-0.0.1.tar.gz (16.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_k8s_pod_fatal-0.0.1-py3-none-any.whl (14.5 kB view details)

Uploaded Python 3

File details

Details for the file python_k8s_pod_fatal-0.0.1.tar.gz.

File metadata

  • Download URL: python_k8s_pod_fatal-0.0.1.tar.gz
  • Upload date:
  • Size: 16.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.0

File hashes

Hashes for python_k8s_pod_fatal-0.0.1.tar.gz
Algorithm Hash digest
SHA256 6e0822d74e27548c1cb7316c04b593815d1b299e840dac02ed361bb16a1d60cd
MD5 dec123b193cf1c0e00d58a612f3f9a30
BLAKE2b-256 27b1e833fe9acbe6ab72c8169c50e945acdfc25fde11844d9263f65040c8aa19

See more details on using hashes here.

File details

Details for the file python_k8s_pod_fatal-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for python_k8s_pod_fatal-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2955eeac993706576a6340fb0b73abb43ef88453ea944487956b53a745f33a9c
MD5 86488d75e71cc6ce88d83310323ab458
BLAKE2b-256 3a615ad39c87f02642bbd614fac3d7c33d08a5cf40a43b212b65ef56ca247c79

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page