If you have a self-managed Kubernetes cluster that runs in an on-premises data center (IDC) or on Alibaba Cloud ECS instances, you must deploy a virtual node (VNode) in the cluster to use ECI. This topic describes how to configure certificates and manually create a VNode for your self-managed Kubernetes cluster.
Prerequisites
-
You have a Kubernetes cluster, version 1.16 to 1.30.
-
If your Kubernetes cluster is deployed in an on-premises data center, make sure that the data center network is connected to the Alibaba Cloud network through Express Connect, Smart Access Gateway (SAG), or VPN Gateway. For more information, see the following topics:
Before you begin
Before you create a VNode, gather the required parameters and review the required permissions. The following table describes the parameters you will need.
|
Parameter |
Description |
How to get |
|
region |
A region is a physical data center. Select a region based on factors such as your location, your target users' location, and resource prices. For more information, see Regions and availability zones. ECI and its related resources are created in the selected region. |
You can find ECI-supported regions on the Elastic Container Instance console or by calling the DescribeRegions operation. |
|
VPC |
A VPC is a custom private network that you create on Alibaba Cloud. VPCs are logically isolated from each other. For more information, see What is a VPC?. ECI and its related resources are created in the VPC that you configure. Note
If your Kubernetes cluster is deployed in an on-premises data center, make sure that the data center network can reach this VPC. |
You can create and view VPCs on the VPC page of the VPC console. |
|
vSwitch |
A vSwitch is a basic network device in a VPC that connects different cloud resources. When you create ECI and its related resources in a VPC, you must specify one or more vSwitches, and the system automatically selects one. |
You can create and view vSwitches on the vSwitch page of the VPC console. Select a vSwitch that belongs to the selected VPC. |
|
security group |
A security group is a virtual firewall that controls inbound and outbound traffic of resources within the group to improve network security. For more information, see Security group overview. ECI and its related resources are added to the security group. Note
We recommend that you use an enterprise security group and add the following inbound rules:
|
You can create and view security groups on the Security Group page of the ECS console. Select a security group that belongs to the selected VPC. |
When you create a VNode, you must configure the required permissions. These include the standard permissions used by native Kubernetes nodes and additional permissions that are specific to VNodes, as described in the following table.
|
Type |
Permission |
Description |
|
Standard permissions |
system:node |
Standard node permissions. |
|
system:node-proxier |
Standard kube-proxy permissions. |
|
|
system:certificates.k8s.io:certificatesigningrequests:nodeclient |
Allows a node to create certificate signing requests (CSRs). |
|
|
system:certificates.k8s.io:certificatesigningrequests:selfnodeclient |
Allows a node to request new certificates based on an existing certificate. This enables certificate rotation. |
|
|
Additional permissions |
pods update and pods patch |
Allows the VNode to update pod annotations, for example, to add computed annotations such as |
|
pvc update and pvc patch |
Allows the VNode to update PersistentVolumeClaim (PVC) annotations. |
Configure the cluster
A VNode uses a kubeconfig file to connect to the cluster. Therefore, you must issue a certificate (kubeconfig) for the VNode before you create it.
If you use the cluster's admin certificate, you can skip this section.
-
Connect to the cluster.
-
Download and run the configuration script. Select TLS bootstrapping or ServiceAccount to generate a kubeconfig file.
TLS Bootstrap
For enhanced security, we recommend TLS bootstrapping. This method automatically deploys the vnode-approver component. This component signs CSRs submitted by VNodes and is open source on GitHub. For more information, see vnode-approver.
curl -fsSL https://eci-docs.oss-cn-beijing.aliyuncs.com/vnode/vnode-deploy.sh | bash -s -- bootstrapServiceAccount
This method does not support certificate rotation. Ensure the token has a long or non-expiring validity period. This prevents the VNode from becoming unavailable due to an expired certificate.
curl -fsSL https://eci-docs.oss-cn-beijing.aliyuncs.com/vnode/vnode-deploy.sh | bash -s -- common -
Check the kubeconfig file.
The generated kubeconfig file is named vnode-config. Run the following command to view the file:
cat vnode-configWhen you check the file, verify the following:
-
Make sure that the VPC where the VNode will be created can reach the server address (for example, they are in the same VPC or connected through networking).
-
If the server address is an IP address, it must be accessible from the VNode's VPC.
-
If the server address is a domain name, it must be resolvable within the Alibaba Cloud VPC, and the resulting IP address must be accessible from the VNode's VPC.
-
-
If the
certificate-authority-dataparameter is empty, check whether the corresponding field in the~/.kube/configfile uses a file path.
TLS Bootstrap
apiVersion: v1 kind: Config current-context: kubernetes-admin@kubernetes contexts: - name: kubernetes-admin@kubernetes context: cluster: kubernetes-admin@kubernetes user: vnode namespace: kube-system clusters: - name: kubernetes-admin@kubernetes cluster: certificate-authority-data: "*****************************************==" server: https://10.16.XX.XX:6443 users: - name: vnode user: token: ******.****************ServiceAccount
apiVersion: v1 kind: Config current-context: kubernetes-admin@kubernetes contexts: - name: kubernetes-admin@kubernetes context: cluster: kubernetes-admin@kubernetes user: vnode namespace: kube-system clusters: - name: kubernetes-admin@kubernetes cluster: certificate-authority-data: "*****************************************==" server: https://10.16.XX.XX:6443 users: - name: vnode user: token: *********************************************** -
Create a VNode
Procedure
You can create a VNode in the Elastic Container Instance console or by calling an API operation.
Console
-
Log on to the Elastic Container Instance console.
-
In the top navigation bar, select a region.
-
In the left-side navigation pane, choose Virtual Node.
-
Click Create Virtual Node.
-
Configure the parameters and click OK.
The following table describes the parameters.
Parameter
Description
VPC, vSwitch, security group
The VPC, vSwitch, and security group for the VNode. These resources must be prepared as described in the Before you begin section.
KubeConfig
The kubeconfig of the Kubernetes cluster to which the VNode connects. This file must be generated as described in the Configure the cluster section.
TlsBootstrapEnabled
Specifies whether to enable TLS bootstrapping.
Enable this parameter if you generated the kubeconfig file by using the TLS bootstrap method. This also enables certificate rotation, which allows the VNode to automatically request a new certificate before the current one expires.
Tags
Tags to bind to the VNode.
You can use tags for cost allocation. After you bind a custom tag to the VNode, you can use the tag to filter the VNode's instance costs during cost analysis. For more information, see View split bills based on tags.
Taints
Taints to apply to the VNode.
resource group
A resource group is a feature that you can use to group resources under your Alibaba Cloud account. Each account has a default resource group. For more information, see Resource Management.
If you do not specify a resource group, the VNode is added to the default resource group.
API
You can call the CreateVirtualNode operation to create a VNode. The following table describes the key parameters. For more information, see CreateVirtualNode.
|
Name |
Type |
Example |
Description |
|
RegionId |
String |
cn-shanghai |
The region ID. |
|
VSwitchId |
String |
vsw-2ze23nqzig8inprou**** |
The ID of the vSwitch used by the VNode and its ECI instances. You can specify 1 to 10 vSwitches that belong to the same VPC. |
|
SecurityGroupId |
String |
sg-2ze81zoc3yl7a3we**** |
The security group ID. The VNode and its ECI instances are added to this security group. |
|
KubeConfig |
String |
JTVDbmFwaVZlcnNpb24lM0ElMjB2MSU1Q25jbHVzdGVycyUzQSU1Q24tJTIwY2x1c3RlciUzQSU1Q24uLi****** |
The kubeconfig for the VNode's Kubernetes cluster. The value must be Base64-encoded. |
|
TlsBootstrapEnabled |
Boolean |
true |
Enable this parameter if you generated the kubeconfig file by using the TLS bootstrap method. This also enables certificate rotation, which allows the VNode to automatically request a new certificate before the current one expires. |
Verify the result
After you create the VNode, wait for a few moments. Then, log on to the Kubernetes cluster and run the kubectl get nodes command to view node information.
-
If the VNode is found, it was created successfully. The expected output is similar to the following:
[root@k8s-master ~]# kubectl get nodes NAME STATUS ROLES AGE VERSION cn-beijing.vnd-2-xxx.sx61at Ready agent 132m v1.20.6 k8s-master Ready control-plane,master 169m v1.20.6 -
If the VNode is not found, the creation failed. We recommend that you troubleshoot the issue based on VNode events.
In the Elastic Container Instance console, go to the Virtual Node page. Click the ID of the target VNode, and then view the events on the Events tab.
The following list describes common event errors:
-
failed to get kubernetes server version, Get \"https://10.50.XX.XX:6443/version?timeout=32s\": net/http: request canceled (Client.Timeout exceeded while awaiting headersThis error indicates that the VPC in which the VNode resides cannot connect to the IP address of the Kubernetes API server. Make sure that the VNode and the API server are in the same VPC. If they are not, ensure they have network connectivity.
-
failed to get kubernetes server version, Get \"https://lb.kubesphere.local:6443/version?timeout=32s\": dial tcp: lookup lb.kubesphere.local on 100.100.X.:53: no such hostThis error indicates that the domain name of the Kubernetes API server cannot be resolved in the VPC. You can configure Alibaba Cloud DNS PrivateZone to add a DNS record for the domain name.
-
If you have any questions or issues when you connect a VNode to a self-managed Kubernetes cluster, search for DingTalk group 44666389 to join the VNode support group.
Prevent DaemonSet scheduling to a VNode
A VNode is a virtual node and cannot run DaemonSets. After creating a VNode, you must add a nodeAffinity to the kube-proxy DaemonSet to prevent DaemonSets from being scheduled to the VNode.
-
Edit the DaemonSet configuration.
kubectl -n kube-system edit ds kube-proxy -
Configure nodeAffinity.
Add the following YAML to
spec.template.spec:affinity: nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: nodeSelectorTerms: - matchExpressions: - key: type operator: NotIn values: - virtual-kubelet
Schedule pods to a VNode
After you create a VNode, you can use the following methods to schedule pods to run as ECI instances on the VNode.
-
Manual scheduling
You can manually schedule pods to a VNode by configuring nodeSelector and tolerations, or by specifying a nodeName. For more information, see Schedule pods to a VNode.
-
Automatic scheduling
After you deploy the eci-profile component, you can configure a custom selector to automatically schedule matching pods to the VNode. For more information, see Use eci-profile to schedule pods to a VNode.