Kubernetes Namespace 命名规则

Kubernetes About 3,257 words

查看帮助

name

kubectl explain namespaces.metadata.name

namespace

kubectl explain namespaces.metadata.namespace

输出

name

PS C:\Users\fendoudebb> kubectl explain namespaces.metadata.name
KIND:     Namespace
VERSION:  v1

FIELD:    name <string>

DESCRIPTION:
     Name must be unique within a namespace. Is required when creating
     resources, although some resources may allow a client to request the
     generation of an appropriate name automatically. Name is primarily intended
     for creation idempotence and configuration definition. Cannot be updated.
     More info: http://kubernetes.io/docs/user-guide/identifiers#names

namespace

PS C:\Users\fendoudebb> kubectl explain namespaces.metadata.namespace
KIND:     Namespace
VERSION:  v1

FIELD:    namespace <string>

DESCRIPTION:
     Namespace defines the space within which each name must be unique. An empty
     namespace is equivalent to the "default" namespace, but "default" is the
     canonical representation. Not all objects are required to be scoped to a
     namespace - the value of this field for those objects will be empty.

     Must be a DNS_LABEL. Cannot be updated. More info:
     http://kubernetes.io/docs/user-guide/namespaces

命名规则

Note: Avoid creating namespaces with the prefix kube-, since it is reserved for Kubernetes system namespaces.

  1. 不能以kube-作为前缀。
  2. 最多63个字符。
  3. 只能是小写字母和数字,或者-中划线。
  4. 首字符必须是字母或数字。
  5. 尾字符必须是字母或数字。
  6. 无法更新。

示例

说明:虽然可以创建kube-为前缀的命名空间,但官方不建议这么做。

备注:命名空间的命名规则可以使用正则[a-z0-9]([-a-z0-9]*[a-z0-9])?和最大63字符来约束。

PS C:\Users\fendoudebb> kubectl create namespace kube-test
namespace/kube-test created

PS C:\Users\fendoudebb> kubectl create namespace 123
namespace/123 created

PS C:\Users\fendoudebb> kubectl create namespace 789-
The Namespace "789-" is invalid:
* metadata.name: Invalid value: "789-": a lowercase RFC 1123 label must consist of lower case alphanumeric characters or '-', and must start and end with an alphanumeric character (e.g. 'my-name',  or '123-abc', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?')
* metadata.labels: Invalid value: "789-": a valid label must be an empty string or consist of alphanumeric characters, '-', '_' or '.', and must start and end with an alphanumeric character (e.g. 'MyValue',  or 'my_value',  or '12345', regex used for validation is '(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?')


PS C:\Users\fendoudebb> kubectl create namespace 123456789012345678901234567890123456789012345678901234567890123
namespace/123456789012345678901234567890123456789012345678901234567890123 created

PS C:\Users\fendoudebb> kubectl create namespace 1234567890123456789012345678901234567890123456789012345678901234
The Namespace "1234567890123456789012345678901234567890123456789012345678901234" is invalid:
* metadata.name: Invalid value: "1234567890123456789012345678901234567890123456789012345678901234": must be no more than 63 characters
* metadata.labels: Invalid value: "1234567890123456789012345678901234567890123456789012345678901234": must be no more than 63 characters

参考

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

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

https://datatracker.ietf.org/doc/html/rfc1123

Views: 1,067 · Posted: 2022-11-03

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓


Today On History
Browsing Refresh