Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Situation Awareness
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive

Kubernetes APIs

Updated on 2024-10-22 GMT+08:00

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 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 --cacert ./ca.crt --cert ./client.crt --key ./client.key  https://192.168.0.198:5443/api/v1/namespaces/default/pods/

    For more cluster APIs, see Kubernetes APIs.

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.

  1. Obtain the token of the region where the cluster is located. For details about how to obtain the token, see Obtaining a Token.
  2. Obtain the cluster ID using either of the following methods:

  3. Determine the requested URL based on the URL format https://{clusterid}.Endpoint/uri.

    • {clusterid}: Obtain the value by using 2.
    • Endpoint: Obtaining the endpoint from Regions and Endpoints.

      For example, the endpoint of CCE in the my-kualalumpur-1 region is cce.my-kualalumpur-1.myhuaweicloud.com.

    • uri: Set this parameter based on the API to be called. For example, if you want to create a Deployment, the request method is POST and the API URI is /apis/apps/v1/namespaces/{namespace}/deployments, where {namespace} indicates the cluster namespace name. In this example, the value is default.

      For more APIs, see Kubernetes APIs.

    Combine the preceding parameters following the URL format https://{clusterid}.Endpoint/uri.

    The following is an example of the URL for calling the API to view information about all pods:
    https://07da5*****.cce.my-kualalumpur-1.myhuaweicloud.com/apis/apps/v1/namespaces/default/deployments

  4. Use the request method specified by the API and set the request header parameters. If parameters in the body need to be added, add the structure corresponding to the API by referring to Kubernetes APIs.

    Example curl command to call the API for creating a Deployment using POST and adding the corresponding body:

    In this example, the nginx.json file is used to create a Deployment named nginx. The Deployment uses the nginx:latest image and contains two pods. Each pod occupies 100m CPU and 200 MiB memory.

    curl --location --request POST 'https://07da5*****.cce.my-kualalumpur-1.myhuaweicloud.com/apis/apps/v1/namespaces/default/deployments' \
    --header 'Content-Type: application/json' \
    --header 'X-Auth-Token: MIIWvw******' \
    --data @nginx.json
    Header parameters contained in the request are as follows:
    Table 2 Request header parameters

    Parameter

    Mandatory

    Type

    Description

    Content-Type

    Yes

    String

    Message body type (format), for example, application/json.

    X-Auth-Token

    Yes

    String

    Requests for calling an API can be authenticated using either a token or AK/SK. If token-based authentication is used, this parameter is mandatory and must be set to a user token. For details, see Obtaining a Token.

    The content of the nginx.json file is as follows:

    {
        "apiVersion": "apps/v1",
        "kind": "Deployment",
        "metadata": {
            "name": "nginx"
        },
        "spec": {
            "replicas": 2,
            "selector": {
                "matchLabels": {
                    "app": "nginx"
                }
            },
            "template": {
                "metadata": {
                    "labels": {
                        "app": "nginx"
                    }
                },
                "spec": {
                    "containers": [
                        {
                            "image": "nginx:latest",
                            "name": "container-0",
                            "resources": {
                                "limits": {
                                    "cpu": "100m",
                                    "memory": "200Mi"
                                },
                                "requests": {
                                    "cpu": "100m",
                                    "memory": "200Mi"
                                }
                            }
                        }
                    ],
                    "imagePullSecrets": [
                        {
                            "name": "default-secret"
                        }
                    ]
                }
            }
        }
    }

Related Documents

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback