JavaScript / ECMAScript

Kubernetes Pod Name (RFC 1123) in JS

Validate Kubernetes pod names per the RFC 1123 DNS label rules — lowercase, ≤63 chars, no leading/trailing hyphen.

Try it in the JS tester →

Pattern

regexJS
^[a-z0-9](?:[a-z0-9\-]{0,61}[a-z0-9])?$

JavaScript / ECMAScript code

jsJavaScript
const re = new RegExp("^[a-z0-9](?:[a-z0-9\\-]{0,61}[a-z0-9])?$", "");
const input = "nginx-deployment-66b6c48dd5-abcd1";
const matches = [...input.matchAll(re)];
console.log(matches.map(m => m[0]));

Uses `String.prototype.matchAll` for global iteration (Node 12+ / all modern browsers).

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-abcd1

Matches

  • nginx-deployment-66b6c48dd5-abcd1

Input

my-app

Matches

  • my-app

Input

MyApp

No match

Same pattern, other engines

← Back to Kubernetes Pod Name (RFC 1123) overview (all engines)