节点组管理
更新时间:2024-06-27
创建节点组
func CreateInstanceGroup() {
// 用户的Access Key ID和Secret Access Key
AK, SK := "", ""
// 用户指定的endpoint
ENDPOINT := ""
// 初始化一个CCEClient
ccev2Client, err := v2.NewClient(AK, SK, ENDPOINT)
if err != nil {
panic(err)
}
resp, err := ccev2Client.CreateInstanceGroup(&v2.CreateInstanceGroupArgs{
ClusterID: "",
Request: &v2.CreateInstanceGroupRequest{
InstanceGroupSpec: types.InstanceGroupSpec{
InstanceGroupName: "",
ClusterID: "",
InstanceTemplate: types.InstanceTemplate{
InstanceSpec: types.InstanceSpec{
MachineType: types.MachineTypeBCC,
InstanceType: api.InstanceType34,
InstanceName: "",
VPCConfig: types.VPCConfig{
VPCSubnetID: "sbn-xxx",
SecurityGroup: types.SecurityGroup{
EnableCCERequiredSecurityGroup: true,
EnableCCEOptionalSecurityGroup: false,
},
},
InstanceResource: types.InstanceResource{
CPU: 2,
MEM: 8,
RootDiskType: api.StorageTypeHP1,
RootDiskSize: 100,
LocalDiskSize: 0,
CDSList: []types.CDSConfig{},
MachineSpec: "bcc.g5.c2m8",
},
ImageID: "7183d3d0-3e24-464d-9c02-xxxxxxx",
InstanceOS: types.InstanceOS{
ImageType: api.ImageTypeSystem,
},
SSHKeyID: "k-xxxx",
DeployCustomConfig: types.DeployCustomConfig{
KubeletRootDir: "/var/lib/kubelet",
KubeReserved: map[string]string{
"cpu": "50m",
"memory": "100Mi",
},
SystemReserved: map[string]string{
"cpu": "50m",
"memory": "100Mi",
},
ContainerdConfig: types.ContainerdConfig{
DataRoot: "/home/cce/containerd",
},
},
RelationTag: true,
InstanceChargingType: api.PaymentTimingPostPaid,
Tags: types.TagList{
{
TagKey: "tagkey",
TagValue: "tagvalue",
},
},
},
},
Replicas: 1,
},
},
})
if err != nil {
fmt.Println(err.Error())
return
}
s, _ := json.MarshalIndent(resp, "", "\t")
fmt.Println("Response:" + string(s))
}
创建节点组并关联标签
resp, err := ccev2Client.CreateInstanceGroup(&v2.CreateInstanceGroupArgs{
ClusterID: "",
Request: &v2.CreateInstanceGroupRequest{
InstanceGroupSpec: types.InstanceGroupSpec{
InstanceGroupName: "",
ClusterID: "",
InstanceTemplate: types.InstanceTemplate{
InstanceSpec: types.InstanceSpec{
// 节点组中的实例配置
//
RelationTag: true,
Tags: types.TagList{
{
TagKey: "tagkey",
TagValue: "tagvalue",
},
},
},
},
Replicas: 1,
},
},
})
if err != nil {
fmt.Println(err.Error())
return
}
s, _ := json.MarshalIndent(resp, "", "\t")
fmt.Println("Response:" + string(s))
查询节点组
func GetInstanceGroup() {
// 用户的Access Key ID和Secret Access Key
AK, SK := "", ""
// 用户指定的endpoint
ENDPOINT := ""
// 初始化一个CCEClient
ccev2Client, err := v2.NewClient(AK, SK, ENDPOINT)
if err != nil {
panic(err)
}
resp, err := ccev2Client.GetInstanceGroup(&v2.GetInstanceGroupArgs{
ClusterID: "",
InstanceGroupID: "",
})
if err != nil {
fmt.Println(err.Error())
return
}
s, _ := json.MarshalIndent(resp, "", "\t")
fmt.Println("Response:" + string(s))
// 节点组标签
tags, _ := json.MarshalIndent(resp.InstanceGroup.Spec.InstanceTemplate.Tags, "", "\t")
fmt.Println("Response:" + string(tags))
}