kubectl 支持操作
CRD 类型 | 操作项 |
MachineSet | 创建原生节点池 kubectl create -f machineset-demo.yaml |
| 查看原生节点池列表 kubectl get machineset |
| 查看原生节点池 YAML 详情 kubectl describe ms machineset-name |
| 删除原生节点池(包年包月节点池需要在控制台删除) kubectl delete ms machineset-name |
| 扩容原生节点池 kubectl scale --replicas=3 machineset/machineset-name |
Machine | 查看原生节点 kubectl get machine |
| 查看原生节点 YAML 详情 kubectl describe ma machine-name |
| 删除原生节点 kubectl delete ma machine-name |
HealthCheckPolicy | 创建故障检测自愈规则 kubectl create -f demo-HealthCheckPolicy.yaml |
| 查看故障自愈规则列表 kubectl get HealthCheckPolicy |
| 查看故障自愈规则 YAML 详情 kubectl describe HealthCheckPolicy HealthCheckPolicy-name |
| 删除故障自愈规则 kubectl delete HealthCheckPolicy HealthCheckPolicy-name |
通过 YAML 使用 CRD
MachineSet
apiVersion: node.tke.cloud.tencent.com/v1beta1kind: MachineSetspec:autoRepair: false #故障自愈开关displayName: testhealthCheckPolicyName: #自愈规则名称instanceTypes: #机型规格- S5.MEDIUM2replicas: 1 #节点数scaling: #自动扩缩容策略createPolicy: ZonePrioritymaxReplicas: 1subnetIDs: #节点池子网- subnet-nnwwb64wtemplate:metadata:annotations:node.tke.cloud.tencent.com/machine-cloud-tags: '[{"tagKey":"xxx","tagValue":"xxx"}]' #腾讯云标签spec:displayName: tke-np-mpam3v4b-worker #可自定义显示名称metadata:annotations:annotation-key1: annotation-value1 #自定义annotationslabels:label-test-key: label-test-value #自定义labelsproviderSpec:type: Nativevalue:dataDisks: #数据盘参数- deleteWithInstance: truediskID: ""diskSize: 50diskType: CloudPremiumfileSystem: ext4mountTarget: /var/lib/containerdinstanceChargeType: PostpaidByHour #节点付费模式keyIDs: #节点登陆SSH参数- skey-xxxlifecycle: #自定义脚本postInit: echo "after node init"preInit: echo "before node init"management: #management参数设置,包含kubelet\\kernel\\nameserver\\hostnamesecurityGroupIDs: #安全组配置- sg-xxxxxsystemDisk: #系统盘配置diskSize: 50diskType: CloudPremiumruntimeRootDir: /var/lib/containerdtaints: #污点 非必填- effect: NoExecutekey: taint-key2value: value2type: Native
kubectl 操作 demo
MachineSet
1. 执行命令
kubectl create -f machineset-demo.yaml
根据上述 YAML 创建 MachineSet:![](https://qcloudimg.tencent-cloud.cn/image/document/462b52e2057e90b45b8b4591e62c9ad2.png)
![](https://qcloudimg.tencent-cloud.cn/image/document/462b52e2057e90b45b8b4591e62c9ad2.png)
2. 根据命令
kubectl get machineset
查看 MachineSet np-pjrlok3w 状态。![](https://qcloudimg.tencent-cloud.cn/image/document/b108fd30295629dc2d3d9acd14e3d90c.png)
![](https://qcloudimg.tencent-cloud.cn/image/document/b108fd30295629dc2d3d9acd14e3d90c.png)
此时控制台上已出现对应节点池,节点在创建中:
![](https://qcloudimg.tencent-cloud.cn/image/document/2a51ccd4a1f7f70cbd7dc30c8148e570.png)
![](https://qcloudimg.tencent-cloud.cn/image/document/2a51ccd4a1f7f70cbd7dc30c8148e570.png)
3. 根据命令
kubectl describe machineset np-pjrlok3w
查看 MachineSet np-pjrlok3w 描述:![](https://qcloudimg.tencent-cloud.cn/image/document/7d15c77fea67f7363fd8227c13184fdd.png)
![](https://qcloudimg.tencent-cloud.cn/image/document/7d15c77fea67f7363fd8227c13184fdd.png)
4. 根据命令
kubectl scale --replicas=2 machineset/np-pjrlok3w
执行节点池扩缩容:![](https://qcloudimg.tencent-cloud.cn/image/document/5e597532015c47ad14342d0a305005a5.png)
5. 根据命令
kubectl delete ms np-pjrlok3w
删除节点池。![](https://qcloudimg.tencent-cloud.cn/image/document/aac43603b33612f118b2a14c944fb1ba.png)
Machine
1. 根据命令
kubectl get machine
查看 Machine 列表:![](https://qcloudimg.tencent-cloud.cn/image/document/a27e50febe01a1b5b02e99faac522cb4.png)
此时控制台上已存在对应节点:
![](https://qcloudimg.tencent-cloud.cn/image/document/8100c432cfdd0b10f7f37101c7dd097f.png)
![](https://qcloudimg.tencent-cloud.cn/image/document/8100c432cfdd0b10f7f37101c7dd097f.png)
2. 根据命令
kubectl describe ma np-14024r66-nv8bk
查看 Machine np-14024r66-nv8bk 描述:![](https://qcloudimg.tencent-cloud.cn/image/document/ba5ce8f409cb8c985245e73ff26798d8.png)
![](https://qcloudimg.tencent-cloud.cn/image/document/ba5ce8f409cb8c985245e73ff26798d8.png)
3. 根据命令
kubectl delete ma np-14024r66-nv8bk
删除节点。说明:
如果没有调整节点池期望节点数而直接删除节点,节点池会检测到实际节点数不足以满足声明式节点数量,然后会创建一个新节点并将其加入节点池。因此,我们推荐按照以下方式进行节点删除操作:
调整期望节点数:kubectl scale --replicas=1 machineset/np-xxxxx
删除对应节点:kubectl delete machine np-xxxxxx-dtjhd
针对包年包月类型的节点,因为涉及到节点销毁退费,因此无法直接通过 kubectl 删除。