Monday, October 23, 2023
HomeSoftware EngineeringTips on how to make a EKS cluster Non-public and permit Nodes...

Tips on how to make a EKS cluster Non-public and permit Nodes to nonetheless be a part of by way of a NodeGroup


[*]

The Principle

To make an Amazon Elastic Kubernetes Service (EKS) cluster personal and permit nodes to affix by way of a node group, you should observe a number of steps. By default, EKS creates a public cluster, however you may configure it to make it personal for enhanced safety. Right here’s an summary of the method:

  1. Create a VPC: Begin by making a Digital Non-public Cloud (VPC) in your AWS account in case you haven’t already. This VPC can be used to host your personal EKS cluster.
  2. Create personal subnets: Inside the VPC, create a number of personal subnets. These subnets will present the community isolation required for a personal cluster. Be sure that the subnets haven’t any direct web entry and that their route tables would not have an web gateway connected.
  3. Create safety teams: Create safety teams to outline the inbound and outbound site visitors guidelines to your EKS cluster and nodes. These safety teams ought to permit communication between the management aircraft and the employee nodes, in addition to every other needed community site visitors.
  4. Create a NAT gateway: For the reason that personal subnets don’t have direct web entry, you should arrange a Community Tackle Translation (NAT) gateway in a public subnet to allow outbound web connectivity for assets within the personal subnets.
  5. Configure VPC endpoints: Create VPC endpoints for EKS and EC2 to permit personal communication between your EKS cluster management aircraft and the employee nodes. These endpoints will make sure that the management aircraft and nodes can talk with out requiring entry to the general public web.
  6. Create a personal EKS cluster: Now, create a personal EKS cluster utilizing the AWS Administration Console, AWS CLI, or AWS SDKs. Through the cluster creation, specify the personal subnets, safety teams, and VPC endpoints you created earlier. This can make sure that the cluster is deployed inside the personal subnets and may talk with the nodes through the VPC endpoints.
  7. Create a node group: As soon as the cluster is created, you may proceed to create a node group. When creating the node group, specify the personal subnets and safety teams that you simply arrange earlier. The node group can be deployed within the personal subnets and be a part of the personal EKS cluster.

Following these steps will lead to a personal EKS cluster the place the management aircraft and employee nodes talk privately by way of the VPC endpoints. The personal nature of the cluster enhances safety by decreasing publicity to the general public web.

Be aware that these steps present a high-level overview of the method, and there could also be extra issues or customizations based mostly in your particular necessities. For detailed directions and essentially the most up-to-date info, it’s really useful to consult with the official AWS EKS documentation.

How to do that in Terraform

To create a personal Amazon EKS cluster and permit nodes to affix by way of a node group utilizing Terraform, you may observe the steps outlined beneath:

  1. Arrange the mandatory Terraform information: Create a brand new listing to your Terraform configuration and create the principle.tf file inside it.
  2. Configure the AWS supplier: In the principle.tf file, configure the AWS supplier to outline your AWS entry credentials and the specified area:
supplier "aws" {
  area = "your_region"
}
  1. Create a VPC: Outline a VPC useful resource to create the Digital Non-public Cloud:
useful resource "aws_vpc" "my_vpc" {
  cidr_block = "10.0.0.0/16"
}
  1. Create personal subnets: Outline personal subnets inside the VPC to host your EKS cluster:
useful resource "aws_subnet" "private_subnet" {
  rely = 2
  vpc_id     = aws_vpc.my_vpc.id
  cidr_block = "10.0.${rely.index}.0/24"
}
  1. Create safety teams: Outline safety teams to permit inbound and outbound site visitors for the EKS cluster:
useful resource "aws_security_group" "eks_cluster_sg" {
  vpc_id = aws_vpc.my_vpc.id

  # Outline inbound and outbound guidelines as per your necessities
  # Instance:
  ingress {
    from_port   = 22
    to_port     = 22
    protocol    = "tcp"
    cidr_blocks = ["0.0.0.0/0"]
  }

  egress {
    from_port   = 0
    to_port     = 0
    protocol    = "-1"
    cidr_blocks = ["0.0.0.0/0"]
  }
}
  1. Create a NAT gateway: Configure a NAT gateway to offer outbound web entry to assets within the personal subnets:
useful resource "aws_eip" "nat_eip" {
  vpc      = true
}

useful resource "aws_nat_gateway" "nat_gateway" {
  allocation_id = aws_eip.nat_eip.id
  subnet_id     = aws_subnet.private_subnet[0].id
}

# Create a route desk entry for the NAT gateway
useful resource "aws_route" "private_subnet_nat_route" {
  route_table_id         = aws_subnet.private_subnet[0].route_table_id
  destination_cidr_block = "0.0.0.0/0"
  nat_gateway_id         = aws_nat_gateway.nat_gateway.id
}
  1. Configure VPC endpoints: Create VPC endpoints for EKS and EC2 to allow personal communication:
useful resource "aws_vpc_endpoint" "eks_endpoint" {
  vpc_id       = aws_vpc.my_vpc.id
  service_name = "com.amazonaws.${var.area}.eks"
}

useful resource "aws_vpc_endpoint" "ec2_endpoint" {
  vpc_id       = aws_vpc.my_vpc.id
  service_name = "com.amazonaws.${var.area}.ec2"
}
  1. Create a personal EKS cluster: Outline the EKS cluster useful resource with the suitable settings:
useful resource "aws_eks_cluster" "my_eks_cluster" {
  title     = "my-cluster"
  role_arn = aws_iam_role.my_eks_role.arn

  vpc_config {
    subnet_ids          = aws_subnet.private_subnet[*].id
    security_group_ids  = [aws_security_group.eks_cluster_sg.id]
    endpoint_private_access = true
    endpoint_public_access  = false
  }

  depends_on = [
    aws_vpc_endpoint.eks_endpoint,
    aws_vpc_endpoint.ec2_endpoint
  ]
}
  1. Create a node group: Outline the EKS node group useful resource to affix the personal EKS cluster:
useful resource "aws_eks_node_group" "my_eks_nodegroup" {
  cluster_name    = aws_eks_cluster.my_eks_cluster.title
  node_group_name = "my-nodegroup"

  node_group_config {
    instance_type = "your_instance_type"
    desired_size  = 1
    min_size      = 1
    max_size      = 1
    subnet_ids    = aws_subnet.private_subnet[*].id
    ami_type      = "AL2_x86_64"
  }
}
  1. Apply the Terraform configuration: Initialize the Terraform working listing and apply the configuration:
terraform init
terraform apply

This configuration will create a personal VPC, subnets, safety teams, NAT gateway, VPC endpoints, EKS cluster, and a node group that joins the personal cluster.

Be sure that to customise the configuration in line with your particular necessities, equivalent to VPC CIDR blocks, safety group guidelines, EKS cluster title, node group occasion sort, and many others.

Be aware: This can be a simplified instance, and there could also be extra assets or configuration choices you should think about based mostly in your particular wants. It’s really useful to consult with the Terraform AWS supplier documentation for detailed info on every useful resource and its attributes.

How to do that in CloudFormation

To create a personal Amazon EKS cluster and permit nodes to affix by way of a node group utilizing AWS CloudFormation, you should utilize AWS CloudFormation templates to outline the infrastructure as code. Right here’s a top level view of the steps to perform this:

  1. Create an AWS CloudFormation template: Create a brand new CloudFormation template in YAML or JSON format. This template will outline the assets required to your personal EKS cluster.
  2. Outline the VPC and subnets: Specify the VPC and personal subnets the place your EKS cluster will reside:
Assets:
  MyVPC:
    Kind: AWS::EC2::VPC
    Properties:
      CidrBlock: 10.0.0.0/16

  PrivateSubnet1:
    Kind: AWS::EC2::Subnet
    Properties:
      VpcId: !Ref MyVPC
      CidrBlock: 10.0.0.0/24

  PrivateSubnet2:
    Kind: AWS::EC2::Subnet
    Properties:
      VpcId: !Ref MyVPC
      CidrBlock: 10.0.1.0/24
  1. Create safety teams: Outline the safety teams to manage inbound and outbound site visitors to your EKS cluster:
