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
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
Help Center/ Ubiquitous Cloud Native Service/ User Guide/ Cluster Federation/ Using kubectl to Connect to a Federation

Using kubectl to Connect to a Federation

Updated on 2025-02-14 GMT+08:00

This section describes how you can use kubectl to connect to a federation.

Permissions

When you use kubectl to connect to a federation, UCS uses kubeconfig.json generated on the federation for authentication. This file contains user information, based on which UCS determines which Kubernetes resources can be accessed by kubectl. The permissions recorded in a kubeconfig.json file vary from user to user.

Constraints

  • For security purposes, the federation API server does not have a public IP address. UCS creates an endpoint in your VPC and subnet and connects the endpoint to the federation API server for the access to the federation. For each federation, only one endpoint is created in the same VPC. If a VPC already has an endpoint for connecting to the federation API server, the endpoint will be reused.
  • Currently, the kubectl configuration file can be downloaded only for projects in AP-Singapore.

Prerequisites

  • Before using kubectl to connect to a federation, ensure that the federation has been enabled (Enabling Cluster Federation) and is running normally.
  • Only the client in a VPC can connect to a federation using kubectl. If there is no client in the VPC, create one.
  • kubectl has been downloaded and uploaded to the client. For details about how to download kubectl, see Kubernetes releases.
  • At least the custom policy iam:clustergroups:get has been created.

Using kubectl to Connect to a Federation

  1. Log in to the UCS console and click the fleet name to access the fleet console. Then, click kubectl in Fleet Info.

    Figure 1 kubectl connection

  2. Select a project, VPC, master node subnet, and validity period as prompted and click Download to download the kubectl configuration file.

    The name of the downloaded file is {Fleet name}_kubeconfig.json.
    Figure 2 Using kubectl to connect to a federation instance
    NOTICE:
    • If the {Fleet name}_kubeconfig.json file is leaked, your clusters may be attacked. Keep it secure.
    • The validity period of the kubectl configuration file can be set as required. The options are 5 years, 1 year, 6 months, 30 days, and 15 days to 1 day. The minimum value is 1 day.

  3. Install and configure kubectl on the executor.

    1. Copy kubectl and its configuration file to the /home directory on the executor in the selected VPC and subnet.
    2. Log in to your executor and configure kubectl.
      cd /home
      chmod +x kubectl
      mv -f kubectl /usr/local/bin
      mkdir -p $HOME/.kube
      mv -f <fleet-name>_kubeconfig.json $HOME/.kube/config   --Change the fleet name in the command to the actual fleet name.

Resources and Operations Supported by a Federation

Table 1 lists the resources and operations supported by a federation. In the table, "√" means the operation can be performed on related resources. "Partially supported" means the operation can be performed on part of the resources. If there is neither "√" nor "partially supported", the operation cannot be performed on related resources.

Table 1 Resources and operations supported by a federation

Group/Version

Resource

GET

LIST

WATCH

CREATE

UPDATE

PATCH

DELETE

core/v1

pods

pods/log

-

-

-

-

-

-

pods/exec

-

-

-

-

-

pods/status

-

-

-

-

-

-

configmaps

secrets

services

nodes

-

-

namespaces

endpoints

-

-

-

-

-

events

-

-

-

-

-

limitranges

-

-

-

-

-

resourcequotas

-

-

-

-

-

persistentvolumeclaims

-

-

-

-

-

persistentvolumes

-

-

-

-

-

serviceaccounts

-

-

-

-

-

admissionregistration.k8s.io/v1

mutatingwebhookconfigurations

-

-

-

-

-

validatingwebhookconfigurations

-

-

-

-

-

apiextensions.k8s.io/v1

customresourcedefinitions

apiregistration.k8s.io/v1

apiservices

-

-

-

-

-

apps/v1

deployments

deployments/scale

-

-

-

-

-

deployments/status

-

-

-

-

-

-

daemonsets

daemonsets/status

-

-

