简体   繁体   English

Cloudformation堆栈删除上的Cleanup Chef节点/客户端

[英]Cleanup Chef node/client on Cloudformation stack deletion

I have a cloudformation stack that consists of a VPC, two subnets (public and private), several EC2 ubuntu instances and all of the routes, EIP addresses, etc. One of the EC2 instances is in a public subnet. 我有一个由VPC,两个子网(公共和私有),几个EC2 ubuntu实例以及所有路由,EIP地址等组成的cloudformation堆栈。其中一个EC2实例位于一个公共子网中。 It is bootstrapped as a Chef node on startup. 在启动时将其引导为Chef节点。

I'd like to figure out a way to delete the chef node when the cloudformation stack is deleted. 我想找出一种删除cloudformation堆栈时删除Chef节点的方法。 So far I've tried dropping a cleanup script into EC2 instance /etc/rc0.d. 到目前为止,我已经尝试将清理脚本放入EC2实例/etc/rc0.d中。

This script does what it should when run manually, however when I just delete the stack, it does not seem to run. 手动运行时,该脚本会执行应有的操作,但是当我删除堆栈时,它似乎无法运行。 Actually - it might very well run, but I'm guessing that by the time the EC2 instance shuts down all of the routing and EIP addresses might already be gone, so Chef server might not be reachable by the EC2 instance. 实际上-它可能运行得很好,但是我猜测到EC2实例关闭所有路由时,EIP地址可能已经消失了,因此EC2实例可能无法访问Chef服务器。

I've also tried locking down creation/deletion order with 'DependsOn' attributes, but that didn't work out either - I don't think it's possible to have the IP and routes depend on the instance that is using the said EIP and routes 我也尝试过使用'DependsOn'属性来锁定创建/删除顺序,但这也没有解决-我认为IP和路由可能不会取决于使用所述EIP和路线

Is there some way to setup some sort of monitoring that will make sure Chef cleanup runs before everything else? 是否可以通过某种方式设置某种监控,以确保在执行其他所有操作之前先执行Chef清理工作?

Gist with the template and chef setup/cleanup script 要点与模板和厨师设置/清理脚本

Yes, most likely your IPs are disassociated/removed before the instance shuts down, making any attempt to reach the Chef server from the instance futile. 是的,很可能在实例关闭之前就已取消关联/删除了您的IP,从而使从实例徒劳地访问Chef服务器的任何尝试。 You can always check your cloudformation action logs but disassociating the IP address before shutdown is what makes most sense. 您始终可以检查cloudformation操作日志,但是最有意义的是在关机之前取消IP地址的关联。

I think some of the workaround are: 我认为一些解决方法是:

  1. Build an app on top of your cloudformation creation so that every time you delete a stack it also deletes the node(s) you want from your chef server. 在cloudformation创建的基础上构建一个应用程序,这样,每次删除堆栈时,它还会从Chef服务器中删除所需的节点。 This would a full blown application with a database to keep track of the servers/stacks running. 这将是一个带有数据库的功能完善的应用程序,以跟踪服务器/堆栈的运行情况。 This will require your app to call the chef server API or simply call a system knife command. 这将要求您的应用调用厨师服务器API或简单地调用系统knife命令。

  2. Run your clean up script from another instance running knife/chef-client. 从另一个运行“刀/厨师客户端”的实例运行清理脚本。 You can have some sort of cron/periodic job checking for stacks/servers that have been deleting on AWS and then run the appropriate knife command to delete the server from. 您可以对已经在AWS上删除的堆栈/服务器进行某种形式的cron /定期作业检查,然后运行适当的knife命令从中删除服务器。 This in essence very similar to 1. with just the difference that you don't necessarily have to build a full blown.application. 从本质上讲,这与1.非常相似,只是您不必构建完整的blown.application。

Hope it helps. 希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM