kubernetes: Incorrect max length check on metadata.name

What happened: As far as I know metadata.name can be one or more DNS labels separated by dots (.) with the following constraints on max length: 1) each label has a max length of 63 characters 2) the maximum number of characters for the name (aka DNS subdomain) is 253 characters.

I did a couple of tests using v1.15.0 and max length for label is not respected

What you expected to happen: I was able to successfully create a pod with a name with a single label with 64 and 72 characters. See pod-name-15.pdf for example of manifest YAML file. kubectl responded as follows: pod/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx64 created

The expected outcome is an error.

pod-name-15.pdf

How to reproduce it (as minimally and precisely as possible):

Anything else we need to know?:

Environment:

  • Kubernetes version (use kubectl version): v1.15.0
  • Cloud provider or hardware configuration:
  • OS (e.g: cat /etc/os-release):
  • Kernel (e.g. uname -a):
  • Install tools:
  • Network plugin and version (if this is a network-related bug):
  • Others:

@kubernetes/sig-cli /sig cli

@kubernetes/sig-api-machinery /sig api-machinery

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 18 (9 by maintainers)

Commits related to this issue

Most upvoted comments

Let me try to clarify one last time. Yes I understand that metadata.name is a DNS_Sudomain and it has a max length of 253 characters. This is constraint #1. No problem here. So far so good.

However, the DNS _Subdomain is also made of one or more DNS Labels and each DNS Label must have a max length of 63 characters. This is constraint #2. This is the part that k8s is not following.

As far as I know both constraints must be followed.

Do you have a different interpretation? If so, then we should consider updating identifiers.md.

https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names:

By convention, the names of Kubernetes resources should be up to maximum length of 253 characters and consist of lower case alphanumeric characters, -, and ., but certain resources have more specific restrictions.

DNS-1123 subdomain allows up to 253 char.

63 char is the limit for DNS labels, e.g. for metadata.labels https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#syntax-and-character-set

The Pod “xxxxxxxxxx. xxxxxxxxxx. xxxxxxxxxx. xxxxxxxxxx. xxxxxxxxxx. xxxxxxxxxx. xxxxxxxx75” is invalid: metadata.name: Invalid value: “xxxxxxxxxx. xxxxxxxxxx. xxxxxxxxxx. xxxxxxxxxx. xxxxxxxxxx. xxxxxxxxxx. xxxxxxxx75”: a DNS-1123 subdomain must consist of lowercase alphanumeric characters, ‘-’ or ‘.’, and must start and end with an alphanumeric character (e.g. ‘example.com’, regex used for validation is ‘a-z0-9?(.a-z0-9?)*’)

I think it’s because “xxxxxxxxxx. xxxxxxxxxx. xxxxxxxxxx. xxxxxxxxxx. xxxxxxxxxx. xxxxxxxxxx. xxxxxxxx75” contains space, which isn’t allowed.