接口设计confluence

一、登录

1.1 config文件登录

1)接口描述

接口描述 使用config文件进行登录
URL /api/v1/login/config
Method POST

2)请求参数

参数 类型 必选 说明
file File Yes Log in to the K8S config file

3)返回参数

参数 类型 必选 说明
status Number Yes Status code
msg String Yes Statemessages
data Object Yes Object

4)例子
200 :登录成功

  1. {
  2. "status": "success",
  3. "responseData": {
  4. "validated" : true
  5. },
  6. "msg": "login success",
  7. "error": null
  8. }
  9. 200 :登录成功
  10. {
  11. "status": "success",
  12. "responseData": {
  13. "data": {
  14. "validated" : true
  15. },
  16. "totalNum" : 0
  17. },
  18. "msg": "login success",
  19. "error": null
  20. }

200 :配置文件为空

  1. {
  2. "status": "failure",
  3. "responseData":null,
  4. "msg": "login failure",
  5. "error": {
  6. "ErrorCode": "KubeSpace.Login.ConfigFileLogin.ConfigFileIsEmpty",
  7. "Description": "Login failed. Kubernetes configuration file is empty",
  8. "Solution": "检查kubernetes配置文件确认无误后再进行登录",
  9. "ErrorDetails":[{"错误细节"}],
  10. }
  11. }

400 :请求发生错误(超时、越权)

  1. {
  2. "status": "failure",
  3. "responseData":null,
  4. "error": {
  5. "ErrorCode": "xxx",
  6. "Description": "Host not found",
  7. "Solution": "http请求发生错误",
  8. "ErrorDetails":null,
  9. }
  10. }

500 :服务器发生错误

  1. {
  2. "status": "failure",
  3. "responseData":null,
  4. "error": {
  5. "ErrorCode": "xxx",
  6. "Description": "",
  7. "Solution": "服务器源代码错误",
  8. "ErrorDetails":null,
  9. }
  10. }

错误:错误码规范

1.2 token登录

1)接口描述

接口描述 使用token字符串进行登录
URL /api/v1/login/token
Method POST

2)请求参数

参数 类型 必选 说明
host string Yes The cluster IP
token string Yes Token string used to log in to K8S

3)返回参数

参数 类型 必选 说明
status Number Yes Status code
msg String Yes Statemessages
data Object Yes Object

4)例子

  1. {
  2. "data": true,
  3. "msg": "Login success",
  4. "status": 200
  5. }

二、资源管理

2.1 service资源管理


2.1.1 创建service

1)接口描述

接口描述 创建一个Service对象
URL /api/v1/namespaces/{namespace}/service
Method POST

2)请求参数

参数 类型 必选 说明
namespace string Yes The namespace to which the service belongs
file File Yes The YAML file used to create the service

3)返回参数

参数 类型 必选 说明
status Number Yes Status code
msg String Yes Statemessages
data Object Yes Object

4)例子

5)状态码

状态码 描述
201 The request has been fulfilled, resulting in the creation of a new resource.

2.1.2 更新service

1)接口描述

接口描述 替换指定的Service对象
URL /api/v1/namespaces/{namespace}/services/{name}
Method PUT

2)请求参数

参数 类型 必选 说明
name string Yes Name of the service
namespace string Yes The namespace to which the service belongs
json string Yes The YAML file used to updatethe service

3)返回参数

参数 类型 必选 说明
status Number Yes Status code
msg String Yes Statemessages
data Object Yes Object

4)例子

image.png

5)状态码

状态码 描述
200 This operation succeeds, and a Service resource object is returned.

2.1.3 查询指定的service

1)接口描述

接口描述 获取指定的Service对象
URL /api/v1/namespaces/{namespace}/services/{name}
Method GET

2)请求参数

参数 类型 必选 说明
name string Yes Name of the service
namespace string Yes The namespace to which the service belongs

3)返回参数

参数 类型 必选 说明
status Number Yes Status code
msg String Yes Statemessages
data Object Yes Object

4)例子

5)状态码

状态码 描述
200 This operation succeeds, and a Service resource object is returned.

2.1.4 指定namespace下的service

1)接口描述

接口描述 列出指定Namespace下的Service对象
URL /api/v1/namespaces/{namespace}/services
Method GET

2)请求参数

参数 类型 必选 说明
namespace string Yes The namespace to which the service belongs

3)返回参数

参数 类型 必选 说明
status Number Yes Status code
msg String Yes Statemessages
data Object Yes Object

4)例子

5)状态码

状态码 描述
200 This operation succeeds, and a group of Service resource objects is returned.


2.1.5 删除指定service

1)接口描述

接口描述 删除一个Service对象
URL /api/v1/namespaces/{namespace}/services/{name}
Method DELETE

2)请求参数

参数 类型 必选 说明
name string Yes Name of the service
namespace string Yes The namespace to which the service belongs

3)返回参数

参数 类型 必选 说明
status Number Yes Status code
msg String Yes Statemessages
data Object Yes Object

4)例子

5)状态码

状态码 描述
200 Delete a Service resource object successfully.

2.2 Workload资源管理


2.2.1 创建Workload

1)接口描述

接口描述 创建一个Workload资源对象
URL /apis/apps/v1/namespaces/{namespace}/workloadType/{deployments }
/apis/apps/v1/namespaces/{namespace}/workloadType/{statefulsets}
/apis/apps/v1/namespaces/{namespace}/workloadType/{daemonsets}
/apis/apps/v1/namespaces/{namespace}/workloadType/{replicasets}
Method POST

2)请求参数

参数 类型 必选 说明
namespace string Yes The namespace to which the workload belongs
Type string Yes workloadType
file File Yes The YAML file used to create the workload

3)返回参数

参数 类型 必选 说明
status Number Yes Status code
msg String Yes Statemessages
data Object Yes Object

4)例子

5)状态码

状态码 描述
200 This operation succeeds, and a Endpoint resource object is returned.

2.2.2 更新Workload

1)接口描述

接口描述 替换指定的Workload对象
URL /apis/apps/v1/namespaces/{namespace}/deployments/{name}
/apis/apps/v1/namespaces/{namespace}/statefulsets/{name}
/apis/apps/v1/namespaces/{namespace}/daemonsets/{name}
/apis/apps/v1/namespaces/{namespace}/replicasets/{name}
Method PUT

2)请求参数

参数 类型 必选 说明
name string Yes Name of the Workload
namespace string Yes The namespace to which the Workload belongs
byte[] string Yes The YAML file used to update the Workload

3)返回参数

参数 类型 必选 说明
status Number Yes Status code
msg String Yes Statemessages
data Object Yes Object

4)例子

5)状态码

状态码 描述
200 This operation succeeds, and a Workload resource object is returned.

2.2.3 查询Workload

1)接口描述

接口描述 获取某个Namespace下指定的Workload对象
URL /apis/apps/v1/namespaces/{namespace}/workloadTypes/{workloadType}
Method GET

2)请求参数
(无)

3)返回参数

参数 类型 必选 说明
status Number Yes Status code
msg String Yes Statemessages
data Object Yes Object

4)例子

5)状态码

状态码 描述
200 This operation succeeds, and a Workload resource object is returned.

2.2.4 删除指定Workload

1)接口描述

接口描述 删除一个Workload对象
URL /apis/apps/v1/namespaces/{namespace}/deployments/{name}
/apis/apps/v1/namespaces/{namespace}/statefulsets/{name}
/apis/apps/v1/namespaces/{namespace}/replicasets/{name}
/apis/apps/v1/namespaces/{namespace}/daemonset/{name}
Method DELETE

2)请求参数

参数 类型 必选 说明
name string Yes Name of the Workload
namespace string Yes The namespace to which the Workload belongs

3)返回参数

参数 类型 必选 说明
status Number Yes Status code
msg String Yes Statemessages
data Object Yes Object

4)例子

5)状态码

状态码 描述
200 Delete a Workload resource object successfully.

2.3 统计资源

2.4.1 获取集群节点CPU、,Memory、namespace数量、pod数量

1)接口描述

接口描述 根据Nodename获取指定的Node
URL /api/v1/index
Method GET

2)请求参数(待定)

参数 类型 必选 说明
cluster集群名称 String 是 Name of the Node.

3)返回参数

参数 类型 必选 说明
status Number Yes Status code
msg String Yes Statemessages
data Object Yes Object

4)响应示例:

5)状态码

状态码 描述
200 This operation succeeds, and a Node resource object is returned.

