服务

提示

本文所介绍的 OpenAPI 适用于 K8s YAML 服务。

获取服务列表

测试服务

请求

  1. GET /openapi/service/yaml/services?projectKey=<项目标识>

Query 参数说明

参数名类型描述必填
projectKeystring项目标识

返回说明

参数名类型描述
service_namestring服务名称
typestring服务类型,固定值 k8s
containers[]Container服务组件列表

Container 参数说明

参数名类型描述
namestring服务组件名称
imagestring服务组件的镜像信息
image_namestring服务组件的镜像名称

返回示例

点击查看

  1. {
  2. "service": [
  3. {
  4. "service_name": "service-1",
  5. "type": "k8s",
  6. "containers": [
  7. {
  8. "name": "myapp-1",
  9. "image": "koderover.tencentcloudcr.com/koderover-demo/myapp-1:v0.1__linux_amd64",
  10. "image_name": "myapp-1"
  11. }
  12. ]
  13. }
  14. ]
  15. }

生产服务

请求

  1. GET /openapi/service/yaml/production/services?projectKey=<项目标识>

Query 参数说明

参数名类型描述必填
projectKeystring项目标识

返回说明

参数名类型描述
service_namestring服务名称
typestring服务类型,固定值 k8s
containers[]Container服务组件列表

Container

参数名类型描述
namestring服务组件名称
imagestring服务组件的镜像信息
image_namestring服务组件的镜像名称

返回示例

点击查看

  1. [
  2. {
  3. "service_name": "service-1",
  4. "type": "k8s",
  5. "containers": [
  6. {
  7. "name": "myapp-1",
  8. "image": "koderover.tencentcloudcr.com/koderover-demo/myapp-1:v0.1__linux_amd64",
  9. "image_name": "myapp-1"
  10. }
  11. ]
  12. }
  13. ]

获取服务详情

测试服务

请求

  1. GET /openapi/service/yaml/:serviceName?projectKey=<项目标识>

路径参数说明

参数名类型描述必填
serviceNamestring服务名称

Query 参数说明

参数名类型描述必填
projectKeystring项目标识

返回说明

参数名类型描述
service_namestring服务名称
created_bystring服务创建者
created_timeint服务创建时间
typestring服务类型,固定为 k8s
containers[]Container服务组件列表
service_variable_kvs[]KeyVal服务变量列表
yamlstring服务配置的 YAML 内容

Container 参数说明

参数名类型描述
namestring服务组件名称
imagestring服务组件的镜像信息
image_namestring服务组件的镜像名称

KeyVal 参数说明

参数名说明类型必填
key变量的键string
value变量的值,若有嵌套值,使用 json 格式any
type变量值的类型,有四种类型:bool、string、enum、yamlstring
options变量可选值列表,当 typeenum 时该字段有意义[]string
desc变量描述信息String

返回示例

点击查看

  1. {
  2. "service_name": "service2",
  3. "type": "k8s",
  4. "created_by": "admin",
  5. "created_time": 1689660993,
  6. "yaml": "apiVersion: apps/v1\nkind: Deployment\nmetadata:\n name: service2\n labels: \n app.kubernetes.io/name: ai-test-2\n app.kubernetes.io/instance: service2\n hello: test\nspec:\n selector:\n matchLabels:\n app.kubernetes.io/name: ai-test-2\n app.kubernetes.io/instance: service2\n replicas: 1\n template:\n metadata: \n labels:\n app.kubernetes.io/name: ai-test-2\n app.kubernetes.io/instance: service2\n hello: {{.world}}\n spec:\n containers:\n - name: service2\n image: koderover.******.com/koderover-demo/service2:latest\n imagePullPolicy: Always \n command:\n - /workspace/service2\n ports:\n - protocol: TCP\n containerPort: {{.port}}\n resources:\n limits:\n memory: {{.memoryLimit}}\n cpu: {{.cpuLimit}}\n---\napiVersion: v1\nkind: Service\nmetadata:\n name: service2\n labels:\n app.kubernetes.io/name: ai-test-2\n app.kubernetes.io/instance: service2\nspec:\n type: NodePort\n ports:\n - protocol: TCP\n port: {{.port}}\n targetPort: {{.port}}",
  7. "containers": [
  8. {
  9. "name": "service2",
  10. "image": "koderover.******.com/koderover-demo/service2:latest",
  11. "image_name": "service2"
  12. }
  13. ],
  14. "service_variable_kvs": [
  15. {
  16. "key": "cpuLimit",
  17. "value": "55m",
  18. "type": "string",
  19. "options": [],
  20. "desc": ""
  21. }
  22. ]
  23. }

生产服务

请求

  1. GET /openapi/service/yaml/production/:serviceName?projectKey=<项目标识>

路径参数说明

参数名类型描述必填
serviceNamestring服务名称

Query 参数说明