-

-

-

-

statefulsets

statefulsets/status

-

-

-

-

-

-

replicasets

-

-

-

-

-

autoscaling/(v1, v2, v2beta1, and v2beta2)

horizontalpodautoscalers

batch/v1

jobs

jobs/status

-

-

-

-

-

-

cronjobs

cronjobs/status

-

-

-

-

-

-

discovery.k8s.io/v1

endpointslices

-

-

-

-

-

events.k8s.io/v1

events

-

-

-

-

-

networking.k8s.io/v1

ingresses

Partially supported

Partially supported

ingressclasses

-

-

-

-

-

networkpolicies

-

-

-

-

-

policy/(v1 and v1beta1)

poddisruptionbudgets

rbac.authorization.k8s.io/v1

clusterrolebindings

clusterroles

rolebindings

roles

storage.k8s.io/v1

storageclasses

-

-

-

-

-

CAUTION:
  • Custom resources in a cluster can be operated through the federation entry only after the CRD is registered with the federation.
  • The UPDATE and PATCH operations of ingress objects can be only performed on resources on the federation control plane, not in member clusters.

FAQ

  • If the following error message is displayed when you access federated resources, you do not have permissions to operate the resources. In this case, apply for permissions by referring to RBAC Authorization for Cluster Federations.

  • If "Precondition Required" is displayed when you access the federation and cluster resources, the cluster may be disconnected due to network problems or member cluster faults. Perform the following steps to locate the fault.

    1. Check whether the member cluster is running normally and whether it can be connected to UCS. For details, see What Can I Do If an Attached Cluster Fails to Be Connected?
    2. Check whether the proxy-agent deployed in the member cluster is running normally. For details, see What Can I Do If proxy-agent Fails to Be Deployed?
  • If "no such host" is displayed, perform the following steps to locate the fault.

    1. Check whether the VPC endpoint exists or is deleted accidentally.
      server=`cat config  | jq '.clusters[0].cluster.server'` echo ${server:15:36}
    2. If the VPC endpoint exists, check whether the executor and the VPC endpoint are in the same VPC and whether the network connection between them is normal.
  • If "You must be logged in to the server (Unauthorized)" is displayed, perform the following steps to locate the fault.
    1. Check whether the certificates are correct.
      Save the certificates to a temporary file.
      cd ~/.kube
      cat config  | jq '.clusters[0].cluster."certificate-authority-data"' | tr -d '"' | base64 -d > ca.crt
      cat config  | jq '.users[0].user."client-certificate-data"' | tr -d '"' | base64 -d > tls.crt
      cat config  | jq '.users[0].user."client-key-data"' | tr -d '"' | base64 -d > tls.key
      Check whether the TLS certificate and the CA certificate match.
      openssl verify -CAfile ca.crt tls.crt

      If "tls.crt: OK" is displayed, the CA certificate is correct. If it is not displayed, download the kubeconfig file again.

      NOTE:

      If the certificate verification command fails to be executed and a message is displayed indicating that there is no jq, check whether jq is installed on the node.

    2. Check whether the public key and private key of the certificate match.
      diff -eq <(openssl x509 -pubkey -noout -in tls.crt) <(openssl rsa -pubout -in tls.key)
      If "writing RSA key" is displayed, the public key and private key match. If they do not match, download the kubeconfig file again. After the verification is complete, delete the temporary file.
      rm -f ca.crt tls.crt tls.key
    3. Check whether the certificate has expired.
      Save the certificate to a temporary file.
      cd ~/.kube
      cat config  | jq '.users[0].user."client-certificate-data"' | tr -d '"' | base64 -d > tls.crt
      Check the certificate validity period.
      openssl x509 -noout -text -in tls.crt  | grep -E "Not Before|Not After"
      The certificate validity period is shown in the following figure. Check whether the current certificate is within the validity period. If the certificate expires, download the kubeconfig file again and delete the temporary file.
      rm -f tls.crt

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