Wednesday, February 21, 2024
HomeSoftware EngineeringHow do you create an EKS cluster utilizing CloudFormation

How do you create an EKS cluster utilizing CloudFormation


The steps to attain this

To create an Amazon Elastic Kubernetes Service (EKS) cluster utilizing CloudFormation, you may observe these steps:

  1. Create a CloudFormation template: Begin by making a CloudFormation template in YAML or JSON format. This template will outline the assets required to your EKS cluster, together with the cluster itself, employee nodes, and different mandatory elements.

  2. Outline the EKS cluster useful resource: Inside your CloudFormation template, outline an AWS::EKS::Cluster useful resource. Specify the specified configuration to your EKS cluster, such because the model, identify, and role-based entry management (RBAC) configuration.

  3. Outline the employee node assets: Subsequent, outline the employee node assets in your CloudFormation template. This may be executed utilizing AWS::AutoScaling::AutoScalingGroup and AWS::EC2::LaunchTemplate assets. Specify the specified occasion kind, AMI, and different configurations to your employee nodes.

  4. Outline the required IAM roles and insurance policies: EKS requires a number of IAM roles and insurance policies for its operation. In your CloudFormation template, outline the required IAM roles and insurance policies utilizing AWS::IAM::Position and AWS::IAM::Coverage assets. These roles will grant permissions to your EKS cluster and employee nodes to work together with different AWS providers.

  5. Add any further assets or configurations: Relying in your particular necessities, you might want to incorporate further assets or configurations in your CloudFormation template. For instance, you would possibly need to provision a VPC, subnets, safety teams, or configure networking settings.

  6. Launch the CloudFormation stack: As soon as your CloudFormation template is prepared, you may launch a CloudFormation stack utilizing the AWS Administration Console, AWS CLI, or AWS SDKs. Present the CloudFormation template file, specify any required parameters, and provoke the stack creation course of.

  7. Monitor the stack creation: CloudFormation will create and provision the required assets based on your template. You may monitor the progress of the stack creation within the CloudFormation console or use the AWS CLI or SDKs to examine the stack standing.

  8. Entry your EKS cluster: After the CloudFormation stack creation is full, you may entry your EKS cluster utilizing the AWS Administration Console, AWS CLI, or Kubernetes command-line instruments (kubectl). You’ll sometimes want the cluster identify and applicable credentials to authenticate and work together with the cluster.

By following these steps, you may create an EKS cluster utilizing CloudFormation and outline the required assets and configurations to fulfill your particular necessities.

The code to attain this

Right here’s an instance CloudFormation template in YAML format that you should utilize to create an EKS cluster with employee nodes:

AWSTemplateFormatVersion: "2010-09-09"
Parameters:
  ClusterName:
    Kind: String
    Description: Identify of the EKS cluster
  WorkerNodeGroupName:
    Kind: String
    Description: Identify of the employee node group
  VpcId:
    Kind: AWS::EC2::VPC::Id
    Description: ID of the VPC the place the cluster will probably be created
  SubnetIds:
    Kind: Listing<AWS::EC2::Subnet::Id>
    Description: Listing of subnet IDs in several availability zones
  KeyName:
    Kind: AWS::EC2::KeyPair::KeyName
    Description: Identify of an current EC2 key pair for SSH entry to employee nodes
Assets:
  EKSCluster:
    Kind: AWS::EKS::Cluster
    Properties:
      Identify: !Ref ClusterName
      ResourcesVpcConfig:
        SecurityGroupIds:
          - !Ref ClusterSecurityGroup
        SubnetIds: !Ref SubnetIds
  ClusterSecurityGroup:
    Kind: AWS::EC2::SecurityGroup
    Properties:
      GroupDescription: EKS cluster safety group
      VpcId: !Ref VpcId
  NodeInstanceProfile:
    Kind: AWS::IAM::InstanceProfile
    Properties:
      Roles:
        - !Ref NodeInstanceRole
  NodeInstanceRole:
    Kind: AWS::IAM::Position
    Properties:
      AssumeRolePolicyDocument:
        Model: "2012-10-17"
        Assertion:
          - Impact: Enable
            Principal:
              Service: ec2.amazonaws.com
            Motion: sts:AssumeRole
      ManagedPolicyArns:
        - arn:aws:iam::aws:coverage/AmazonEKSWorkerNodePolicy
        - arn:aws:iam::aws:coverage/AmazonEKS_CNI_Policy
        - arn:aws:iam::aws:coverage/AmazonEC2ContainerRegistryReadOnly
  NodeAutoScalingGroup:
    Kind: AWS::AutoScaling::AutoScalingGroup
    Properties:
      AutoScalingGroupName: !Ref WorkerNodeGroupName
      VPCZoneIdentifier: !Ref SubnetIds
      MinSize: 1
      MaxSize: 3
      DesiredCapacity: 2
      LaunchConfigurationName: !Ref NodeLaunchConfig
      Tags:
        - Key: kubernetes.io/cluster/${ClusterName}
          Worth: "owned"
          PropagateAtLaunch: true
  NodeLaunchConfig:
    Kind: AWS::AutoScaling::LaunchConfiguration
    Properties:
      ImageId: ami-xxxxxxxxxxxxxx  # Specify the suitable employee node AMI ID to your area
      InstanceType: t3.medium     # Specify the specified employee node occasion kind
      IamInstanceProfile: !Ref NodeInstanceProfile
      SecurityGroups:
        - !Ref NodeSecurityGroup
      KeyName: !Ref KeyName
  NodeSecurityGroup:
    Kind: AWS::EC2::SecurityGroup
    Properties:
      GroupDescription: EKS employee node safety group
      VpcId: !Ref VpcId
Outputs:
  ClusterName:
    Description: EKS cluster identify
    Worth: !Ref ClusterName
  ClusterEndpoint:
    Description: EKS cluster endpoint
    Worth: !GetAtt EKSCluster.Endpoint
  WorkerNodeGroupName:
    Description: EKS employee node group identify
    Worth: !Ref WorkerNodeGroupName

On this template, you may exchange ami-xxxxxxxxxxxxxx with the suitable AMI ID to your area and specify the specified occasion kind (t3.medium within the instance). Additionally, make sure that to offer legitimate values for different parameters corresponding to ClusterName, WorkerNodeGroupName, VpcId, SubnetIds, and KeyName.

This template will create an EKS cluster with the desired identify and VPC configuration. It can additionally create a employee node group utilizing an Auto Scaling Group and launch configuration. The employee nodes will probably be related to the EKS cluster and could have the required IAM roles and safety teams.

You should utilize this CloudFormation template to create a stack utilizing the AWS Administration Console, AWS CLI, or AWS SDKs.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments