Yandex Cloud
  • Services
  • Solutions
  • Why Yandex Cloud
  • Pricing
  • Documentation
  • Contact us
Get started
Language / Region
© 2022 Yandex.Cloud LLC
Yandex Managed Service for Kubernetes
  • Comparison with other Yandex Cloud services
  • Getting started
  • Step-by-step instructions
    • All instructions
    • Configuring security groups
    • Connecting to a node over SSH
    • Creating a configuration file
    • Updating Kubernetes
    • Installing applications
      • Basics of working with Cloud Marketplace
      • Installing Metrics Provider
    • Network scenarios
      • Granting access to an app running in a Kubernetes cluster
      • Configuring the Calico network policy controller
      • Configuring the Cilium network policy controller
      • Configuring Node Local DNS for the Cilium network policy controller
    • Encrypting secrets
    • Automatic scaling
    • Working with persistent volumes
      • Dynamic volume provisioning
      • Static volume provisioning
      • Managing storage classes
      • Expanding a pod volume
      • Expanding a StatefulSet controller volume
      • Mounting a volume in Block mode
      • Integration with Object Storage
    • Managing a Kubernetes cluster
      • Adding Kubernetes cluster credentials to the kubectl configuration file
      • Getting information about a Kubernetes cluster
      • Creating a Kubernetes cluster
      • Editing a Kubernetes cluster
      • Creating a namespace in a Kubernetes cluster
      • Deleting a Kubernetes cluster
    • Managing a node group
      • Getting information about a node group
      • Creating a node group
      • Changing a node group
      • Managing cluster node labels
      • Deleting a node group
    • Connecting external nodes to the cluster
  • Practical guidelines
    • All tutorials
    • Integration with Container Registry
    • Running workloads with GPUs
    • Installing the NGINX Ingress controller with Let's Encrypt®
    • Configuring the Application Load Balancer Ingress controller
    • Backup to Object Storage
    • Horizontal application scaling in a cluster
    • Working with snapshots
    • Integration with a corporate DNS zone
    • Automatic DNS scaling by cluster size
    • Setting up local DNS caching
    • Configuring Fluent Bit for Yandex Cloud Logging
    • Syncing with Yandex Lockbox secrets
  • Concepts
    • Relationship between service resources
    • Release channels and updates
    • Encrypting secrets
    • Using Kubernetes API objects
      • Volumes
      • Service
    • Node groups
      • Cluster autoscaler
      • Evicting pods from nodes
      • Dynamic resource allocation for a node
      • Node groups with GPUs
    • Network in Managed Service for Kubernetes
    • External cluster nodes
    • Network settings and cluster policies
    • Automatic scaling
    • Quotas and limits
    • Recommendations for using Managed Service for Kubernetes
  • Access management
  • Pricing policy
  • API reference
    • Authentication in the API
    • gRPC
      • Overview
      • ClusterService
      • NodeGroupService
      • VersionService
      • OperationService
    • REST
      • Overview
      • Cluster
        • Overview
        • create
        • delete
        • get
        • list
        • listNodeGroups
        • listNodes
        • listOperations
        • start
        • stop
        • update
      • NodeGroup
        • Overview
        • create
        • delete
        • get
        • list
        • listNodes
        • listOperations
        • update
      • Version
        • Overview
        • list
  • Questions and answers
    • General questions
    • Data storage
    • Configuring and updating
    • Automatic scaling
    • Resources
    • Logs
    • All questions on one page
  1. Step-by-step instructions
  2. Configuring security groups

Configuring security groups

Written by
Yandex Cloud
  • Create rules for service traffic
  • Create a rule for connecting to services from the internet
  • Create a rule for connecting to nodes via SSH
  • Create rules to access the Kubernetes API
  • Examples

Security groups follow the principle all traffic that is not allowed is prohibited. In order for a cluster to work, you need to create rules in its security groups that allow:

  • Service traffic within the cluster.
  • Connections to services from the internet.
  • Connections to nodes over SSH.
  • Access to the Kubernetes API.

You can set more detailed rules for security groups, such as allowing traffic in only specific subnets.

Security groups must be correctly configured for all subnets that will host the cluster. This determines the performance and availability of the cluster and the services running there.

Create rules for service traffic

Warning