Assets:
  EKSSecurityGroup:
    Kind: AWS::EC2::SecurityGroup
    Properties:
      GroupDescription: EKS safety group
      VpcId: !Ref MyVPC
      SecurityGroupIngress:
        - IpProtocol: tcp
          FromPort: 22
          ToPort: 22
          CidrIp: 0.0.0.0/0
      SecurityGroupEgress:
        - IpProtocol: "-1"
          FromPort: 0
          ToPort: 0
          CidrIp: 0.0.0.0/0
  1. Create a NAT gateway: Arrange a NAT gateway to allow outbound web entry for the personal subnets:
Assets:
  MyEIP:
    Kind: AWS::EC2::EIP
    Properties:
      Area: vpc

  MyNATGateway:
    Kind: AWS::EC2::NatGateway
    Properties:
      AllocationId: !GetAtt MyEIP.AllocationId
      SubnetId: !Ref PrivateSubnet1

  PrivateSubnet1RouteTable:
    Kind: AWS::EC2::RouteTable
    Properties:
      VpcId: !Ref MyVPC

  PrivateSubnet1Route:
    Kind: AWS::EC2::Route
    DependsOn: MyNATGateway
    Properties:
      RouteTableId: !Ref PrivateSubnet1RouteTable
      DestinationCidrBlock: 0.0.0.0/0
      NatGatewayId: !Ref MyNATGateway

  PrivateSubnet1Association:
    Kind: AWS::EC2::SubnetRouteTableAssociation
    Properties:
      SubnetId: !Ref PrivateSubnet1
      RouteTableId: !Ref PrivateSubnet1RouteTable
  1. Configure VPC endpoints: Create VPC endpoints for EKS and EC2 to allow personal communication:
Assets:
  EKSEndpoint:
    Kind: AWS::EC2::VPCEndpoint
    Properties:
      VpcId: !Ref MyVPC
      ServiceName: com.amazonaws.<area>.eks

  EC2Endpoint:
    Kind: AWS::EC2::VPCEndpoint
    Properties:
      VpcId: !Ref MyVPC
      ServiceName: com.amazonaws.<area>.ec2
  1. Create a personal EKS cluster: Outline the EKS cluster useful resource with the suitable settings:
Assets:
  MyEKSCluster:
    Kind: AWS::EKS::Cluster
    Properties:
      Title: my-cluster
      ResourcesVpcConfig:
        SecurityGroupIds:
          - !Ref EKSSecurityGroup
        SubnetIds:
          - !Ref PrivateSubnet1
          - !Ref PrivateSubnet2
      Model: "1.21"
      RoleArn: arn:aws:iam::123456789012:function/MyEKSClusterRole
      KubernetesNetworkConfig:
        ServiceIpv4Cidr: "10.100.0.0/16"
  1. Create a node group: Outline the EKS node group useful resource to affix the personal EKS cluster:
Assets:
  MyEKSNodeGroup:
    Kind: AWS::EKS::Nodegroup
    Properties:
      ClusterName: !Ref MyEKSCluster
      NodegroupName: my-nodegroup
      ScalingConfig:
        DesiredSize: 1
        MinSize: 1
        MaxSize: 3
      Subnets:
        - !Ref PrivateSubnet1
        - !Ref PrivateSubnet2
      InstanceTypes:
        - t3.medium
      RemoteAccess:
        Ec2SshKey: my-key-pair
  1. Deploy the CloudFormation stack: Use the AWS Administration Console, AWS CLI, or AWS SDKs to deploy the CloudFormation stack together with your template.

Be certain that you customise the configuration based mostly in your particular necessities, equivalent to VPC CIDR blocks, safety group guidelines, EKS cluster title, node group occasion sort, and many others.

Please notice that it is a simplified instance, and extra issues and customization could also be required based mostly in your particular wants. For extra detailed info on every useful resource and its properties, seek the advice of the AWS CloudFormation documentation.

[*]
[*]Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments