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
Metadata
Release files for python-k8s-pod-fatal 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| python_k8s_pod_fatal-0.0.1.tar.gz | 16.7 kB | Without provenance | Details for python_k8s_pod_fatal-0.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| python_k8s_pod_fatal-0.0.1-py3-none-any.whl | Python 3 | none | any | Details for python_k8s_pod_fatal-0.0.1-py3-none-any.whl |
Total release size: 31.2 kB
Release files / python_k8s_pod_fatal-0.0.1.tar.gz
| Download URL | python_k8s_pod_fatal-0.0.1.tar.gz |
|---|---|
| Size | 16.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6e0822d74e27548c1cb7316c04b593815d1b299e840dac02ed361bb16a1d60cd
|
|
BLAKE2b-256 checksum How to use checksums |
27b1e833fe9acbe6ab72c8169c50e945acdfc25fde11844d9263f65040c8aa19
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.0
|
Release files / python_k8s_pod_fatal-0.0.1-py3-none-any.whl
| Download URL | python_k8s_pod_fatal-0.0.1-py3-none-any.whl |
|---|---|
| Size | 14.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2955eeac993706576a6340fb0b73abb43ef88453ea944487956b53a745f33a9c
|
|
BLAKE2b-256 checksum How to use checksums |
3a615ad39c87f02642bbd614fac3d7c33d08a5cf40a43b212b65ef56ca247c79
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.0
|
Security for python-k8s-pod-fatal 0.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.