Managing Kubernetes node labels
You can add Kubernetes-labels to all Managed Service for Kubernetes nodes in a node group at the same time. To do this, specify a set of labels using the node_labels
parameter when creating a Managed Service for Kubernetes node group.
-
Create a Managed Service for Kubernetes cluster.
You can use an existing Managed Service for Kubernetes cluster or create a new one.
-
Create a node group with Kubernetes labels:
Management consoleCLITerraformAPI- In the management console
, select the folder where you created the Managed Service for Kubernetes cluster. - In the list of services, select Managed Service for Kubernetes.
- Select the Managed Service for Kubernetes cluster to create a node group for.
- On the Managed Service for Kubernetes cluster page, go to the Nodes manager tab.
- Click Create a node group.
- Enter a name for the Managed Service for Kubernetes node group.
- In the Kubernetes version field, select a Kubernetes version for Managed Service for Kubernetes nodes.
- Under Scaling:
- Select the scaling policy type.
- Specify the number of nodes in the Managed Service for Kubernetes node group.
- Under Allow when creating and updating, specify the maximum number of instances by which you can exceed or reduce the size of the Managed Service for Kubernetes group.
- Under Computing resources:
- Choose a platform.
- Specify the required number of vCPUs, guaranteed vCPU performance, and the amount of RAM.
- Under Storage:
- Specify the Managed Service for Kubernetes node Disk type:
HDD
: Standard network drive; network block storage on an HDD.SSD
: Fast network drive; network block storage on an SSD.Non-replicated SSD
: Network drive with enhanced performance achieved by removing redundancy. You can only change the size of this type of disk in 93 GB increments.SSD IO
: Network drive with the same performance characteristics asNon-replicated SSD
, plus redundancy. You can only change the size of this type of disk in 93 GB increments.
- Specify the Managed Service for Kubernetes node disk size.
- Specify the Managed Service for Kubernetes node Disk type:
- Under Network settings:
- In the Public address field, choose a method for assigning an IP address:
Auto
: Assign a random IP address from the Yandex Cloud IP pool.No address
: Do not assign a public IP address.
- Specify how Managed Service for Kubernetes nodes should be distributed across the availability zones and networks.
- In the Public address field, choose a method for assigning an IP address:
- Under Access, specify the information required to access the Managed Service for Kubernetes node:
- Enter the username in the Login field.
- In the SSH key field, paste the contents of the public key file.
- Under Maintenance window settings:
- In the Maintenance frequency / Disable field, select your preferred maintenance window:
Disabled
: Automatic updates disabled.Anytime
: Updates allowed at any time.Daily
: Updates will take place within the time interval specified in the Time (UTC) and duration field.On selected days
: Updates will take place within the time interval specified in the Weekly schedule field.
- In the Maintenance frequency / Disable field, select your preferred maintenance window:
- Under Additional:
- In the Node labels field, click Add label and specify the label key and value. Add multiple labels if needed.
- Click Create.
Create a Managed Service for Kubernetes node group:
yc managed-kubernetes node-group create \ --name k8s-labels-node \ --cluster-name k8s-labels \ --disk-type network-ssd \ --fixed-size 1 \ --node-labels environment=production,apps/tier=backend
Where:
--name
: Name of the Managed Service for Kubernetes node group.--cluster-name
: Name of the Managed Service for Kubernetes cluster where the node group is created.--disk-type
: Disk type on the Managed Service for Kubernetes node.--fixed-size
: Number of Managed Service for Kubernetes nodes in the group.--node-labels
: Managed Service for Kubernetes node labels. You can specify multiple labels separated by commas.
Result:
done (2m19s) id: catkuapro07e******** cluster_id: abcsk1s2f3fm******** created_at: "2020-09-24T13:32:24Z" name: k8s-labels-node status: RUNNING node_template: platform_id: standard-v2 resources_spec: memory: "4294967296" cores: "2" core_fraction: "100" boot_disk_spec: disk_type_id: network-ssd disk_size: "103079215104" v4_address_spec: {} scheduling_policy: {} scale_policy: fixed_scale: size: "1" allocation_policy: locations: - zone_id: ru-central1-a subnet_id: e9bm87gkjd81******** deploy_policy: max_expansion: "3" instance_group_id: cl1v2gh33j1c******** node_version: "1.17" version_info: current_version: "1.17" maintenance_policy: auto_upgrade: true auto_repair: true maintenance_window: anytime: {} node_labels: apps/tier: backend environment: production
Warning
A Managed Service for Kubernetes node group will be recreated from scratch.
-
Open the current configuration file describing the Managed Service for Kubernetes node group.
For more information about creating this file, see Creating a node group.
-
Add the
node_labels
property to the Managed Service for Kubernetes node group description:resource "yandex_kubernetes_node_group" "<node_group_name>" { cluster_id = yandex_kubernetes_cluster.<cluster_name>.id ... node_labels = { "<label_1>" = "<value_1>" "<label_2>" = "<value_2>" ... } }
-
Make sure the configuration files are valid.
-
Using the command line, navigate to the folder that contains the up-to-date Terraform configuration files with an infrastructure plan.
-
Run the command:
terraform validate
If there are errors in the configuration files, Terraform will point to them.
-
-
Confirm updating the resources.
-
Run the command to view planned changes:
terraform plan
If the resource configuration descriptions are correct, the terminal will display a list of the resources to modify and their parameters. This is a test step. No resources are updated.
-
If you are happy with the planned changes, apply them:
-
Run the command:
terraform apply
-
Confirm the update of resources.
-
Wait for the operation to complete.
-
For more information, see the Terraform provider documentation
. -
- In the management console
-
Get information about the created node group with Kubernetes labels:
Management consoleCLIAPI- In the management console
, select the folder where the Managed Service for Kubernetes cluster was created. - In the list of services, select Managed Service for Kubernetes.
- Select the Managed Service for Kubernetes cluster where the node group was created.
- On the Managed Service for Kubernetes cluster page, go to the Nodes manager tab.
- Open the page of one of the Managed Service for Kubernetes nodes and go to the Labels tab. The tab lists the system and user Kubernetes node labels.
-
Install kubectl
and configure it to work with the created cluster. -
View all the nodes in a Managed Service for Kubernetes cluster:
kubectl get nodes
Result:
NAME STATUS ROLES AGE VERSION catkuapro07e********-hgjd Ready <none> 1h v1.17.8 catkuapro07e********-lskc Ready <none> 1h v1.17.8
-
Get information on a selected Managed Service for Kubernetes cluster node:
kubectl describe node catkuapro07e********-hgjd
Result:
Name: catkuapro07e********-hgjd Roles: <none> Labels: apps/tier=backend beta.kubernetes.io/arch=amd64 beta.kubernetes.io/instance-type=standard-v2 beta.kubernetes.io/os=linux environment=production failure-domain.beta.kubernetes.io/zone=ru-central1-a kubernetes.io/arch=amd64 kubernetes.io/hostname=catkuapro07e********-hgjd kubernetes.io/os=linux node.kubernetes.io/kube-proxy-ds-ready=true node.kubernetes.io/masq-agent-ds-ready=true node.kubernetes.io/node-problem-detector-ds-ready=true yandex.cloud/node-group-id=catkuapro07e******** yandex.cloud/pci-topology=k8s yandex.cloud/preemptible=false
- In the management console