illustrate:
Official API:
http://kubernetes.io/kubernetes/third_party/swagger-ui/#/
Notice:
The api of k8s is strictly in accordance with the restful style, that is, the same
/api/v1/namespaces/{namespace}/pods
If it is POST, it will create a pod, if it is DELETE, it will delete the pod
This article excerpts some of the APIs we need in our daily use to provide agent calls
1. pod operation
1. Create a pod
POST /api/v1/namespaces/{namespace}/pods //Here our namespaces are default
Type: application/json
Parameters: refer to the official
2. Delete a pod
DELETE /api/v1/namespaces/{namespace}/pods
3. View the pod list
GET /api/v1/namespaces/{namespace}/pods
4. View the pod with the specified name
GET /api/v1/namespaces/{namespace}/pods/{name}
Two.rc operation: Replicationcontroller
1. Create an rc
POST /api/v1/namespaces/{namespace}/replicationcontrollers
2. delete an rc
DELETE /api/v1/namespaces/{namespace}/replicationcontrollers/{name}
3. Get the rc list
GET /api/v1/namespaces/{namespace}/replicationcontrollers
4. Get the rc of the specified name
GET /api/v1/namespaces/{namespace}/replicationcontrollers/{name}
5. Replace the specified rc
PUT /api/v1/namespaces/{namespace}/replicationcontrollers/{name}
三.Service操作
1.创建一个新的service
POST /api/v1/namespaces/{namespace}/services
2.删除一个指定service
DELETE /api/v1/namespaces/{namespace}/services/{name}
3.获取一个指定service的信息
GET /api/v1/namespaces/{namespace}/services/{name}
4.显示所有service列表及信息
GET /api/v1/namespaces/{namespace}/services
四.Node操作(节点/minion)
1.创建一个新的node
POST /api/v1/nodes
2.获取所有k8s的node列表
GET /api/v1/nodes
3.删除指定node
DELETE /api/v1/nodes/{name}
4.获取指定node信息
GET /api/v1/nodes/{name}
不难发现,一旦统一风格后,restful api就显得非常清楚明了,路径一致,只需要改变请求方法即可.
五.实践:通过http请求删除一个pod
具体执行一个请求,比如在10.1.1.1上部署了整个k8s环境,并且配置了api server端口为8080。
此时机子上面跑了一个pod:test-pod。
我们测试一下通过http请求删除pod,而不是kubectl delete pod name.
请求path:
10.1.1.1:8080/api/v1/namespaces/default/pods
请求方法:
http delete
测试代码如下:
待续.
直接http get显示pods信息
http://10.1.1.1:8080/api/v1/namespaces/default/pods
这里写图片描述
确实列出了所有pod的信息.验证了restful api
其他资料:
Kubernetes权威指南之Kubernetes API详解
http://www.infoq.com/cn/articles/Kubernetes-API?amp&&
http://blog.csdn.net/jinzhencs/article/details/51452208