1

我试图在 Kubernetes 中访问我的自定义资源定义端点,但找不到 Kubernetes 如何在 Kubernetes API 中公开我的自定义资源定义的确切示例。如果我用这个点击自定义服务 API:

https://localhost:6443/apis/apiextensions.k8s.io/v1beta1/customresourcedefinitions

我收到了这个回复

"items": [
    {
        "metadata": {
            "name": "accounts.stable.ibm.com",
            "selfLink": "/apis/apiextensions.k8s.io/v1beta1/customresourcedefinitions/accounts.stable.ibm.com",
            "uid": "eda9d695-d3d4-11e9-900f-025000000001",
            "resourceVersion": "167252",
            "generation": 1,
            "creationTimestamp": "2019-09-10T14:11:48Z",
            "deletionTimestamp": "2019-09-12T22:26:20Z",
            "finalizers": [
                "customresourcecleanup.apiextensions.k8s.io"
            ]
        },
        "spec": {
            "group": "stable.ibm.com",
            "version": "v1",
            "names": {
                "plural": "accounts",
                "singular": "account",
                "shortNames": [
                    "acc"
                ],
                "kind": "Account",
                "listKind": "AccountList"
            },
            "scope": "Namespaced",
            "versions": [
                {
                    "name": "v1",
                    "served": true,
                    "storage": true
                }
            ],
            "conversion": {
                "strategy": "None"
            }
        },
        "status": {
            "conditions": [
                {
                    "type": "NamesAccepted",
                    "status": "True",
                    "lastTransitionTime": "2019-09-10T14:11:48Z",
                    "reason": "NoConflicts",
                    "message": "no conflicts found"
                },
                {
                    "type": "Established",
                    "status": "True",
                    "lastTransitionTime": null,
                    "reason": "InitialNamesAccepted",
                    "message": "the initial names have been accepted"
                },
                {
                    "type": "Terminating",
                    "status": "True",
                    "lastTransitionTime": "2019-09-12T22:26:20Z",
                    "reason": "InstanceDeletionCheck",
                    "message": "could not confirm zero CustomResources remaining: timed out waiting for the condition"
                }
            ],
            "acceptedNames": {
                "plural": "accounts",
                "singular": "account",
                "shortNames": [
                    "acc"
                ],
                "kind": "Account",
                "listKind": "AccountList"
            },
            "storedVersions": [
                "v1"
            ]
        }
    }
]
}

这让我相信我已经正确地创建了自定义资源帐户。有许多示例似乎不太正确,我在 Kubernetes REST api 中找不到我的资源。我可以使用来自kubectl的自定义资源,但我需要使用 RESTful API 公开它。

https://localhost:6443/apis/stable.example.com/v1/namespaces/default/accounts

返回

404 page not found

然而:

https://localhost:6443/apis/apiextensions.k8s.io/v1beta1/apis/stable.ibm.com/namespaces/default/accounts

返回

{
"kind": "Status",
"apiVersion": "v1",
"metadata": {},
"status": "Failure",
"message": "the server could not find the requested resource",
"reason": "NotFound",
"details": {},
"code": 404
}

我查看了https://docs.okd.io/latest/admin_guide/custom_resource_definitions.htmlhttps://kubernetes.io/docs/tasks/access-kubernetes-api/custom-resources/custom-resource-definitions/

确切的 URL 将不胜感激。

4

1 回答 1

2

这是在某些顶级调试级别上检索 K8s REST API资源执行命令的一种相当不错的方式kubectl get,例如评论中提到的@Suresh Vishnoi:

kubectl get <api-resource> -v=8

显然,最终由@Amit Kumar Gupta 检查,根据您的 CRD json 输出访问自定义资源的正确 URL 如下:

https://<API_server>:port/apis/stable.ibm.com/v1/namespaces/default/accounts

根据您可以选择的身份验证方法:X509 客户端证书静态令牌文件承载令牌HTTP API 代理,以便针对 Kubernetes API 对用户请求进行身份验证。

于 2019-09-17T08:20:33.423 回答