Description of Kubernetes APIs
Description of Kubernetes API URL
The URL of Kubernetes-native APIs is in the format of https://{clusterid}.Endpoint/uri. In the URL, {clusterid} indicates the cluster ID, and uri indicates the resource path, that is, the path for API access.
|
Parameter |
Description |
|---|---|
|
{clusterid} |
Cluster ID. After a cluster is created, call the API for obtaining a cluster in a specified project to obtain the cluster ID. |
|
Endpoint |
URL that is the entry point for a web service. It is obtained from Regions and Endpoints. |
|
uri |
Access path of an API for performing a specified operation. Obtain the path from the URI of an API. For example, the resource-path of the API used to obtain a user token is v3/auth/tokens. |
Calling APIs
Exceptions in the Response Body of APIs for Deleting Resources
If the native SDK of Kubernetes is used to call APIs for deleting resources, the actual response may be inconsistent with the expected response. The SDK is generated based on the Swagger 2.0 OpenAPI specifications of Kubernetes and provides only one response. However, there are two types of responses. For example, after a pod is deleted, the Kubernetes status response body and the response body of the corresponding Deployment are returned. As a result, the SDK reports an error. If 200 is returned, the API is called successfully. The following is an example:
Situation 1: Kubernetes status response body
{
"kind": "Status",
"apiVersion": "v1",
"metadata": {},
"status": "Success",
"code": 200
}
Situation 2: Response body of the corresponding Deployment
{
"kind": "Pod",
"apiVersion": "v1",
"metadata": {
"name": "test-delete-pod-6fd8bd995f-225lr",
"generateName": "test-delete-pod-6fd8bd995f-",
"namespace": "default",
"selfLink": "/api/v1/namespaces/default/pods/test-delete-pod-6fd8bd995f-225lr",
"uid": "e9d2cf9e-497a-4ed3-81a7-2308c2ce7ce1",
"resourceVersion": "440357",
"creationTimestamp": "2020-10-12T02:13:17Z",
"deletionTimestamp": "2020-10-12T02:14:25Z",
"deletionGracePeriodSeconds": 30,
"labels": {
"app": "test-delete-pod",
"pod-template-hash": "6fd8bd995f"
},
"annotations": {
"k8s.v1.cni.cncf.io/network-status": "[{\n \"name\": \"default-network\",\n \"ips\": [\n \"10.0.1.133\"\n ],\n \"default\": true\n}]",
"kubernetes.io/psp": "psp-global",
"metrics.alpha.kubernetes.io/custom-endpoints": "[{\"api\":\"\",\"path\":\"\",\"port\":\"\",\"names\":\"\"}]"
},
"ownerReferences": [
{
"apiVersion": "apps/v1",
"kind": "ReplicaSet",
"name": "test-delete-pod-6fd8bd995f",
"uid": "ea5c9294-d725-4fa0-8a77-a31559281c0d",
"controller": true,
"blockOwnerDeletion": true
}
]
},
"spec": {
"volumes": [
{
"name": "default-token-pgdkj",
"secret": {
"secretName": "default-token-pgdkj",
"defaultMode": 420
}
}
],
"containers": [
{
"name": "container-0",
"image": "swr.cn-north-7.myhuaweicloud.com/paas_cce_y00416048/nginx:latest",
"env": [
{
"name": "PAAS_APP_NAME",
"value": "test-delete-pod"
},
{
"name": "PAAS_NAMESPACE",
"value": "default"
},
{
"name": "PAAS_PROJECT_ID",
"value": "47eb1d64cbeb45cfa01ae20af4f4b563"
}
],
"resources": {
"limits": {
"cpu": "250m",
"memory": "512Mi"
},
"requests": {
"cpu": "250m",
"memory": "512Mi"
}
},
"volumeMounts": [
{
"name": "default-token-pgdkj",
"readOnly": true,
"mountPath": "/var/run/secrets/kubernetes.io/serviceaccount"
}
],
"terminationMessagePath": "/dev/termination-log",
"terminationMessagePolicy": "File",
"imagePullPolicy": "Always"
}
],
"restartPolicy": "Always",
"terminationGracePeriodSeconds": 30,
"dnsPolicy": "ClusterFirst",
"serviceAccountName": "default",
"serviceAccount": "default",
"nodeName": "192.168.0.241",
"securityContext": {},
"imagePullSecrets": [
{
"name": "default-secret"
}
],
"affinity": {},
"schedulerName": "default-scheduler",
"tolerations": [
{
"key": "node.kubernetes.io/not-ready",
"operator": "Exists",
"effect": "NoExecute",
"tolerationSeconds": 300
},
{
"key": "node.kubernetes.io/unreachable",
"operator": "Exists",
"effect": "NoExecute",
"tolerationSeconds": 300
}
],
"priority": 0,
"dnsConfig": {
"options": [
{
"name": "timeout",
"value": ""
},
{
"name": "ndots",
"value": "5"
},
{
"name": "single-request-reopen"
}
]
},
"enableServiceLinks": true
},
"status": {
"phase": "Running",
"conditions": [
{
"type": "Initialized",
"status": "True",
"lastProbeTime": null,
"lastTransitionTime": "2020-10-12T02:13:17Z"
},
{
"type": "Ready",
"status": "True",
"lastProbeTime": null,
"lastTransitionTime": "2020-10-12T02:13:23Z"
},
{
"type": "ContainersReady",
"status": "True",
"lastProbeTime": null,
"lastTransitionTime": "2020-10-12T02:13:23Z"
},
{
"type": "PodScheduled",
"status": "True",
"lastProbeTime": null,
"lastTransitionTime": "2020-10-12T02:13:17Z"
}
],
"hostIP": "192.168.0.241",
"podIP": "10.0.1.133",
"podIPs": [
{
"ip": "10.0.1.133"
}
],
"startTime": "2020-10-12T02:13:17Z",
"containerStatuses": [
{
"name": "container-0",
"state": {
"running": {
"startedAt": "2020-10-12T02:13:22Z"
}
},
"lastState": {},
"ready": true,
"restartCount": 0,
"image": "nginx:latest",
"imageID": "f1c72ba4d94d57",
"containerID": "docker://8c382e61f99ff3c9fe6d5b01edaad419b878174e25792b6fe5581659b5e63c67",
"started": true
}
],
"qosClass": "Guaranteed"
}
}
For details, see the native Java SDK issue at https://github.com/kubernetes-client/java/issues/86.
Last Article: Kubernetes APIs
Next Article: Node
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.