How Do I Build an EKS Managed Node Group?
Introduction
In this guide, we will walk through the process of building an Amazon Elastic Kubernetes Service (EKS) managed node group using Pulumi. An EKS managed node group simplifies the management of Kubernetes worker nodes by automating node lifecycle tasks such as scaling and maintenance. This tutorial will provide a step-by-step explanation to help you set up your EKS cluster and node group efficiently.
Prerequisites
Before you start, ensure you have the following resources ready:
- VPC: The networking layer that will host your EKS cluster.
- EKS Cluster: The core platform for container orchestration.
- IAM Roles: Necessary permissions for EKS to manage nodes.
- Security Groups: To control network access.
Step-by-Step Process
Define a VPC and Subnet: Begin by setting up a VPC and a subnet to host your EKS cluster. This provides the necessary network infrastructure.
Create Security Groups: Establish security groups to manage network access to your EKS cluster.
Set Up IAM Roles: Create IAM roles with appropriate policies for both the EKS cluster and the node group. This involves defining roles and attaching the necessary policies.
Create the EKS Cluster: Use the defined roles and network configurations to create the EKS cluster. Ensure you specify the VPC and subnet IDs in the configuration.
Define the Node Group: Set up an EKS managed node group, specifying the cluster name, node role, and subnet IDs. Configure the scaling parameters to control the desired, minimum, and maximum number of nodes.
Here is the code example that implements these steps:
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
const main = new aws.ec2.Vpc("main", {cidrBlock: "10.0.0.0/16"});
const subnet1 = new aws.ec2.Subnet("subnet1", {
vpcId: main.id,
cidrBlock: "10.0.1.0/24",
});
const eks = new aws.ec2.SecurityGroup("eks", {vpcId: main.id});
const eksRole = new aws.iam.Role("eks_role", {
name: "eks_role",
assumeRolePolicy: JSON.stringify({
Version: "2012-10-17",
Statement: [{
Action: "sts:AssumeRole",
Principal: {
Service: "eks.amazonaws.com",
},
Effect: "Allow",
}],
}),
});
const eksAmazonEKSClusterPolicy = new aws.iam.RolePolicyAttachment("eks_AmazonEKSClusterPolicy", {
policyArn: "arn:aws:iam::aws:policy/AmazonEKSClusterPolicy",
role: eksRole.name,
});
const example = new aws.eks.Cluster("example", {
name: "example-cluster",
roleArn: eksRole.arn,
vpcConfig: {
subnetIds: [subnet1.id],
},
}, {
dependsOn: [eksAmazonEKSClusterPolicy],
});
const nodeRole = new aws.iam.Role("node_role", {
name: "node_role",
assumeRolePolicy: JSON.stringify({
Version: "2012-10-17",
Statement: [{
Action: "sts:AssumeRole",
Principal: {
Service: "ec2.amazonaws.com",
},
Effect: "Allow",
}],
}),
});
const amazonEKSWorkerNodePolicy = new aws.iam.RolePolicyAttachment("AmazonEKSWorkerNodePolicy", {
policyArn: "arn:aws:iam::aws:policy/AmazonEKSWorkerNodePolicy",
role: nodeRole.name,
});
const exampleNodes = new aws.eks.NodeGroup("example_nodes", {
clusterName: example.name,
nodeGroupName: "example-ng",
nodeRoleArn: nodeRole.arn,
subnetIds: [subnet1.id],
scalingConfig: {
desiredSize: 2,
maxSize: 3,
minSize: 1,
},
});
export const clusterId = example.id;
export const nodeGroupId = exampleNodes.id;
Key Points
- Network Setup: Ensure your VPC and subnets are correctly configured to host the EKS cluster.
- Security and Permissions: Proper IAM roles and policies are crucial for managing cluster and node operations.
- Cluster and Node Group Configuration: Define the cluster and node group with appropriate scaling configurations to meet your workload demands.
Conclusion
By following this guide, you have successfully created an Amazon EKS cluster with a managed node group using Pulumi. This setup allows for efficient scaling and management of your Kubernetes infrastructure, freeing you to focus on deploying and managing applications. Enjoy the benefits of automated Kubernetes infrastructure management!
Deploy this code
Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.
Sign upNew to Pulumi?
Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.
Sign upThank you for your feedback!
If you have a question about how to use Pulumi, reach out in Community Slack.
Open an issue on GitHub to report a problem or suggest an improvement.