简体   繁体   English

Kubernetes REST API

[英]Kubernetes REST API

Does kubernetes accessible via a REST API?是否可以通过 REST API 访问 kubernetes? I was looking over at the Kubernetes API page and it all looks very cryptic / incomplete.我正在查看Kubernetes API页面,它看起来非常神秘/不完整。 They talk about new versions but have not disclosed the API usage or docs anywhere.他们谈论新版本,但没有在任何地方公开 API 用法或文档。 I just wanted to know if there is a way to access the cluster information in any other way other than using the kubectl command.我只是想知道除了使用kubectl命令之外,是否还有其他方式可以访问集群信息。

Example usage:用法示例:

What I do now:我现在应该做什么:

kubectl get pod --context='my-prod-cluster'

What I'd like to do:我想做什么:

curl GET /some/parameters/to/get/info

您可以通过将--v=8传递给任何 kubectl 命令来查看 kubectl 正在进行的所有 API 调用

The REST API is fully documented on the Kubernetes website: https://kubernetes.io/docs/reference/using-api/api-overview/ Kubernetes 网站上完整记录了 REST API: https ://kubernetes.io/docs/reference/using-api/api-overview/

It includes info on how to reach the API , be authorized to use the API , and a full breakdown of what API objects are available and what operations you can do on them.它包括有关如何访问 API被授权使用 API以及可用 API 对象以及您可以对它们执行哪些操作的完整分类的信息。

The API is available to you outside of kubectl .您可以在kubectl之外使用该 API。 In fact, my understanding is that underneath it all kubectl is just making REST calls to the API server.事实上,我的理解是,在其kubectl ,所有kubectl只是对 API 服务器进行 REST 调用。 In a cluster using TLS certificates for authentication, a curl call to list your pods might look something like this (you can get your apiserver location/port with kubectl cluster-info | grep 'Kubernetes master' ):在使用 TLS 证书进行身份验证的集群中,用于列出 pod 的 curl 调用可能如下所示(您可以使用kubectl cluster-info | grep 'Kubernetes master'获取 apiserver 位置/端口):

curl --cert myuser.pem --key myuser-key.pem --cacert /path/to/ca.pem https://my-prod-cluster-apiserver:6443/api/v1/pods

This doc shows how to use kubectl proxy to allow you to explore the Swagger-generated API docs on your own cluster. 本文档展示了如何使用kubectl proxy来允许您在自己的集群上探索 Swagger 生成的 API 文档。

I think this is maybe what you find , though it is not always up to date.我认为这可能是您所发现的,尽管它并不总是最新的。 http://kubernetes.io/kubernetes/third_party/swagger-ui/ http://kubernetes.io/kubernetes/third_party/swagger-ui/

Kubernetes has an API reference page. Kubernetes 有一个 API 参考页面。 It details all the operations accessible via the API.它详细说明了可通过 API 访问的所有操作。 To access your cluster's API locally, make sure to proxy in, using kubectl proxy (after set-up of course).要在本地访问集群的 API,请确保使用kubectl proxy (当然是在设置之后)进行kubectl proxy

API Reference: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.11/ API 参考: https : //kubernetes.io/docs/reference/generated/kubernetes-api/v1.11/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM