kubernetes - 我在哪里可以找到有关 kubernetes ID 规范的信息,即 pod 后缀 ID 长度或 replicaSet 后缀 ID 长度?
问题描述
我正在尝试查找上述信息,但似乎找不到任何具体的信息。
我已经尝试查看k8s 源代码,但在那里找到相关位有点困难,我不确定我是否可以依赖这些信息。
这样做的原因是我想在不调用 API 的情况下提取有关 pod 的某些数据。
所以有:
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
grafana-79dcc6469f-zzgmh 2/2 Running 2 4d
$ kubectl get rs
NAME DESIRED CURRENT READY AGE
collection-grafana-79dcc6469f 1 1 1 4d1h
$ kubectl get deployment
NAME READY UP-TO-DATE AVAILABLE AGE
collection-grafana 1/1 1 1 4d1h
我想提取zzgmh
为 pod ID 和79dcc6469f
副本集 ID。
解决方案
我在哪里可以找到有关 kubernetes ID 规范的信息,即 pod 后缀 ID 长度?
该simpleNameGenerator
函数在许多地方用于名称生成。
$ cat kubernetes/staging/src/k8s.io/apiserver/pkg/storage/names/generate.go
var SimpleNameGenerator NameGenerator = simpleNameGenerator{}
const (
// TODO: make this flexible for non-core resources with alternate naming rules.
maxNameLength = 63
randomLength = 5
maxGeneratedNameLength = maxNameLength - randomLength
)
func (simpleNameGenerator) GenerateName(base string) string {
if len(base) > maxGeneratedNameLength {
base = base[:maxGeneratedNameLength]
}
return fmt.Sprintf("%s%s", base, utilrand.String(randomLength))
}
replicaSet 后缀 ID 长度
从 1.8+开始,名称有 10 个符文长的后缀(辅音 + 数字)。这是通过文件控制func ControllerRevisionName
的kubernetes/pkg/controller/history/controller_history.go
。
$ cat pkg/controller/history/controller_history.go
// ControllerRevisionName returns the Name for a ControllerRevision in the form prefix-hash. If the length
// of prefix is greater than 223 bytes, it is truncated to allow for a name that is no larger than 253 bytes.
func ControllerRevisionName(prefix string, hash string) string {
if len(prefix) > 223 {
prefix = prefix[:223]
}
return fmt.Sprintf("%s-%s", prefix, rand.SafeEncodeString(strconv.FormatInt(int64(hash), 10)))
}
此外,如果您要引入自己的更改ReplicaSet
和Pod
命名,您可能需要至少查看pkg/controller/deployment/sync.go
描述podTemplateSpecHash
.
此外,如果您只需要快速浏览 pod 或跟踪日志,您可能需要检查Stern和kube-fzf工具。
推荐阅读
- elasticsearch - 将图像/二进制数据与文本日志一起存储
- javascript - 将数组值转换为对象
- c++ - 如何区分反汇编的二进制文件?
- node.js - mongodb,在附加到数组时检查键是否存在
- c# - 远程服务器返回错误:(401) Unauthorized c#
- python - 对与另一列中最常见的项目相关联的列中最常见的项目进行分组
- java - 在 getSingleResult 聚合中处理 null 的正确方法
- c# - 功能测试跳过授权 WebApplicationFactory OIDC
- python - 如何使递归函数在这个特定的 Python 脚本中工作?
- encryption - Drupal9:安装问题 PHP-加密库