Setting up rules for service traffic enables the performance of a regional cluster.

  1. Add rules for incoming traffic.

    • For a network load balancer:

      • Port range: 0-65535.
      • Protocol: TCP.
      • Source type: CIDR.
      • Destination: 198.18.235.0/24 and 198.18.248.0/24.
    • To transfer service traffic between the master and nodes:

      • Port range: 0-65535.
        • Protocol: Any.
        • Source type: Security group.
        • Security group: Current (Self).
    • To transfer traffic between pods and services:

      • Port range: 0-65535.
      • Protocol: Any.
      • Source type: CIDR.
      • Destination: Specify the IP address ranges of the subnets created along with the cluster, such as:
        • 10.96.0.0/16.
        • 10.112.0.0/16.
    • To test the nodes using ICMP requests from the subnets within Yandex Cloud:

      • Protocol: ICMP.
      • Source type: CIDR.
      • Destination: IP address ranges of the subnets within Yandex Cloud to perform cluster diagnostics from, such as:
        • 10.0.0.0/8.
        • 192.168.0.0/16.
        • 172.16.0.0/12.
  2. Add a rule for outgoing traffic that allows cluster hosts to connect to external resources, for example, to download images from Docker Hub or work with Yandex Object Storage:

    • Port range: 0-65535.
    • Protocol: Any.
    • Source type: CIDR.
    • Destination: 0.0.0.0/0.

Create a rule for connecting to services from the internet

The services running on the nodes are accessible from the internet and subnets within Yandex Cloud after you create a rule for incoming traffic:

  • Port range: 30000-32767.
  • Protocol: TCP.
  • Source type: CIDR.
  • Destination: 0.0.0.0/0.

Create a rule for connecting to nodes via SSH

To connect to nodes over SSH, create a rule for incoming traffic:

  • Port: 22.
  • Protocol: TCP.
  • Source type: CIDR.
  • Destination: IP address ranges of the subnets within Yandex Cloud and public IP addresses of computers on the internet, for example:
    • 10.0.0.0/8.
    • 192.168.0.0/16.
    • 172.16.0.0/12.
    • 85.32.32.22/32.

Create rules to access the Kubernetes API

To access the Kubernetes API and manage clusters using kubectl and other utilities, you need rules that allow connections to the master via ports 6443 and 443. Create two rules for incoming traffic, one per port:

  • Ports: 443 and 6443.
  • Protocol: TCP.
  • Source type: CIDR.
  • Destination: Specify the IP address range of the subnets that you'll manage the cluster from, such as:
    • 85.23.23.22/32: For the external network.
    • 192.168.0.0/24: For the internal network.

Examples

Terraform

For example, you need to create rules for an existing Kubernetes cluster:

  • With the zonal master located in the ru-central1-c availability zone.

  • With the worker-nodes-c node group.

  • With access to services:

    • From the load balancer's address range 198.18.235.0/24 and 198.18.248.0/24.
    • From the internal subnet 10.129.0.0/24 to transfer traffic between pods and services.
    • From the internal subnet 172.16.0.0/12 for the ICMP protocol.
    • From the internet from any addresses (0.0.0.0/0) to a range of NodePort ports (30000-32767).
  • With access to nodes from the internet from the address 85.32.32.22/32 to port 22.

  • With access to the Kubernetes API from an external subnet from the address range 203.0.113.0/24 via ports 443 and 6443.

    Four security groups are created:

    • k8s-main-sg: Rules for service traffic.
    • k8s-public-services: Rules for connecting to nodes from the internet.
    • k8s-nodes-ssh-access: Rules for connecting to nodes over SSH.
    • k8s-master-whitelist: Rules for accessing the cluster API.
    The configuration file for the cluster:
    terraform {
      required_providers {
        yandex = {
          source = "yandex-cloud/yandex"
        }
      }
    }
    
    provider "yandex" {
      token = "<OAuth or static key of service account>"
      cloud_id  = "<cloud ID>"
      folder_id = "<folder ID>"
      zone      = "<availability zone>"
    }
    
    resource "yandex_vpc_security_group" "k8s-main-sg" {
      name        = "k8s-main-sg"
      description = "Group rules ensure the basic performance of the cluster. Apply it to the cluster and node groups."
      network_id  = "<cloud network ID>"
      ingress {
        protocol       = "TCP"
        description    = "The rule allows availability checks from the load balancer's range of addresses. It is required for the operation of a fault-tolerant cluster and load balancer services."
        v4_cidr_blocks = ["198.18.235.0/24", "198.18.248.0/24"]
        from_port      = 0
        to_port        = 65535
      }
      ingress {
        protocol          = "ANY"
        description       = "The rule allows the master-node and node-node interaction within the security group."
        predefined_target = "self_security_group"
        from_port         = 0
        to_port           = 65535
      }
      ingress {
        protocol       = "ANY"
        description = "The rule allows the pod-pod and service-service interaction. Specify the subnets of your cluster and services."
        v4_cidr_blocks = ["10.129.0.0/24"]
        from_port      = 0
        to_port        = 65535
      }
      ingress {
        protocol       = "ICMP"
        description = "The rule allows receipt of debugging ICMP packets from internal subnets."
        v4_cidr_blocks = ["172.16.0.0/12"]
      }
      egress {
        protocol       = "ANY"
        description = "The rule allows all outgoing traffic. Nodes can connect to Yandex Container Registry, Object Storage, Docker Hub, and more."
        v4_cidr_blocks = ["0.0.0.0/0"]
        from_port      = 0
        to_port        = 65535
      }
    }
    
    resource "yandex_vpc_security_group" "k8s-public-services" {
      name        = "k8s-public-services"
      description = "Group rules allow connections to services from the internet. Only apply the rules to node groups."
      network_id  = "<cloud network ID>"
    
      ingress {
        protocol       = "TCP"
        description = "The rule allows incoming traffic from the internet to a range of NodePort ports. Add or change the ports to the ones you need."
        v4_cidr_blocks = ["0.0.0.0/0"]
        from_port      = 30000
        to_port        = 32767
      }
    }
    
    resource "yandex_vpc_security_group" "k8s-nodes-ssh-access" {
      name        = "k8s-nodes-ssh-access"
      description = "Group rules allow connections to cluster nodes over SSH. Only apply the rules to node groups."
      network_id  = "<cloud network ID>"
    
      ingress {
        protocol       = "TCP"
        description = "The rule allows SSH connections to nodes from the specified IP addresses."
        v4_cidr_blocks = ["85.32.32.22/32"]
        port           = 22
      }
    }
    
    resource "yandex_vpc_security_group" "k8s-master-whitelist" {
      name        = "k8s-master-whitelist"
      description = "Group rules allow accessing the Kubernetes API  from the internet. Apply the rules to the cluster only."
      network_id  = "<cloud network ID>"
    
      ingress {
        protocol       = "TCP"
        description = "The rule allows connections to the Kubernetes API through port 6443 from the specified network."
        v4_cidr_blocks = ["203.0.113.0/24"]
        port           = 6443
      }
    
      ingress {
        protocol       = "TCP"
        description = "The rule allows connections to the Kubernetes API through port 443 from the specified network."
        v4_cidr_blocks = ["203.0.113.0/24"]
        port           = 443
      }
    }
    
    resource "yandex_kubernetes_cluster" "k8s-cluster" {
      name = "k8s-cluster"
      ...
      master {
        version = "1.20"
        zonal {
          zone      = "ru-central1-c"
          subnet_id = <cloud subnet ID>
        }
    
        security_group_ids = [
          yandex_vpc_security_group.k8s-main-sg.id,
          yandex_vpc_security_group.k8s-master-whitelist.id
        ]
        ...
      }
      ...
    }
    
    resource "yandex_kubernetes_node_group" "worker-nodes-c" {
      cluster_id = yandex_kubernetes_cluster.k8s-cluster.id
      name       = "worker-nodes-c"
      version    = "1.20"
      ...
      instance_template {
        platform_id = "standard-v3"
        network_interface {
          nat                = true
          subnet_ids         = [<cloud subnet ID>]
          security_group_ids = [
            yandex_vpc_security_group.k8s-main-sg.id,
            yandex_vpc_security_group.k8s-nodes-ssh-access.id,
            yandex_vpc_security_group.k8s-public-services.id
          ]
          ...
        }
        ...
      }
    }
    

Was the article helpful?

Language / Region
© 2022 Yandex.Cloud LLC
In this article:
  • Create rules for service traffic
  • Create a rule for connecting to services from the internet
  • Create a rule for connecting to nodes via SSH
  • Create rules to access the Kubernetes API
  • Examples