可在 AWS 控制台中创建一个 launch template 或通过以下命令进行创建(需要AWS CLI):
aws ec2 create-launch-template --launch-template-name my-launch-template --image-id ami-1234567890abcdef0 --instance-type t2.micro --key-name my-key-pair --security-group-ids sg-049df611 --subnet-id subnet-0753b470 --user-data file://my-script.txt
此命令将创建并命名一个新的 launch template,其中:
· --image-id 指定 AMI ID。
· --instance-type 指定实例类型。
· --key-name 指定 SSH 密钥对。
· --security-group-ids 指定安全组 ID。
· --subnet-id 指定子网 ID。
· --user-data 指定要启动实例时提供的脚本。
(以下例子中,使用了已经创建好的命名为 my-launch-template 的 launch template)
或者,也可以通过以下命令将现有 ASG 的配置更新到 Launch Template:
aws autoscaling update-auto-scaling-group --auto-scaling-group-name my-asg --launch-template LaunchTemplateId=[my-launch-template ID],Version=[my-launch-template version],Overrides=[{InstanceType=t2.small}]
此命令将调用 AWS Autoscaling API 来更新现有 ASG 的启动配置,其中:
· --auto-scaling-group-name my-asg 指定要更新的 ASG 名称。
· --launch-template LaunchTemplateId=[my-launch-template ID],Version=[my-launch-template version],Overrides=[{InstanceType=t2.small}] 指定要用于更新 ASG 的 Launch Template 的 ID 和版本,以及要更新的实例类型。
使用 Kubernetes 中的命令可以对 kubectl 应用进行更新,在 EKS 中创建或更新 ASG:
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-deployment