### Terraform Kubernetes Node Groups Example Source: https://github.com/terraform-yc-modules/terraform-yc-kubernetes/blob/master/README.md This Terraform configuration defines multiple Kubernetes node groups for a Yandex Cloud cluster. It demonstrates fixed-scale, auto-scaled, and GPU-enabled node groups with various settings like labels, node labels, locations, and GPU configurations. This example showcases how to leverage the `yandex` provider for Kubernetes resources. ```hcl node_groups = { "yc-k8s-ng-01" = { cluster_name = "k8s-kube-cluster" description = "Kubernetes nodes group with fixed scale policy and one maintenance window" fixed_scale = { size = 3 } labels = { owner = "yandex" service = "kubernetes" } node_labels = { role = "worker-01" environment = "dev" } }, "yc-k8s-ng-02" = { description = "Kubernetes nodes group with auto scale policy" auto_scale = { min = 2 max = 4 initial = 2 } node_locations = [ { zone = "ru-central1-b" subnet_id = "e2lu07tr481h35012c8p" } ] labels = { owner = "example" service = "kubernetes" } node_labels = { role = "worker-02" environment = "testing" } instance_labels = { managed_by = "terraform" environment = "stage" } }, "yc-k8s-ng-03" = { description = "Kubernetes nodes group with GPU" fixed_scale = { size = 1 } platform_id = "gpu-standard-v2" node_gpus = 2 node_gpu_settings = { gpu_environment = "runc_drivers_cuda" } node_locations = [ { zone = "ru-central1-b" subnet_id = "e2lu07tr481h35012c8p" } ] labels = { owner = "example" service = "kubernetes" } node_labels = { role = "worker-03" environment = "gpu" } node_taints = [ "nvidia.com/gpu=:NoSchedule" ] } } ``` -------------------------------- ### Run Pre-commit Hooks in Terraform Kubernetes Module Source: https://github.com/terraform-yc-modules/terraform-yc-kubernetes/blob/master/CONTRIBUTING.md This command executes all pre-commit hooks for the project, ensuring code quality and consistency before committing changes. It is a mandatory step in the contribution process. ```bash pre-commit run -a ``` -------------------------------- ### Terraform: Custom Metadata Example Source: https://github.com/terraform-yc-modules/terraform-yc-kubernetes/blob/master/README.md Adds custom metadata to Yandex Kubernetes node groups. This allows for attaching arbitrary key-value pairs to nodes for identification or configuration purposes. ```Terraform custom_metadata = { foo = "bar" } ``` -------------------------------- ### Configure Master Maintenance Windows for Kubernetes Source: https://github.com/terraform-yc-modules/terraform-yc-kubernetes/blob/master/README.md Defines maintenance windows during which automatic updates for the Kubernetes master are permitted. The example shows a configuration for a Monday maintenance window starting at 23:00 with a duration of 3 hours. This is useful for scheduling updates during off-peak hours. ```terraform master_maintenance_windows = [ { day = "monday" start_time = "23:00" duration = "3h" } ] ``` -------------------------------- ### Terraform Yandex Kubernetes Cluster Module Example Source: https://github.com/terraform-yc-modules/terraform-yc-kubernetes/blob/master/README.md This HCL-Terraform snippet demonstrates how to use the Yandex.Cloud Kubernetes module to define a cluster with master locations, maintenance windows, and multiple node groups. It showcases configuration options for fixed and auto-scaling node groups, including descriptions, locations, labels, and scaling parameters. ```hcl-terraform module "kube" { source = "./modules/kubernetes" network_id = "enpmff6ah2bvi0k10j66" master_locations = [ { zone = "ru-central1-a" subnet_id = "e9b3k97pr2nh1i80as04" }, { zone = "ru-central1-b" subnet_id = "e2laaglsc7u99ur8c4j1" }, { zone = "ru-central1-c" subnet_id = "b0ckjm3olbpmk2t6c28o" } ] master_maintenance_windows = [ { day = "monday" start_time = "23:00" duration = "3h" } ] node_groups = { "yc-k8s-ng-01" = { description = "Kubernetes nodes group 01" fixed_scale = { size = 3 } node_labels = { role = "worker-01" environment = "testing" } }, "yc-k8s-ng-02" = { description = "Kubernetes nodes group 02" auto_scale = { min = 2 max = 4 initial = 2 } node_locations = [ { zone = "ru-central1-b" subnet_id = "e2lu07tr481h35012c8p" } ] node_labels = { role = "worker-02" environment = "dev" } max_expansion = 1 max_unavailable = 1 } } } ``` -------------------------------- ### Terraform: Default NodePort Rules Example Source: https://github.com/terraform-yc-modules/terraform-yc-kubernetes/blob/master/README.md Enables the creation of default security rules for the NodePort port range. This rule typically allows incoming TCP traffic from any IPv4 CIDR block to the NodePort range (30000-32767), facilitating external access to services exposed via NodePort. ```Terraform enable_node_ports_rules = true # Example configuration if explicitly defined: # nodeport_rules = [ # { # protocol = "TCP" # description = "Rule allows incoming traffic from the Internet to the NodePort port range." # v4_cidr_blocks = ["0.0.0.0/0"] # from_port = 30000 # to_port = 32767 # } # ] ``` -------------------------------- ### Terraform Node Group Definition Example Source: https://github.com/terraform-yc-modules/terraform-yc-kubernetes/blob/master/README.md This HCL-Terraform snippet defines the structure for a node group within a Yandex.Cloud Kubernetes cluster. It illustrates how to configure parameters like description, scaling policies (fixed or auto-scaling), and node locations. This is a reusable configuration block for defining worker nodes. ```hcl-terraform node_groups = { "yc-k8s-ng-01" = { description = "Kubernetes nodes group 01" fixed_scale = { size = 2 } }, "yc-k8s-ng-02" = { description = "Kubernetes nodes group 02" auto_scale = { min = 3 max = 5 initial = 3 } } } ``` -------------------------------- ### Get Kubernetes Cluster Credentials (External) Source: https://github.com/terraform-yc-modules/terraform-yc-kubernetes/blob/master/README.md This command retrieves credentials for accessing the Yandex Managed Kubernetes cluster externally. It downloads the kube config and configures kubectl to interact with the cluster. This is useful for remote management and testing. ```bash $ yc managed-kubernetes cluster get-credentials --id --external kubectl get cluster-info ``` -------------------------------- ### Terraform: Custom Ingress Security Rules Example Source: https://github.com/terraform-yc-modules/terraform-yc-kubernetes/blob/master/README.md Defines custom ingress security rules for a Yandex Kubernetes cluster. Supports various configurations including protocol, description, CIDR blocks, specific ports, port ranges, and allowing traffic from the security group itself. Enables granular control over incoming traffic. ```Terraform custom_ingress_rules = { "rule1" = { protocol = "TCP" description = "rule-1" v4_cidr_blocks = ["0.0.0.0/0"] from_port = 3000 to_port = 32767 }, "rule2" = { protocol = "TCP" description = "rule-2" v4_cidr_blocks = ["0.0.0.0/0"] port = 443 }, "rule3" = { protocol = "TCP" description = "rule-3" predefined_target = "self_security_group" from_port = 0 to_port = 65535 } } ``` -------------------------------- ### Terraform: Custom Egress Security Rules Example Source: https://github.com/terraform-yc-modules/terraform-yc-kubernetes/blob/master/README.md Defines custom egress security rules for a Yandex Kubernetes cluster. Allows specifying protocol, description, IPv4 CIDR blocks, and port ranges for outgoing traffic. Supports different rule configurations for broad or specific access. ```Terraform custom_egress_rules = { "rule1" = { protocol = "ANY" description = "rule-1" v4_cidr_blocks = ["10.0.1.0/24", "10.0.2.0/24"] from_port = 8090 to_port = 8099 }, "rule2" = { protocol = "UDP" description = "rule-2" v4_cidr_blocks = ["10.0.1.0/24"] from_port = 8090 to_port = 8099 } } ``` -------------------------------- ### Get Kubernetes Cluster Credentials (Internal) Source: https://github.com/terraform-yc-modules/terraform-yc-kubernetes/blob/master/README.md This command retrieves credentials for accessing the Yandex Managed Kubernetes cluster internally. It downloads the kube config and configures kubectl for use within the same VPC as the cluster nodes. This is suitable for accessing the cluster from within your Yandex Cloud network. ```bash $ yc managed-kubernetes cluster get-credentials --id --internal ``` -------------------------------- ### Configure Master Auto Scale Policy for Kubernetes Source: https://github.com/terraform-yc-modules/terraform-yc-kubernetes/blob/master/README.md Sets the auto-scaling policy for the Kubernetes master nodes. This example configures the auto-scale to use a minimum resource preset ID of 's-c2-m8'. This allows the master's resources to be adjusted based on demand within defined limits. ```terraform master_scale_policy = { auto_scale = { min_resource_preset_id = "s-c2-m8" } } ``` -------------------------------- ### Terraform Yandex Cloud Authentication Environment Variables Source: https://github.com/terraform-yc-modules/terraform-yc-kubernetes/blob/master/README.md This shell script snippet shows how to set environment variables for authenticating Terraform with Yandex Cloud using the YC CLI. It retrieves a IAM token, Cloud ID, and Folder ID, which are essential for Terraform to interact with Yandex.Cloud resources. ```bash export YC_TOKEN=$(yc iam create-token) export YC_CLOUD_ID=$(yc config get cloud-id) export YC_FOLDER_ID=$(yc config get folder-id) ``` -------------------------------- ### Enable All Outgoing Traffic for Kubernetes Nodes Source: https://github.com/terraform-yc-modules/terraform-yc-kubernetes/blob/master/README.md This configuration enables all outgoing traffic for Kubernetes nodes, allowing them to connect to services like Yandex Container Registry, Yandex Object Storage, and Docker Hub. It defines a rule that permits any protocol and covers all IPv4 addresses on all ports. ```terraform "rule-1" = { protocol = "ANY" description = "Rule allows all outgoing traffic. Nodes can connect to Yandex Container Registry, Yandex Object Storage, Docker Hub, and so on." v4_cidr_blocks = ["0.0.0.0/0"] from_port = 0 to_port = 65535 } ``` -------------------------------- ### Configure SSH Access for Kubernetes Nodes Source: https://github.com/terraform-yc-modules/terraform-yc-kubernetes/blob/master/README.md This configuration enables SSH access to Kubernetes worker nodes by defining an ingress rule. It specifies the protocol (TCP), a description, the allowed IPv4 CIDR blocks for access, and the SSH port (22). Ensure `var.allowed_ips_ssh` is correctly set with the desired IP addresses. ```terraform ingress { protocol = "TCP" description = "Allow access to worker nodes via SSH from IP's." v4_cidr_blocks = var.allowed_ips_ssh port = 22 } ``` -------------------------------- ### Terraform Kubernetes Node Group Defaults Configuration Source: https://github.com/terraform-yc-modules/terraform-yc-kubernetes/blob/master/README.md This Terraform configuration snippet defines default values for Kubernetes node groups. These defaults, such as platform ID, core count, memory, disk type and size, and maintenance settings, are applied to node groups unless explicitly overridden in the `node_groups` configuration. This helps in maintaining consistency and reducing boilerplate code. ```hcl node_groups_defaults = { "core_fraction": 100, "disk_size": 64, "disk_type": "network-ssd", "ipv4": true, "ipv6": false, "nat": false, "node_cores": 4, "node_gpus": 0, "node_memory": 8, "platform_id": "standard-v3", "preemptible": false, "template_name": "{instance_group.id}-{instance.short_id}" } ``` -------------------------------- ### Configure OS Login or SSH Keys for Nodes Source: https://github.com/terraform-yc-modules/terraform-yc-kubernetes/blob/master/README.md This input variable controls the method for managing SSH access to nodes, allowing either OS Login or the addition of SSH keys to node group metadata. The default setting disables OS Login. ```terraform { "enable-oslogin": "false", "ssh-keys": null } ``` -------------------------------- ### Configure Master Logging Options for Kubernetes Source: https://github.com/terraform-yc-modules/terraform-yc-kubernetes/blob/master/README.md Specifies the logging options for the Kubernetes master. This optional configuration allows enabling or disabling logs for the Kubernetes API server, autoscaler, events, and audit logs. It can also be configured to use a specific folder ID or log group ID for centralized logging. ```terraform master_logging = { enabled = true folder_id = null enabled_kube_apiserver = true enabled_autoscaler = true enabled_events = true enabled_audit = true log_group_id = null } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.