agent: |
arNo9xyeCFz2aAIWyXa1Create worker nodes for EKS cluster 'my-eks-cluster' with t3.micro type EC2 instances, maximum 2 worker nodes, in us-west-2
Create worker nodes for EKS cluster 'my-eks-cluster' with t3.micro type EC2 instances, maximum 2 worker nodes, in us-west-2
There was a problem that the LLM was not able to address. Please rephrase your prompt and try again.
This script creates a node group for the EKS cluster 'my-eks-cluster' with t3.micro EC2 instances, setting the desired capacity to 2, in the us-west-2 region.
inputs
outputs
import boto3
import json
import time
def create_eks_cluster_with_addons():
eks_client = boto3.client(
'eks',
region_name=region,
aws_access_key_id=getEnvVar('AWS_ACCESS_KEY_ID'),
aws_secret_access_key=getEnvVar('AWS_SECRET_ACCESS_KEY')
)
# Step 1: Create the EKS cluster
print("Creating EKS cluster...") # This EKS Cluster allows both endpoint public and private access as shown in the configuration below
response = eks_client.create_cluster(
name=eks_cluster_name,
version=kubernetes_version,
roleArn=role_arn,
resourcesVpcConfig={
'subnetIds': public_subnet_ids,
'securityGroupIds': [security_group_id],
'endpointPublicAccess': True,
'endpointPrivateAccess': True
},
kubernetesNetworkConfig={
'serviceIpv4Cidr': '10.102.0.0/16' # <-- Specify the service CIDR here
}
)
cluster_arn = response['cluster']['arn']
print(f"Cluster ARN: {cluster_arn}")
# Step 2: Wait for the cluster to become active
print("Waiting for EKS cluster to become ACTIVE...")
waiter = eks_client.get_waiter('cluster_active')
waiter.wait(name=eks_cluster_name)
print("EKS cluster is ACTIVE.")
# Step 3: Install essential add-ons
addons = ['vpc-cni', 'kube-proxy', 'coredns']
addons_status = {}
for addon in addons:
try:
print(f"Installing add-on: {addon}")
response = eks_client.create_addon(
clusterName=eks_cluster_name,
addonName=addon
)
addons_status[addon] = 'Created'
except Exception as e:
addons_status[addon] = f'Error: {str(e)}'
print("Add-on status:")
print(json.dumps(addons_status, indent=4, default=str))
return cluster_arn, addons_status
# Run the combined setup
cluster_arn, addons_status = create_eks_cluster_with_addons()
copied