参数名类型描述必填
projectKeystring项目标识

返回说明

参数名类型描述
service_namestring服务名称
created_bystring服务创建者
created_timeint服务创建时间
typestring服务类型,固定为 k8s
containers[]Container服务组件列表
service_variable_kvs[]KeyVal服务变量列表
yamlstring服务配置的 YAML 内容

Container 参数说明

参数名类型描述
namestring服务组件名称
imagestring服务组件的镜像信息
image_namestring服务组件的镜像名称

KeyVal 参数说明

参数名说明类型必填
key变量的键string
value变量的值,若有嵌套值,使用 json 格式any
type变量值的类型,有四种类型:bool、string、enum、yamlstring
options变量可选值列表,当 typeenum 时该字段有意义[]string
desc变量描述信息String

返回示例

点击查看

  1. {
  2. "service_name": "service2",
  3. "type": "k8s",
  4. "created_by": "admin",
  5. "created_time": 1689660993,
  6. "yaml": "apiVersion: apps/v1\nkind: Deployment\nmetadata:\n name: service2\n labels: \n app.kubernetes.io/name: ai-test-2\n app.kubernetes.io/instance: service2\n hello: test\nspec:\n selector:\n matchLabels:\n app.kubernetes.io/name: ai-test-2\n app.kubernetes.io/instance: service2\n replicas: 1\n template:\n metadata: \n labels:\n app.kubernetes.io/name: ai-test-2\n app.kubernetes.io/instance: service2\n hello: {{.world}}\n spec:\n containers:\n - name: service2\n image: koderover.******.com/koderover-demo/service2:latest\n imagePullPolicy: Always \n command:\n - /workspace/service2\n ports:\n - protocol: TCP\n containerPort: {{.port}}\n resources:\n limits:\n memory: {{.memoryLimit}}\n cpu: {{.cpuLimit}}\n---\napiVersion: v1\nkind: Service\nmetadata:\n name: service2\n labels:\n app.kubernetes.io/name: ai-test-2\n app.kubernetes.io/instance: service2\nspec:\n type: NodePort\n ports:\n - protocol: TCP\n port: {{.port}}\n targetPort: {{.port}}",
  7. "containers": [
  8. {
  9. "name": "service2",
  10. "image": "koderover.******.com/koderover-demo/service2:latest",
  11. "image_name": "service2"
  12. }
  13. ],
  14. "service_variable_kvs": [
  15. {
  16. "key": "cpuLimit",
  17. "value": "55m",
  18. "type": "string",
  19. "options": [],
  20. "desc": ""
  21. }
  22. ]
  23. }

使用模板新建服务

测试服务

请求

  1. POST /openapi/service/template/load/yaml

Body 参数说明

参数名说明类型必填
service_name服务名称string
project_key项目标识string
template_nameK8s Yaml 模板名称string
auto_sync自动同步开关bool
variable_yaml模板中的变量信息[]KeyVal

KeyVal 参数说明

参数名说明类型必填
key变量的键值string
value变量的值,若有嵌套值,使用 json 格式any

Body 参数示例

使用模板 microservice-template 为项目 demo 新建服务 service1

点击查看

  1. {
  2. "service_name": "service1",
  3. "project_key":"demo",
  4. "template_name": "microservice-template",
  5. "auto_sync": true,
  6. "variable_yaml": [
  7. {
  8. "key": "cpuLimit",
  9. "value": "100m"
  10. },
  11. {
  12. "key": "memoryLimit",
  13. "value": "100Mi"
  14. },
  15. {
  16. "key": "port",
  17. "value": "20221"
  18. }
  19. ]
  20. }

返回

  1. {
  2. "message": "success"
  3. }

生产服务

请求

  1. POST /openapi/service/template/production/load/yaml

Body 参数说明

参数名说明类型必填
service_name服务名称string
yaml服务的 YAML 内容string
project_key项目标识string
template_nameK8s Yaml 模板名称string
auto_sync自动同步开关bool
variable_yaml模板中的变量信息[]KeyVal

KeyVal 参数说明

参数名说明类型必填
key变量的键值string
value变量的值,若有嵌套值,使用 json 格式any

Body 参数示例

使用模板 base-template 为项目 demo 新建服务 service1

点击查看

  1. {
  2. "service_name": "service1",
  3. "production":true,
  4. "project_key":"demo",
  5. "template_name":"base-template",
  6. "auto_sync":true,
  7. "variable_yaml":[
  8. {
  9. "key":"cpuLimit",
  10. "value":"15m"
  11. }
  12. ]
  13. }

返回

  1. {
  2. "message": "success"
  3. }

手动输入新建服务

测试服务

请求

  1. POST /openapi/service/yaml/raw?projectKey=<项目标识>

Body 参数说明

参数名说明类型必填
service_name服务名称string
yaml服务的 YAML 内容string
variable_yamlyaml中的变量信息[]KeyVal

