Updated on 2023-07-03 GMT+08:00

Kubernetes APIs

Description

Kubernetes APIs are resource-based (RESTful) programming interfaces provided through HTTP. It supports query, creation, update, and deletion of various cluster resources using standard HTTP request methods (POST, PUT, PATCH, DELETE, and GET).

CCE allows you to use native Kubernetes APIs in the following ways:

Calling Kubernetes APIs Through API Gateway

You can call Kubernetes native APIs through API Gateway using the URL 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.

Table 1 URL parameters

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

Entry (URL) for a web service, which can be obtained from Endpoints.

uri

Path in which the resource requested by the API is located. Obtain the value from the URI of the API. For details, see Kubernetes API.

Calling Kubernetes APIs Through the Cluster API Server

You can use the API server of a Kubernetes cluster to call Kubernetes native APIs.

  1. Obtain the cluster certificate and API server.

    • Method 1: Obtain the certificate by calling the API for obtaining the cluster certificate, save the returned information to the kubeconfig.json file, and extract the certificate, private key, and API server information. The commands are as follows:
      # Obtain the certificate and save it as client.crt.
      cat ./kubeconfig.json |grep client-certificate-data | awk -F '"' '{print $4}' | base64 -d > ./client.crt
      # Obtain the private key and save it as client.key.
      cat ./kubeconfig.json |grep client-key-data | awk -F '"' '{print $4}' | base64 -d > ./client.key
      # Obtain the API server.
      cat ./kubeconfig.json |grep server | awk -F '"' '{print $4}'
    • Method 2: Query the API server address (private or public network address) on the Cluster Information page of the CCE console and download the certificate (client.crt and client.key files).

  2. Call native Kubernetes APIs using the cluster certificate.

    For example, run the curl command to call an API to view pod information. In the following example, 192.168.0.198:5443 is the IP address of the cluster API server.

    curl --cert ./client.crt --key ./client.key  https://192.168.0.198:5443/api/v1/namespaces/default/pods/

    For more cluster APIs, see Kubernetes APIs.

Related Documents