Skip to content
This repository has been archived by the owner on Oct 6, 2022. It is now read-only.

Commit

Permalink
support ExtraNodeLabels and auto create node label NVIDIAGPU=1 for GP…
Browse files Browse the repository at this point in the history
…U instances(#2 #3)
  • Loading branch information
pahud committed Jul 7, 2019
1 parent 0d90748 commit e4726c2
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ create-eks-cluster:
ParameterKey=KeyName,ParameterValue="$(SSH_KEY_NAME)" \
ParameterKey=LambdaRoleArn,ParameterValue="$(EKS_ADMIN_ROLE)" \
ParameterKey=OnDemandBaseCapacity,ParameterValue="$(OnDemandBaseCapacity)" \
ParameterKey=NodeImageId,ParameterValue="$(NodeImageId)" \
ParameterKey=NodeAutoScalingGroupMinSize,ParameterValue="$(NodeAutoScalingGroupMinSize)" \
ParameterKey=NodeAutoScalingGroupDesiredSize,ParameterValue="$(NodeAutoScalingGroupDesiredSize)" \
ParameterKey=NodeAutoScalingGroupMaxSize,ParameterValue="$(NodeAutoScalingGroupMaxSize)" \
Expand Down Expand Up @@ -127,6 +128,7 @@ update-eks-cluster:
ParameterKey=KeyName,ParameterValue="$(SSH_KEY_NAME)" \
ParameterKey=LambdaRoleArn,ParameterValue="$(EKS_ADMIN_ROLE)" \
ParameterKey=OnDemandBaseCapacity,ParameterValue="$(OnDemandBaseCapacity)" \
ParameterKey=NodeImageId,ParameterValue="$(NodeImageId)" \
ParameterKey=NodeAutoScalingGroupMinSize,ParameterValue="$(NodeAutoScalingGroupMinSize)" \
ParameterKey=NodeAutoScalingGroupDesiredSize,ParameterValue="$(NodeAutoScalingGroupDesiredSize)" \
ParameterKey=NodeAutoScalingGroupMaxSize,ParameterValue="$(NodeAutoScalingGroupMaxSize)" \
Expand Down
7 changes: 7 additions & 0 deletions cloudformation/eks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ Parameters:
# #Type: List<String>
# Type: String

NodeImageId:
Type: String
Default: ""
Description: Specify AMI id for the node instances. Leave it blank if you preferred the latest EKS-optimized AMI

NodeVolumeSize:
Type: Number
Description: Node volume size
Expand Down Expand Up @@ -194,11 +199,13 @@ Resources:
NodeAutoScalingGroupDesiredSize: !Ref NodeAutoScalingGroupDesiredSize
NodeAutoScalingGroupMaxSize: !Ref NodeAutoScalingGroupMaxSize
NodeVolumeSize: !Ref NodeVolumeSize
NodeImageId: !Ref NodeImageId
OnDemandBaseCapacity: !Ref OnDemandBaseCapacity
LatestAMIId: !GetAtt AMI.Outputs.AmiId
Subnets: !Ref SubnetIds
ExistingNodeSecurityGroups: !Ref ExistingNodeSecurityGroups
ExtraNodeSecurityGroups: !Ref ExtraNodeSecurityGroups



# RootStackName: !Sub "${AWS::StackName}"
Expand Down
29 changes: 23 additions & 6 deletions cloudformation/nodegroup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -230,15 +230,20 @@ Parameters:
ClusterName:
Description: The cluster name provided when the cluster was created. If it is incorrect, nodes will not be able to join the cluster.
Type: String

ExtraNodeLabels:
Description: Extra Node Labels(seperated by comma)
Type: String
Default: "foo=bar"

BootstrapArgumentsForOnDemand:
Description: Arguments to pass to the bootstrap script. See files/bootstrap.sh in https://github.com/awslabs/amazon-eks-ami
Default: "--kubelet-extra-args --node-labels=lifecycle=OnDemand"
Default: "--kubelet-extra-args --node-labels=lifecycle=OnDemand,$ExtraNodeLabels"
Type: String

BootstrapArgumentsForSpotFleet:
Description: Arguments to pass to the bootstrap script. See files/bootstrap.sh in https://github.com/awslabs/amazon-eks-ami
Default: "--kubelet-extra-args '--node-labels=lifecycle=Ec2Spot --register-with-taints=spotInstance=true:PreferNoSchedule'"
Default: "--kubelet-extra-args '--node-labels=lifecycle=Ec2Spot,$ExtraNodeLabels --register-with-taints=spotInstance=true:PreferNoSchedule'"
Type: String

ClusterControlPlaneSecurityGroup:
Expand All @@ -249,6 +254,11 @@ Parameters:
Description: Unique identifier for the Node Group.
Type: String

PauseTime:
Description: Pause Time
Type: String
Default: PT1M

# RootStackName:
# Type: String

Expand Down Expand Up @@ -435,7 +445,7 @@ Resources:
AutoScalingRollingUpdate:
MinInstancesInService: !Ref NodeAutoScalingGroupDesiredSize
MaxBatchSize: '1'
PauseTime: 'PT5M'
PauseTime: !Ref PauseTime

LCH:
Type: AWS::AutoScaling::LifecycleHook
Expand Down Expand Up @@ -473,14 +483,21 @@ Resources:
set -o xtrace
yum install -y ec2-instance-connect
iid=$(curl -s http://169.254.169.254/latest/meta-data/instance-id)
it=$(curl -s http://169.254.169.254/latest/meta-data/instance-type)
export AWS_DEFAULT_REGION=${AWS::Region}
ilc=`aws ec2 describe-instances --instance-ids $iid --query 'Reservations[0].Instances[0].InstanceLifecycle' --output text`
if [[ $it == p* ]] || [[ $it == g* ]]; then
# GPU instance type
ExtraNodeLabels="${ExtraNodeLabels},NVIDIAGPU=1"
else
ExtraNodeLabels="${ExtraNodeLabels}"
fi
if [ "$ilc" == "spot" ]; then
/etc/eks/bootstrap.sh ${ClusterName} ${BootstrapArgumentsForSpotFleet}
bash -c "/etc/eks/bootstrap.sh ${ClusterName} ${BootstrapArgumentsForSpotFleet}"
else
/etc/eks/bootstrap.sh ${ClusterName} ${BootstrapArgumentsForOnDemand}
bash -c "/etc/eks/bootstrap.sh ${ClusterName} ${BootstrapArgumentsForOnDemand}"
fi
# /etc/eks/bootstrap.sh ${ClusterName} $BootstrapArgumentsForOnDemand
/etc/eks/bootstrap.sh ${ClusterName} $BootstrapArgumentsForOnDemand
/opt/aws/bin/cfn-signal --exit-code $? \
--stack ${AWS::StackName} \
--resource NodeGroup \
Expand Down

0 comments on commit e4726c2

Please sign in to comment.