Kubernetes Pod Name (RFC 1123) in PY
Validate Kubernetes pod names per the RFC 1123 DNS label rules — lowercase, ≤63 chars, no leading/trailing hyphen.
Try it in the PY tester →Pattern
regexPY
^[a-z0-9](?:[a-z0-9\-]{0,61}[a-z0-9])?$Python (re) code
pyPython
import re
pattern = re.compile(r"^[a-z0-9](?:[a-z0-9\-]{0,61}[a-z0-9])?$")
input_text = "nginx-deployment-66b6c48dd5-abcd1"
for m in pattern.finditer(input_text):
print(m.group(0))Stdlib `re` module — no third-party dependency. Works on Python 3.6+.
How the pattern works
Stricter than the general hostname pattern: pod names must be LOWERCASE only (per K8s spec). [a-z0-9] for first char. (?:[a-z0-9\-]{0,61}[a-z0-9])? optionally allows up to 61 more chars ending in a non-hyphen. Total length ≤63 chars per RFC 1123 label limits.
Examples
Input
nginx-deployment-66b6c48dd5-abcd1Matches
nginx-deployment-66b6c48dd5-abcd1
Input
my-appMatches
my-app
Input
MyAppNo match
—