2.4 Node

2.4.1 获取指定的Node

1)接口描述

接口描述 根据Nodename获取指定的Node
URL /api/v1/nodes/{name}
Method GET

2)请求参数

参数 类型 必选 说明
nodename String 是 Name of the Node.

3)返回参数

参数 类型 必选 说明
status Number Yes Status code
msg String Yes Statemessages
data Object Yes Object

4)响应示例:

  1. {
  2. "data": {
  3. "Name": "k8smaster",
  4. "IP": "10.4.104.169",
  5. "Image": "CentOS Linux 7 (Core)",
  6. "System": "linux",
  7. "KernelVersion": "3.10.0-1127.el7.x86_64",
  8. "Architecture": "amd64",
  9. "CreationTime": "2021-03-30 16:26:07 +0800 CST"
  10. },
  11. "msg": "Query node success",
  12. "status": 1
  13. }

5)状态码

状态码 描述
200 This operation succeeds, and a Node resource object is returned.


2.4.2 获取Node列表

1)接口描述

接口描述 列出所有的Node
URL /api/v1/nodes
Method GET

2)请求参数

参数 类型 必选 说明
cluster集群名称 String 是 Name of the Node.

3)返回参数

参数 类型 必选 说明
status Number Yes Status code
msg String Yes Statemessages
data Object Yes Object

4)响应示例:

  1. {
  2. "data": [
  3. {
  4. "Name": "k8smaster",
  5. "IP": "10.4.104.169",
  6. "Image": "CentOS Linux 7 (Core)",
  7. "System": "linux",
  8. "KernelVersion": "3.10.0-1127.el7.x86_64",
  9. "Architecture": "amd64",
  10. "CreationTime": "2021-03-30 16:26:07 +0800 CST"
  11. },
  12. {
  13. "Name": "k8snode1",
  14. "IP": "10.4.104.170",
  15. "Image": "CentOS Linux 7 (Core)",
  16. "System": "linux",
  17. "KernelVersion": "3.10.0-1127.el7.x86_64",
  18. "Architecture": "amd64",
  19. "CreationTime": "2021-03-30 16:29:59 +0800 CST"
  20. },
  21. {
  22. "Name": "k8snode2",
  23. "IP": "10.4.104.171",
  24. "Image": "CentOS Linux 7 (Core)",
  25. "System": "linux",
  26. "KernelVersion": "3.10.0-1127.el7.x86_64",
  27. "Architecture": "amd64",
  28. "CreationTime": "2021-03-30 16:30:06 +0800 CST"
  29. }
  30. ],
  31. "msg": "Query node list success",
  32. "status": 1
  33. }

5)状态码

状态码 描述
200 This operation succeeds, and the JSONs of a group of Node objects are returned.

2.5 Namespace

2.5.1 获取指定Namespace

1)接口描述

接口描述 根据namespace名称获取详细信息
URL /api/v1/namespaces/{name}
Method GET

2)请求参数

参数 类型 必选 说明
namespace string Yes NameSpace

3)返回参数

参数 类型 必选 说明
status Number Yes Status code
msg String Yes Statemessages
data Object Yes Object

4)响应示例:

  1. {
  2. "data": {
  3. "Name": "default",
  4. "Phase": "Active",
  5. "CreationTime": "2021-03-30 16:26:08 +0800 CST",
  6. "Link": "/api/v1/namespaces/default"
  7. },
  8. "msg": "Query namespace success",
  9. "status": 1
  10. }

5)状态码

状态码 描述
200 This operation succeeds, and a Namespace resource object is returned.

2.5.2 获取namespace列表

1)接口描述

接口描述 获取集群中所有Namespace的信息
URL /api/v1/namespaces
Method GET

2)请求参数
(也可无)

参数 类型 必选 说明
cluster集群名称 String 是 Name of the Node.

3)返回参数

参数 类型 必选 说明
status Number Yes Status code
msg String Yes Statemessages
data Object Yes Object