KeyVal 参数说明

参数名说明类型必填
key变量的键string
value变量的值,若有嵌套值,使用 json 格式any
type变量值的类型,有四种类型:bool、string、enum、yamlstring
options变量可选值列表,当 typeenum 时该字段有意义[]string
desc变量描述信息String

Body 参数示例

点击查看

  1. {
  2. "service_name":"service-3",
  3. "yaml":"apiVersion: v1\nkind: Service\nmetadata:\n name: a\n labels:\n app: a\nspec:\n ports:\n - name: http\n port: 80\n targetPort: 8080\n selector:\n app: a\n\n---\n\napiVersion: apps/v1\nkind: Deployment\nmetadata:\n name: a\n labels:\n app: a\nspec:\n selector:\n matchLabels:\n app: a\n replicas: 1\n template:\n metadata:\n labels:\n app: a\n spec:\n containers:\n - name: myapp-1\n image: koderover.******.com/koderover-demo/myapp-1:v0.1__linux_amd64\n imagePullPolicy: Always\n command: [\"/myapp-1\"]\n args: [\"--downstream-addr\", \"$(DOWNSTREAM_ADDR)\", \"--headers\", \"$(HEADERS)\"]\n env:\n - name: DOWNSTREAM_ADDR\n value: \"b\"\n - name: HEADERS\n value: \"x-request-id\"\n ports:\n - containerPort: 8080\n resources:\n limits:\n cpu: {{.cpu}}\n memory: 122Mi\n",
  4. "variable_yaml":[
  5. {
  6. "key":"cpu",
  7. "value":"12m",
  8. "desc":"cpu值",
  9. "type":"string"
  10. }
  11. ]
  12. }

返回

  1. {
  2. "message": "success"
  3. }

生产服务

请求

  1. POST /openapi/service/yaml/production/raw?projectKey=<项目标识>

Body 参数说明

参数名说明类型必填
service_name服务名称string
yaml服务的 YAML 内容string
variable_yamlyaml中的变量信息[]KeyVal

KeyVal 参数说明

参数名说明类型必填
key变量的键string
value变量的值,若有嵌套值,使用 json 格式any
type变量值的类型,有四种类型:bool、string、enum、yamlstring
options变量可选值列表,当 typeenum 时该字段有意义[]string
desc变量描述信息String

Body 参数示例

点击查看

  1. {
  2. "service_name":"service-3",
  3. "yaml":"apiVersion: v1\nkind: Service\nmetadata:\n name: a\n labels:\n app: a\nspec:\n ports:\n - name: http\n port: 80\n targetPort: 8080\n selector:\n app: a\n\n---\n\napiVersion: apps/v1\nkind: Deployment\nmetadata:\n name: a\n labels:\n app: a\nspec:\n selector:\n matchLabels:\n app: a\n replicas: 1\n template:\n metadata:\n labels:\n app: a\n spec:\n containers:\n - name: myapp-1\n image: koderover.******.com/koderover-demo/myapp-1:v0.1__linux_amd64\n imagePullPolicy: Always\n command: [\"/myapp-1\"]\n args: [\"--downstream-addr\", \"$(DOWNSTREAM_ADDR)\", \"--headers\", \"$(HEADERS)\"]\n env:\n - name: DOWNSTREAM_ADDR\n value: \"b\"\n - name: HEADERS\n value: \"x-request-id\"\n ports:\n - containerPort: 8080\n resources:\n limits:\n cpu: {{.cpu}}\n memory: 122Mi\n",
  4. "variable_yaml":[
  5. {
  6. "key":"cpu",
  7. "value":"12m",
  8. "desc":"cpu值",
  9. "type":"string"
  10. }
  11. ]
  12. }

返回

  1. {
  2. "message": "success"
  3. }

更新服务配置

测试服务

请求

  1. PUT /openapi/service/yaml/:serviceName?projectKey=<project_name>

路径参数说明

参数名类型描述必填
serviceNamestring服务名称

Query 参数说明

参数名类型描述必填
projectKeystring项目标识

Body 参数说明

参数名说明类型必填
type服务类型,指定为 k8sstring
yaml服务配置的 YAML 内容string

Body 参数示例

