1

每个工人运行多个任务。如果我们有很多任务,我们将需要多个工人。为了节省资源,我们希望根据供应(备用容量)和需求(待处理的任务)弹性地进出工人。

扩展很容易:添加更多节点,它们向 TSA 注册并开始工作。

缩小是比较棘手的:需要等待它的任务完成,然后才能杀死一个工人的实例。否则他们将不得不在另一个工人身上重新开始。这对于小任务来说很好,但对于可能无法接受的较长任务。

AWS 上一种可能的解决方案是使用Autoscaling Lifecycle Hooks同步告诉工作人员不要再接受任何任务并在所有任务完成后返回,然后将其终止。不过,Concourse Worker API没有任何此类操作。

有没有办法实现 Concourse 工作人员的安全扩展?

如果答案是“别担心,波什会处理的”,我想知道这些机制是什么,因为我可能不会使用它。

4

2 回答 2

1

您必须在concourse运行 ATC(即大厅调度程序和 Web 界面)的主机上使用命令行中的二进制文件:

concourse --help
Usage:
  concourse [OPTIONS] <command>

Application Options:
  -v, --version  Print the version of Concourse and exit [$CONCOURSE_VERSION]

Help Options:
  -h, --help     Show this help message

Available commands:
  land-worker    Safely drain a worker's assignments for temporary downtime.
  retire-worker  Safely remove a worker from the cluster permanently.
  web            Run the web UI and build scheduler.
  worker         Run and register a worker.

所以看起来你可以连接到 Autoscaling Lifecycle 服务调用的东西,land-worker然后retire-worker(不确定是否retire-worker足够),一旦你确定你想要停止哪个工人......

当您转回同一个工人时,您可能必须小心工人名称,我似乎记得有时 ATC 会感到困惑,您必须对此进行试验(是否可以保留相同的名称或更改它)。

于 2017-06-09T16:15:21.743 回答
1

您可以在您的 Concourse 工作人员 ASG 上创建一个 Lifecyle 挂钩:

    Type: AWS::AutoScaling::LifecycleHook
    Properties:
      AutoScalingGroupName: !Ref ConcourseWorkerASG
      DefaultResult: CONTINUE / ABANDON
      HeartbeatTimeout: 900 # 15 minutes for example
      LifecycleHookName: lchname
      LifecycleTransition: "autoscaling:EC2_INSTANCE_TERMINATING"

使用脚本让工人退休,类似于

lch.sh

#!/bin/bash

TYPE=$(cat /opt/concourse/type)
tsa_host=zz
instance_id=$(curl -s http://169.254.169.254/latest/meta-data/instance-id/)
lifecycleState=$(aws autoscaling describe-auto-scaling-instances --instance-ids $instance_id --query 'AutoScalingInstances[0].LifecycleState' --output text --region eu-west-1)

if [ "$TYPE" == "worker" ]; then
  if [ "$lifecycleState" == "Terminating:Wait" ]; then
    asg=$(aws autoscaling describe-auto-scaling-instances --instance-ids $instance_id --query 'AutoScalingInstances[0].AutoScalingGroupName' --output text --region eu-west-1)

    /opt/concourse/concourse/bin/concourse retire-worker \
        --name $HOSTNAME \  
        --tsa-host ${tsa_host}:2222 \
        --tsa-public-key some_tsa_host_key.pub \
        --tsa-worker-private-key some_worker_key

    sleep 5m

    systemctl stop your_concourse_service

    aws autoscaling complete-lifecycle-action \
      --instance-id $instance_id \
      --auto-scaling-group-name $asg \
      --lifecycle-hook-name "lchname" \
      --lifecycle-action-result "CONTINUE" \
      --region eu-west-1
  fi
fi

然后安排一个 cronjob,例如通过 Ansible:

- name: List lch.sh as cronjob
  cron:
    name: "check asg lch for retiring the worker"
    minute: "*/5" # run every 5 minutes
    job: "/opt/concourse/lch.sh"
于 2019-06-14T09:45:07.107 回答