Cookbook development¶
Imported from Confluence
Content may be outdated. Verify before following any procedures. View original | Last updated: November 2023
Configuration pipeline
Baking - run chef-client -z against exported policyfile inside packer to provision image
Making changes on existing servers:
- If it is stateless, immutable server/group of servers then bake new image and redeploy servers group (blue-green deployment in spotinst elastigroup), the same approach as for containers
- If it is stateful, mutable server/group of servers which couldn't be redeployed then there could be different ways:
- As we use consul for service discovery and KV store, cookbook could contain consul-template which will query consul cluster for changes in services or KV store and render new config files from appropriate templates
- Export new version of policyfile, upload it to s3 or policy group on chef server and run chef-client (THIS PIPELINE is UNDER DEPLOYMENT NOW)
Requirements¶
- Don't use search to find nodes by roles, environments etc., it won't work in environment without chef server, it won't work in packer while baking image
- If configuration behaviour will change at runtime, keep in mind step 2 and predefine all needed attributes. Also keep in mind that attributes in user data and policyfile could be different and second chef run will overwrite them, so use this way only for immutable servers and make changes via redeployment with new image
- All services should be registered in consul cluster
- Application parameters which could be changed have to be stored in Consul KV store, configuration files should rendered with consul-template. Cookbook should allow to change type of parameter, will it be dynamic (consul: true) or static (consul: false)
Example from druid cookbook:
default[cookbook_name]['druid']['config']['jvm']['middleManager'] = {
'-Xms' => { 'value' => '64m', 'consul': true },
'-Xmx' => { 'value' => '64m', 'consul': true },
}