4)响应示例:

  1. {
  2. "data": [
  3. {
  4. "Name": "acme",
  5. "Phase": "Active",
  6. "CreationTime": "2021-04-13 14:03:28 +0800 CST",
  7. "Link": "/api/v1/namespaces/acme"
  8. },
  9. {
  10. "Name": "cvtest",
  11. "Phase": "Active",
  12. "CreationTime": "2021-08-16 18:10:08 +0800 CST",
  13. "Link": "/api/v1/namespaces/cvtest"
  14. },
  15. {
  16. "Name": "default",
  17. "Phase": "Active",
  18. "CreationTime": "2021-03-30 16:26:08 +0800 CST",
  19. "Link": "/api/v1/namespaces/default"
  20. },
  21. {
  22. "Name": "demo",
  23. "Phase": "Active",
  24. "CreationTime": "2021-07-20 19:47:57 +0800 CST",
  25. "Link": "/api/v1/namespaces/demo"
  26. },
  27. {
  28. "Name": "dev",
  29. "Phase": "Active",
  30. "CreationTime": "2021-04-13 18:23:24 +0800 CST",
  31. "Link": "/api/v1/namespaces/dev"
  32. },
  33. {
  34. "Name": "kube-node-lease",
  35. "Phase": "Active",
  36. "CreationTime": "2021-03-30 16:26:07 +0800 CST",
  37. "Link": "/api/v1/namespaces/kube-node-lease"
  38. },
  39. {
  40. "Name": "kube-public",
  41. "Phase": "Active",
  42. "CreationTime": "2021-03-30 16:26:07 +0800 CST",
  43. "Link": "/api/v1/namespaces/kube-public"
  44. },
  45. {
  46. "Name": "kube-system",
  47. "Phase": "Active",
  48. "CreationTime": "2021-03-30 16:26:07 +0800 CST",
  49. "Link": "/api/v1/namespaces/kube-system"
  50. },
  51. {
  52. "Name": "my-namespace",
  53. "Phase": "Active",
  54. "CreationTime": "2021-04-13 14:09:22 +0800 CST",
  55. "Link": "/api/v1/namespaces/my-namespace"
  56. },
  57. {
  58. "Name": "roledemo",
  59. "Phase": "Active",
  60. "CreationTime": "2021-04-13 10:26:20 +0800 CST",
  61. "Link": "/api/v1/namespaces/roledemo"
  62. },
  63. {
  64. "Name": "sademo",
  65. "Phase": "Active",
  66. "CreationTime": "2021-04-20 14:42:07 +0800 CST",
  67. "Link": "/api/v1/namespaces/sademo"
  68. }
  69. ],
  70. "msg": "Query namespace list success",
  71. "status": 1
  72. }

5)状态码

状态码 描述
200 This operation succeeds, and a group of Namespace resource objects is returned.

2.6 yaml文件获取

1)接口描述

接口描述 获取集群中所有Namespace的信息
URL /api/v1/yaml
Method GET

2)请求参数
(也可无)

参数 类型 必选 说明
cluster集群名称 String 是 Name of the Node.

3)返回参数

参数 类型 必选 说明
status Number Yes Status code
msg String Yes Statemessages
data Object Yes Object

以下作废
2.4.3 获取指定Node的资源信息

1)接口描述

接口描述 根据Nodename查询指定node的资源信息
URL http://10.4.104.169:8010/api/v1/node/getResources
Method GET

2)请求参数

参数 类型 必选 说明
nodename String 是 Name of the Node.

3)返回参数

参数 类型 必选 说明
status Number Yes Status code
msg String Yes Statemessages
data Object Yes Object

4)响应示例:

  1. {
  2. "data": {
  3. "CPURequestsFraction": 18.75,
  4. "MemoryRequestsFraction": 0.7610930802963111,
  5. "PodNumber": 7
  6. },
  7. "msg": "Query node success",
  8. "status": 1
  9. }

5)状态码

状态码 描述
200 This operation succeeds, and the Resources of Node object are returned.

2.5.3 获取Namespace的数量

1)接口描述

接口描述 根据集群下Namespace的数量
URL http://10.4.104.169:8010/api/v1/namespace/queryNum
Method GET

2)请求参数
无

3)返回参数

参数 类型 必选 说明
status Number Yes Status code
msg String Yes Statemessages
data Object Yes Object

4)响应示例:

  1. {
  2. "data": 11,
  3. "msg": "Query namespace number success",
  4. "status": 1
  5. }

5)状态码

状态码 描述
200 This operation succeeds, and the number of Namespace is returned.