点击查看

  1. {
  2. "type":"k8s",
  3. "yaml":"apiVersion: apps/v1\nkind: Deployment\nmetadata:\n name: service1\n labels: \n app.kubernetes.io/name: demo\n app.kubernetes.io/instance: service1\nspec:\n selector:\n matchLabels:\n app.kubernetes.io/name: demo\n app.kubernetes.io/instance: service1\n replicas: 1\n template:\n metadata: \n labels:\n app.kubernetes.io/name: demo\n app.kubernetes.io/instance: service1\n spec:\n containers:\n - name: service1\n image: koderover.******.com/koderover-demo/service1:latest\n imagePullPolicy: Always \n command:\n - /workspace/service1\n ports:\n - protocol: TCP\n containerPort: {{.port}}\n resources:\n limits:\n memory: {{.memoryLimit}}\n cpu: {{.cpuLimit}}\n---\napiVersion: v1\nkind: Service\nmetadata:\n name: service1\n labels:\n app.kubernetes.io/name: yaml-poc\n app.kubernetes.io/instance: service1\nspec:\n type: NodePort\n ports:\n - protocol: TCP\n port: {{.port}}\n targetPort: {{.port}}\n",
  4. }

返回

  1. {
  2. "message": "success"
  3. }

生产服务

请求

  1. PUT /openapi/service/yaml/production/:serviceName?projectKey=<project_name>

路径参数说明

参数名类型描述必填
serviceNamestring服务名称

Query 参数说明

参数名类型描述必填
projectKeystring项目标识

Body 参数说明

参数名说明类型必填
type服务类型,指定为 k8sstring
yaml服务配置的 YAML 内容string

Body 参数示例

点击查看

  1. {
  2. "type":"k8s",
  3. "yaml":"apiVersion: apps/v1\nkind: Deployment\nmetadata:\n name: service1\n labels: \n app.kubernetes.io/name: demo\n app.kubernetes.io/instance: service1\nspec:\n selector:\n matchLabels:\n app.kubernetes.io/name: demo\n app.kubernetes.io/instance: service1\n replicas: 1\n template:\n metadata: \n labels:\n app.kubernetes.io/name: demo\n app.kubernetes.io/instance: service1\n spec:\n containers:\n - name: service1\n image: koderover.******.com/koderover-demo/service1:latest\n imagePullPolicy: Always \n command:\n - /workspace/service1\n ports:\n - protocol: TCP\n containerPort: {{.port}}\n resources:\n limits:\n memory: {{.memoryLimit}}\n cpu: {{.cpuLimit}}\n---\napiVersion: v1\nkind: Service\nmetadata:\n name: service1\n labels:\n app.kubernetes.io/name: yaml-poc\n app.kubernetes.io/instance: service1\nspec:\n type: NodePort\n ports:\n - protocol: TCP\n port: {{.port}}\n targetPort: {{.port}}\n",
  4. }

返回

  1. {
  2. "message": "success"
  3. }

更新服务变量

测试服务

请求

  1. PUT /openapi/service/yaml/:serviceName/variable?projectKey=<projectKey>

路径参数说明

参数名类型描述必填
serviceNamestring服务名称

Query 参数说明

参数名类型描述必填
projectKeystring项目标识

Body 参数说明

参数名说明类型必填
service_variable_kvs服务变量列表[]KeyVal

KeyVal 参数说明

参数名说明类型必填
key变量的键string
value变量的值,若有嵌套值,使用 json 格式any
type变量值的类型,有四种类型:bool、string、enum、yamlstring
options变量可选值列表,当 typeenum 时该字段有意义[]string
desc变量描述信息String

Body 参数示例

点击查看

  1. {
  2. "service_variable_kvs": [
  3. {
  4. "key":"cpu",
  5. "value":"12m",
  6. "type":"string",
  7. "options":[],
  8. "desc":""
  9. }
  10. ]
  11. }

返回

  1. {
  2. "message": "success"
  3. }

生产服务

请求

  1. PUT /openapi/service/yaml/production/:serviceName/variable?projectKey=<projectKey>

路径参数说明

参数名类型描述必填
serviceNamestring服务名称

Query 参数说明

参数名类型描述必填
projectKeystring项目标识

Body 参数说明

参数名说明类型必填
service_variable_kvs服务变量列表[]KeyVal

KeyVal 参数说明

参数名说明类型必填
key变量的键string
value变量的值,若有嵌套值,使用 json 格式any
type变量值的类型,有四种类型:bool、string、enum、yamlstring
options变量可选值列表,当 typeenum 时该字段有意义[]string
desc变量描述信息String

Body 参数示例

点击查看

  1. {
  2. "service_variable_kvs": [
  3. {
  4. "key":"cpu",
  5. "value":"12m",
  6. "type":"string",
  7. "options":[],
  8. "desc":""
  9. }
  10. ]
  11. }

返回

  1. {
  2. "message": "success"
  3. }

删除服务

测试服务

请求

  1. DELETE /openapi/service/yaml/<服务名称>?projectKey=<项目标识>

返回

  1. {
  2. "message": "success"
  3. }

生产服务

请求

  1. DELETE /openapi/service/yaml/production/:serviceName?projectKey=<项目标识>

路径参数说明

参数名类型描述必填
serviceNamestring服务名称

Query 参数说明

参数名类型描述必填
projectKeystring项目标识

返回

  1. {
  2. "message": "success"
  3. }