有没有办法从
kubectl
获取输出的默认模板,如果没有,是否有这些的在线资源?
它输出哪种格式并不重要,我只是对如何从对象 kubectl 查询构造输出的参考感兴趣。
Kubernetes documentation 展示了如何构建 custom-columns (还有一个 go-template 和 jsonpath 方法可以做到这一点)来自
kubectl
的输出。
使用describe,或--output json或yaml,我可以获得完整的对象列表,并搜索它来组装类似的输出,但我想编写一个简单的工具,将一列添加到现有输出,为此我需要一个“默认输出”的起点。
你激起了我的好奇心。
这不是答案,但希望有帮助。
我尝试了以下方法来收集
kubectl
进行的 API 调用:
kubectl get deployments --all-namespaces --v=9
而且,输出包含以下内容的本质(我使用
kubectl proxy --port=8801
来简化这一点):
curl \
--get \
--header "Accept: application/json;as=Table;v=v1;g=meta.k8s.io,application/json;as=Table;v=v1beta1;g=meta.k8s.io,application/json" \
http://localhost:8001/apis/apps/v1/deployments?limit=1
{
"kind": "Table",
"apiVersion": "meta.k8s.io/v1",
"metadata": {
"resourceVersion": "4949817",
"continue": "[redacted]",
"remainingItemCount": 1
},
"columnDefinitions": [
{
"name": "Name",
"type": "string",
"format": "name",
"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: https://kubernetes.io/docs/concepts/overview/working-with-objects/names#names",
"priority": 0
},
{
"name": "Ready",
"type": "string",
"format": "",
"description": "Number of the pod with ready state",
"priority": 0
},
{
"name": "Up-to-date",
"type": "string",
"format": "",
"description": "Total number of non-terminated pods targeted by this deployment that have the desired template spec.",
"priority": 0
},
{
"name": "Available",
"type": "string",
"format": "",
"description": "Total number of available pods (ready for at least minReadySeconds) targeted by this deployment.",
"priority": 0
},
{
"name": "Age",
"type": "string",
"format": "",
"description": "CreationTimestamp is a timestamp representing the server time when this object was created. It is not guaranteed to be set in happens-before order across separate operations. Clients may not set this value. It is represented in RFC3339 form and is in UTC.\n\nPopulated by the system. Read-only. Null for lists. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata",
"priority": 0
},
{
"name": "Containers",
"type": "string",
"format": "",
"description": "Names of each container in the template.",
"priority": 1
},
"rows": [...]
所以,我并不完全清楚
Deployment
是如何解析为 Table
类型(我之前不知道存在),但它似乎与内置资源的打印列相匹配。