Create
Creates a node group in the specified Kubernetes cluster.
- TypeScript
- Python
import {
cloudApi,
decodeMessage,
serviceClients,
Session,
waitForOperation,
} from "@yandex-cloud/nodejs-sdk";
import { google } from "googleapis";
const ContainerRuntimeSettings_Type =
cloudApi.k8s.node.ContainerRuntimeSettings_Type;
const CreateNodeGroupRequest =
cloudApi.k8s.node_group_service.CreateNodeGroupRequest;
const DayOfWeek = google.type.dayofweek.DayOfWeek;
const GpuSettings_GpuEnvironment = cloudApi.k8s.node.GpuSettings_GpuEnvironment;
const IpVersion = cloudApi.k8s.node.IpVersion;
const NetworkSettings_Type = cloudApi.k8s.node.NetworkSettings_Type;
const NodeGroup = cloudApi.k8s.node_group.NodeGroup;
const Taint_Effect = cloudApi.k8s.node.Taint_Effect;
(async () => {
const authToken = process.env["YC_OAUTH_TOKEN"];
const session = new Session({ oauthToken: authToken });
const client = session.client(serviceClients.NodeGroupServiceClient);
const operation = await client.create(
CreateNodeGroupRequest.fromPartial({
clusterId: "clusterId",
// name: "name",
// description: "description",
// labels: {"key": "labels"},
nodeTemplate: {
// name: "name",
// labels: {"key": "labels"},
// platformId: "platformId",
// resourcesSpec: {
// memory: 0,
// cores: 0,
// coreFraction: 0,
// gpus: 0
// },
// bootDiskSpec: {
// diskTypeId: "diskTypeId",
// diskSize: 0
// },
// metadata: {"key": "metadata"},
// v4AddressSpec: {
// oneToOneNatSpec: {
// ipVersion: IpVersion.IPV4
// },
// dnsRecordSpecs: [{
// fqdn: "fqdn",
// dnsZoneId: "dnsZoneId",
// ttl: 0,
// ptr: true
// }]
// },
// schedulingPolicy: {
// preemptible: true
// },
// networkInterfaceSpecs: [{
// subnetIds: ["subnetIds"],
// primaryV4AddressSpec: {
// oneToOneNatSpec: {
// ipVersion: IpVersion.IPV4
// },
// dnsRecordSpecs: [{
// fqdn: "fqdn",
// dnsZoneId: "dnsZoneId",
// ttl: 0,
// ptr: true
// }]
// },
// primaryV6AddressSpec: {
// oneToOneNatSpec: {
// ipVersion: IpVersion.IPV4
// },
// dnsRecordSpecs: [{
// fqdn: "fqdn",
// dnsZoneId: "dnsZoneId",
// ttl: 0,
// ptr: true
// }]
// },
// securityGroupIds: ["securityGroupIds"]
// }],
// placementPolicy: {
// placementGroupId: "placementGroupId"
// },
// networkSettings: {
// type: NetworkSettings_Type.STANDARD
// },
// containerRuntimeSettings: {
// type: ContainerRuntimeSettings_Type.DOCKER
// },
// containerNetworkSettings: {
// podMtu: 0
// },
// gpuSettings: {
// gpuClusterId: "gpuClusterId",
// gpuEnvironment: GpuSettings_GpuEnvironment.RUNC_DRIVERS_CUDA
// }
},
scalePolicy: {
// fixedScale: {
// size: 0
// },
// autoScale: {
// minSize: 0,
// maxSize: 0,
// initialSize: 0
// }
},
// allocationPolicy: {
// locations: [{
// zoneId: "zoneId",
// subnetId: "subnetId"
// }]
// },
// deployPolicy: {
// maxUnavailable: 0,
// maxExpansion: 0
// },
// version: "version",
// maintenancePolicy: {
// autoUpgrade: true,
// autoRepair: true,
// maintenanceWindow: {
// anytime: {
// },
// dailyMaintenanceWindow: {
// startTime: {
// hours: 0,
// minutes: 0,
// seconds: 0,
// nanos: 0
// },
// duration: {
// seconds: 0,
// nanos: 0
// }
// },
// weeklyMaintenanceWindow: {
// daysOfWeek: [{
// days: [DayOfWeek.MONDAY],
// startTime: {
// hours: 0,
// minutes: 0,
// seconds: 0,
// nanos: 0
// },
// duration: {
// seconds: 0,
// nanos: 0
// }
// }]
// }
// }
// },
// allowedUnsafeSysctls: ["allowedUnsafeSysctls"],
// nodeTaints: [{
// key: "key",
// value: "value",
// effect: Taint_Effect.NO_SCHEDULE
// }],
// nodeLabels: {"key": "nodeLabels"}
})
);
const finishedOp = await waitForOperation(operation, session);
if (finishedOp.response) {
const result = decodeMessage<typeof NodeGroup>(finishedOp.response);
console.log(result);
}
})();
import os
import grpc
import yandexcloud
import {google} from "googleapis";
from yandex.cloud.k8s.v1.maintenance_pb2 import AnytimeMaintenanceWindow
from yandex.cloud.k8s.v1.node_group_service_pb2 import CreateNodeGroupMetadata
from yandex.cloud.k8s.v1.node_group_service_pb2 import CreateNodeGroupRequest
from yandex.cloud.k8s.v1.maintenance_pb2 import DailyMaintenanceWindow
const DayOfWeek = google.type.dayofweek;
from yandex.cloud.k8s.v1.maintenance_pb2 import DaysOfWeekMaintenanceWindow
from yandex.cloud.k8s.v1.node_group_pb2 import DeployPolicy
from yandex.cloud.k8s.v1.node_pb2 import DiskSpec
from yandex.cloud.k8s.v1.node_pb2 import DnsRecordSpec
from yandex.cloud.k8s.v1.node_pb2 import GpuSettings
from yandex.cloud.k8s.v1.node_pb2 import IpVersion
from yandex.cloud.k8s.v1.maintenance_pb2 import MaintenanceWindow
from yandex.cloud.k8s.v1.node_pb2 import NetworkInterfaceSpec
from yandex.cloud.k8s.v1.node_pb2 import NodeAddressSpec
from yandex.cloud.k8s.v1.node_group_pb2 import NodeGroup
from yandex.cloud.k8s.v1.node_group_pb2 import NodeGroupAllocationPolicy
from yandex.cloud.k8s.v1.node_group_pb2 import NodeGroupLocation
from yandex.cloud.k8s.v1.node_group_pb2 import NodeGroupMaintenancePolicy
from yandex.cloud.k8s.v1.node_group_service_pb2_grpc import NodeGroupServiceStub
from yandex.cloud.k8s.v1.node_pb2 import NodeTemplate
from yandex.cloud.k8s.v1.node_pb2 import OneToOneNatSpec
from yandex.cloud.k8s.v1.node_pb2 import PlacementPolicy
from yandex.cloud.k8s.v1.node_pb2 import ResourcesSpec
from yandex.cloud.k8s.v1.node_group_pb2 import ScalePolicy
from yandex.cloud.k8s.v1.node_pb2 import SchedulingPolicy
from yandex.cloud.k8s.v1.node_pb2 import Taint
const TimeOfDay = google.type.timeofday;
from yandex.cloud.k8s.v1.maintenance_pb2 import WeeklyMaintenanceWindow
token = os.getenv('YC_OAUTH_TOKEN')
sdk = yandexcloud.SDK(token=token)
service = sdk.client(NodeGroupServiceStub)
operation = service.Create(
CreateNodeGroupRequest(
cluster_id = "clusterId",
# name = "name",
# description = "description",
# labels = {"key": "labels"},
node_template = NodeTemplate(
# name = "name",
# labels = {"key": "labels"},
# platform_id = "platformId",
# resources_spec = ResourcesSpec(
# memory = 0,
# cores = 0,
# core_fraction = 0,
# gpus = 0
# ),
# boot_disk_spec = DiskSpec(
# disk_type_id = "diskTypeId",
# disk_size = 0
# ),
# metadata = {"key": "metadata"},
# v_4_address_spec = NodeAddressSpec(
# one_to_one_nat_spec = OneToOneNatSpec(
# ip_version = IpVersion.IPV4
# ),
# dns_record_specs = [DnsRecordSpec(
# fqdn = "fqdn",
# dns_zone_id = "dnsZoneId",
# ttl = 0,
# ptr = true
# )]
# ),
# scheduling_policy = SchedulingPolicy(
# preemptible = true
# ),
# network_interface_specs = [NetworkInterfaceSpec(
# subnet_ids = ["subnetIds"],
# primary_v_4_address_spec = NodeAddressSpec(
# one_to_one_nat_spec = OneToOneNatSpec(
# ip_version = IpVersion.IPV4
# ),
# dns_record_specs = [DnsRecordSpec(
# fqdn = "fqdn",
# dns_zone_id = "dnsZoneId",
# ttl = 0,
# ptr = true
# )]
# ),
# primary_v_6_address_spec = NodeAddressSpec(
# one_to_one_nat_spec = OneToOneNatSpec(
# ip_version = IpVersion.IPV4
# ),
# dns_record_specs = [DnsRecordSpec(
# fqdn = "fqdn",
# dns_zone_id = "dnsZoneId",
# ttl = 0,
# ptr = true
# )]
# ),
# security_group_ids = ["securityGroupIds"]
# )],
# placement_policy = PlacementPolicy(
# placement_group_id = "placementGroupId"
# ),
# network_settings = NodeTemplate.NetworkSettings(
# type = NetworkSettings.Type.STANDARD
# ),
# container_runtime_settings = NodeTemplate.ContainerRuntimeSettings(
# type = ContainerRuntimeSettings.Type.DOCKER
# ),
# container_network_settings = NodeTemplate.ContainerNetworkSettings(
# pod_mtu = 0
# ),
# gpu_settings = GpuSettings(
# gpu_cluster_id = "gpuClusterId",
# gpu_environment = GpuSettings.GpuEnvironment.RUNC_DRIVERS_CUDA
# )
),
scale_policy = ScalePolicy(
# fixed_scale = ScalePolicy.FixedScale(
# size = 0
# ),
# auto_scale = ScalePolicy.AutoScale(
# min_size = 0,
# max_size = 0,
# initial_size = 0
# )
),
# allocation_policy = NodeGroupAllocationPolicy(
# locations = [NodeGroupLocation(
# zone_id = "zoneId",
# subnet_id = "subnetId"
# )]
# ),
# deploy_policy = DeployPolicy(
# max_unavailable = 0,
# max_expansion = 0
# ),
# version = "version",
# maintenance_policy = NodeGroupMaintenancePolicy(
# auto_upgrade = true,
# auto_repair = true,
# maintenance_window = MaintenanceWindow(
# anytime = AnytimeMaintenanceWindow(
# ),
# daily_maintenance_window = DailyMaintenanceWindow(
# start_time = TimeOfDay(
# hours = 0,
# minutes = 0,
# seconds = 0,
# nanos = 0
# ),
# duration = Duration(
# seconds = 0,
# nanos = 0
# )
# ),
# weekly_maintenance_window = WeeklyMaintenanceWindow(
# days_of_week = [DaysOfWeekMaintenanceWindow(
# days = [DayOfWeek.MONDAY],
# start_time = TimeOfDay(
# hours = 0,
# minutes = 0,
# seconds = 0,
# nanos = 0
# ),
# duration = Duration(
# seconds = 0,
# nanos = 0
# )
# )]
# )
# )
# ),
# allowed_unsafe_sysctls = ["allowedUnsafeSysctls"],
# node_taints = [Taint(
# key = "key",
# value = "value",
# effect = Taint.Effect.NO_SCHEDULE
# )],
# node_labels = {"key": "nodeLabels"}
)
)
operation_result = sdk.wait_operation_and_get_result(
operation,
response_type=NodeGroup,
meta_type=CreateNodeGroupMetadata,
)
print(operation_result)
CreateNodeGroupRequest
clusterId
: string
ID of the Kubernetes cluster to create a node group in. To get the Kubernetes cluster ID, use a ClusterService.List request.
name
: string
Name of the node group. The name must be unique within the folder.
description
: string
Description of the node group.
labels
: string
Resource labels as key:value
pairs.
nodeTemplate
: NodeTemplate
Node template for creating the node group.
scalePolicy
: ScalePolicy
Scale policy of the node group.
allocationPolicy
: NodeGroupAllocationPolicy
Allocation policy of the node group by the zones and regions.
deployPolicy
: DeployPolicy
Deploy policy according to which the updates are rolled out. If not specified, the default is used.
version
: string
Version of Kubernetes components that runs on the nodes.
maintenancePolicy
: NodeGroupMaintenancePolicy
Maintenance policy of the node group.
allowedUnsafeSysctls
: string
Support for unsafe sysctl parameters. For more details see documentation.
nodeTaints
: Taint
Taints that are applied to the nodes of the node group at creation time.
nodeLabels
: string
Labels that are assigned to the nodes of the node group at creation time.
NodeTemplate
NetworkSettings
Type
TYPE_UNSPECIFIED
STANDARD
SOFTWARE_ACCELERATED
type
: Type
ContainerRuntimeSettings
Type
TYPE_UNSPECIFIED
DOCKER
CONTAINERD
type
: Type
ContainerNetworkSettings
podMtu
: int64
name
: string
Name of the instance. In order to be unique it must contain at least on of instance unique placeholders: {instance.short_id} {instance.index} combination of {instance.zone_id} and {instance.index_in_zone} Example: my-instance-{instance.index} If not set, default is used: {instance_group.id}-{instance.short_id} It may also contain another placeholders, see metadata doc for full list.
labels
: string
these labels will be assigned to compute nodes (instances), created by the nodegroup
platformId
: string
ID of the hardware platform configuration for the node.
resourcesSpec
: ResourcesSpec
Computing resources of the node such as the amount of memory and number of cores.
bootDiskSpec
: DiskSpec
Specification for the boot disk that will be attached to the node.
metadata
: string
The metadata as key:value
pairs assigned to this instance template. Only SSH keys are supported as metadata.
For more information, see Connecting to a node over SSH.
v4AddressSpec
: NodeAddressSpec
Specification for the create network interfaces for the node group compute instances. Deprecated, please use network_interface_specs.
schedulingPolicy
: SchedulingPolicy
Scheduling policy configuration.
networkInterfaceSpecs
: NetworkInterfaceSpec
New api, to specify network interfaces for the node group compute instances. Can not be used together with 'v4_address_spec'
placementPolicy
: PlacementPolicy
networkSettings
: NetworkSettings
this parameter allows to specify type of network acceleration used on nodes (instances)
containerRuntimeSettings
: ContainerRuntimeSettings
containerNetworkSettings
: ContainerNetworkSettings
gpuSettings
: GpuSettings
GPU settings
ScalePolicy
FixedScale
size
: int64
Number of nodes in the node group.
AutoScale
minSize
: int64
Minimum number of nodes in the node group.
maxSize
: int64
Maximum number of nodes in the node group.
initialSize
: int64
Initial number of nodes in the node group.
One of scaleType
fixedScale
: FixedScaleFixed scale policy of the node group.
autoScale
: AutoScaleAuto scale policy of the node group.
NodeGroupAllocationPolicy
locations
: NodeGroupLocation
List of locations where resources for the node group will be allocated.
DeployPolicy
maxUnavailable
: int64
The maximum number of running instances that can be taken offline (i.e., stopped or deleted) at the same time during the update process. If max_expansion is not specified or set to zero, max_unavailable must be set to a non-zero value.
maxExpansion
: int64
The maximum number of instances that can be temporarily allocated above the group's target size during the update process. If max_unavailable is not specified or set to zero, max_expansion must be set to a non-zero value.
NodeGroupMaintenancePolicy
autoUpgrade
: bool
If set to true, automatic updates are installed in the specified period of time with no interaction from the user. If set to false, automatic upgrades are disabled.
autoRepair
: bool
If set to true, automatic repairs are enabled. Default value is false.
maintenanceWindow
: MaintenanceWindow
Maintenance window settings. Update will start at the specified time and last no more than the specified duration. The time is set in UTC.
Taint
Effect
EFFECT_UNSPECIFIED
NO_SCHEDULE
Do not allow new pods to schedule onto the node unless they tolerate the taint, but allow all pods submitted to Kubelet without going through the scheduler to start, and allow all already-running pods to continue running.
PREFER_NO_SCHEDULE
Like NO_SCHEDULE, but the scheduler tries not to schedule new pods onto the node, rather than prohibiting new pods from scheduling onto the node entirely. Enforced by the scheduler.
NO_EXECUTE
Evict any already-running pods that do not tolerate the taint.
key
: string
The taint key to be applied to a node.
value
: string
The taint value corresponding to the taint key.
effect
: Effect
The effect of the taint on pods that do not tolerate the taint.
ResourcesSpec
memory
: int64
Amount of memory available to the node, specified in bytes.
cores
: int64
Number of cores available to the node.
coreFraction
: int64
Baseline level of CPU performance with the possibility to burst performance above that baseline level. This field sets baseline performance for each core.
gpus
: int64
Number of GPUs available to the node.
DiskSpec
diskTypeId
: string
ID of the disk type.
diskSize
: int64
Size of the disk, specified in bytes.
NodeAddressSpec
oneToOneNatSpec
: OneToOneNatSpec
One-to-one NAT configuration. Setting up one-to-one NAT ensures that public IP addresses are assigned to nodes, and therefore internet is accessible for all nodes of the node group. If the field is not set, NAT will not be set up.
dnsRecordSpecs
: DnsRecordSpec
Internal DNS configuration.
SchedulingPolicy
preemptible
: bool
True for preemptible compute instances. Default value is false. Preemptible compute instances are stopped at least once every 24 hours, and can be stopped at any time if their resources are needed by Compute. For more information, see Preemptible Virtual Machines.
NetworkInterfaceSpec
subnetIds
: string
IDs of the subnets.
primaryV4AddressSpec
: NodeAddressSpec
Primary IPv4 address that is assigned to the instance for this network interface.
primaryV6AddressSpec
: NodeAddressSpec
Primary IPv6 address that is assigned to the instance for this network interface.
securityGroupIds
: string
IDs of security groups.
PlacementPolicy
placementGroupId
: string
Identifier of placement group
NetworkSettings
Type
TYPE_UNSPECIFIED
STANDARD
SOFTWARE_ACCELERATED
type
: Type
ContainerRuntimeSettings
Type
TYPE_UNSPECIFIED
DOCKER
CONTAINERD
type
: Type
ContainerNetworkSettings
podMtu
: int64
GpuSettings
GpuEnvironment
GPU_ENVIRONMENT_UNSPECIFIED
Use one of the values below, depending on the default for the specific Cloud installation.
RUNC_DRIVERS_CUDA
Use a node image with the pre-installed GPU toolkit, drivers and CUDA.
RUNC
Use a node image with the pre-installed GPU toolkit but without drivers. You should install drivers on a node yourself in that case. There are tools to help you to do that, for example gpu-operator.
gpuClusterId
: string
GPU cluster id, that mk8s node will join.
gpuEnvironment
: GpuEnvironment
GPU environment configured on node.
FixedScale
size
: int64
Number of nodes in the node group.
AutoScale
minSize
: int64
Minimum number of nodes in the node group.
maxSize
: int64
Maximum number of nodes in the node group.
initialSize
: int64
Initial number of nodes in the node group.
NodeGroupLocation
zoneId
: string
ID of the availability zone where the nodes may reside.
subnetId
: string
ID of the subnet. If a network chosen for the Kubernetes cluster has only one subnet in the specified zone, subnet ID may be omitted.
MaintenanceWindow
One of policy
Maintenance policy.
anytime
: AnytimeMaintenanceWindowUpdating the master at any time.
dailyMaintenanceWindow
: DailyMaintenanceWindowUpdating the master on any day during the specified time window.
weeklyMaintenanceWindow
: WeeklyMaintenanceWindowUpdating the master on selected days during the specified time window.
OneToOneNatSpec
ipVersion
: IpVersion
IP version for the public IP address.
DnsRecordSpec
fqdn
: string
FQDN (required).
dnsZoneId
: string
DNS zone id (optional, if not set, private zone is used).
ttl
: int64
DNS record ttl, values in 0-86400 (optional).
ptr
: bool
When set to true, also create PTR DNS record (optional).
AnytimeMaintenanceWindow
DailyMaintenanceWindow
startTime
: google.type.TimeOfDay
Window start time, in the UTC timezone.
duration
: google.protobuf.Duration
Window duration.
WeeklyMaintenanceWindow
daysOfWeek
: DaysOfWeekMaintenanceWindow
Days of the week and the maintenance window for these days when automatic updates are allowed.
DaysOfWeekMaintenanceWindow
days
: google.type.DayOfWeek
Days of the week when automatic updates are allowed.
startTime
: google.type.TimeOfDay
Window start time, in the UTC timezone.
duration
: google.protobuf.Duration
Window duration.
Operation
An Operation resource. For more information, see Operation.
id
: string
ID of the operation.
description
: string
Description of the operation. 0-256 characters long.
createdAt
: google.protobuf.Timestamp
Creation timestamp.
createdBy
: string
ID of the user or service account who initiated the operation.
modifiedAt
: google.protobuf.Timestamp
The time when the Operation resource was last modified.
done
: bool
If the value is false
, it means the operation is still in progress.
If true
, the operation is completed, and either error
or response
is available.
metadata
: google.protobuf.Any
Service-specific metadata associated with the operation. It typically contains the ID of the target resource that the operation is performed on. Any method that returns a long-running operation should document the metadata type, if any.
One of result
The operation result.
If done == false
and there was no failure detected, neither error
nor response
is set.
If done == false
and there was a failure detected, error
is set.
If done == true
, exactly one of error
or response
is set.
error
: google.rpc.StatusThe error result of the operation in case of failure or cancellation.
response
: google.protobuf.AnyThe normal response of the operation in case of success.
If the original method returns no data on success, such as Delete, the response is google.protobuf.Empty. If the original method is the standard Create/Update, the response should be the target resource of the operation. Any method that returns a long-running operation should document the response type, if any.