Search code examples
kubernetesgoogle-kubernetes-engine

What characters are allowed in kubernetes port and container names?


What patterns are valid in kubernetes for the names of containers and ports?

I had underscores in the names of ports and containers and got an error. Replacing the underscores with hyphens worked.


Solution

  • Container names and port names must conform to the RFC 1123 definition of a DNS label.

    Names must be no longer than 63 characters, must start and end with a lowercase letter or number, and may contain lowercase letters, numbers, and hyphens.

    Expressed as a regular expression:

    [a-z0-9]([-a-z0-9]*[a-z0-9])?
    

    Here's the applicable code in GitHub for checking container names, checking port names, and defining acceptable names.