Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Learn Bosh - Understand the Bosh Agent - Part 2

Learn Bosh - Understand the Bosh Agent - Part 2

Video on YouTube https://www.youtube.com/watch?v=ta4RarXTxXY

If you want to learn about bosh, then you'll want to learn about the bosh agent - it is how every server/instance is controlled by the bosh director. This part 2 of a 3 part short series into the inner workings of bosh from the perspective of the bosh agent itself.

In this screencast, we find the bosh agent log on a server and trace through its initial boot and the messages that it receives from the director.

Then we look at how it downloads and unpacks blobs - the compile packages (redis-server) and jobs (the configuration and run scripts).

Dr Nic Williams

June 06, 2013
Tweet

More Decks by Dr Nic Williams

Other Decks in Technology

Transcript

  1. DR NIC | STARK & WAYNE | THE DEEP MAGIC

    OF BOSH AGENT ADVANCED Agent logs Boot & apply sequence Blobs Properties Watch now:
  2. DR NIC | STARK & WAYNE | THE DEEP MAGIC

    OF BOSH AGENT redis-­‐server :6379
  3. DR NIC | STARK & WAYNE | THE DEEP MAGIC

    OF BOSH AGENT director monit bosh_agent director: the API for a bosh
  4. DR NIC | STARK & WAYNE | THE DEEP MAGIC

    OF BOSH AGENT director nats-­‐server monit bosh_agent “apply spec” nats: the message bus used within bosh and its managed servers
  5. DR NIC | STARK & WAYNE | THE DEEP MAGIC

    OF BOSH AGENT director blobstore monit bosh_agent “get blobs” nats-­‐server blobstore: blobs/packages accessed by HTTP (nginx & filesystem)
  6. DR NIC | STARK & WAYNE | THE DEEP MAGIC

    OF BOSH AGENT director blobstore redis-­‐server monit bosh_agent “start job” nats-­‐server job: a component or thing that runs
  7. DR NIC | STARK & WAYNE | THE DEEP MAGIC

    OF BOSH AGENT The director assigns a job to the agent
  8. DR NIC | STARK & WAYNE | THE DEEP MAGIC

    OF BOSH AGENT ADVANCED Agent logs Boot & apply sequence Blobs Properties
  9. DR NIC | STARK & WAYNE | THE DEEP MAGIC

    OF BOSH AGENT agent logs $ bosh ssh redis/0 # sudo tail -f /var/vcap/bosh/log/current 2013-06-04_21:54:09.68919 #[584] INFO: Heartbeat sent 2013-06-04_21:54:09.69033 #[584] DEBUG: Heartbeat delivered 2013-06-04_21:55:09.79097 #[584] INFO: Heartbeat sent 2013-06-04_21:55:09.79201 #[584] DEBUG: Heartbeat delivered 2013-06-04_21:56:09.90876 #[584] INFO: Heartbeat sent
  10. DR NIC | STARK & WAYNE | THE DEEP MAGIC

    OF BOSH AGENT agent messages • migrate_disk • list_disk • mount_disk • unmount_disk • state • drain • apply • compile_package • fetch_logs • ssh • ping • start • stop • prepare_network_change
  11. DR NIC | STARK & WAYNE | THE DEEP MAGIC

    OF BOSH AGENT agent messages • migrate_disk • list_disk • mount_disk • unmount_disk • state • drain • apply • compile_package • fetch_logs • ssh • ping • start • stop • prepare_network_change
  12. DR NIC | STARK & WAYNE | THE DEEP MAGIC

    OF BOSH AGENT BOOT First, the director contacts the agent
  13. DR NIC | STARK & WAYNE | THE DEEP MAGIC

    OF BOSH AGENT boot sequence: Agent Start $ bosh ssh redis/0 # sudo head -n 5 /var/vcap/bosh/log/current INFO: Starting agent 1.5.0.pre.688... INFO: Configuring agent... INFO: Configuring instance INFO: OpenStack user data: "{\"registry\":{\"endpoint\": \"http://admin:admin@localhost:25889\"}...}" INFO: loaded new infrastructure settings: {"networks"=>{...}, "disks"=>{...}, "blobstore"=>{"provider"=>"dav", "options"=>{"endpoint"=>"http://216.55.141.200:25250",...}}, "mbus"=>"nats://nats:[email protected]:4222"}
  14. DR NIC | STARK & WAYNE | THE DEEP MAGIC

    OF BOSH AGENT boot sequence: load settings • User data: registry location • Registry: network, blobstore, message bus • Wait for director to “ping”
  15. DR NIC | STARK & WAYNE | THE DEEP MAGIC

    OF BOSH AGENT boot sequence: Agent Start $ bosh ssh redis/0 # sudo head -n 5 /var/vcap/bosh/log/current INFO: Starting agent 1.5.0.pre.688... INFO: Configuring agent... INFO: Configuring instance INFO: OpenStack user data: "{\"registry\":{\"endpoint\": \"http://admin:admin@localhost:25889\"}...}" INFO: loaded new infrastructure settings: {"networks"=>{...}, "disks"=>{...}, "blobstore"=>{"provider"=>"dav", "options"=>{"endpoint"=>"http://216.55.141.200:25250",...}}, "mbus"=>"nats://nats:[email protected]:4222"}
  16. DR NIC | STARK & WAYNE | THE DEEP MAGIC

    OF BOSH AGENT director nats-­‐server monit bosh_agent “ping” the agent is running...
  17. DR NIC | STARK & WAYNE | THE DEEP MAGIC

    OF BOSH AGENT boot sequence: the ping $ bosh ssh redis/0 # sudo grep ping /var/vcap/bosh/log/current INFO: Message: {"method"=>"ping", "arguments"=>[], "reply_to"=>"director.43dcae02-2e48-45ee-953e- e40b0a4240f5.bb1638e0-aba3-4329-b909-f7bd1af8fa38"}
  18. DR NIC | STARK & WAYNE | THE DEEP MAGIC

    OF BOSH AGENT APPLY The director assigns a job to the agent
  19. DR NIC | STARK & WAYNE | THE DEEP MAGIC

    OF BOSH AGENT apply sequence • drain • stop • apply • migrate_disk • list_disk • mount_disk • unmount_disk • state • drain • apply • compile_package • fetch_logs • ssh • ping • start • stop • prepare_network_change
  20. DR NIC | STARK & WAYNE | THE DEEP MAGIC

    OF BOSH AGENT apply sequence: drain $ bosh ssh redis/0 # sudo grep drain /var/vcap/bosh/log/current INFO: Message: {"method"=>"drain", "arguments"=>["update", SPEC], "reply_to"=>"director.UUID"}
  21. DR NIC | STARK & WAYNE | THE DEEP MAGIC

    OF BOSH AGENT apply sequence: stop $ bosh ssh redis/0 # sudo grep stop /var/vcap/bosh/log/current INFO: Message: {"method"=>"stop", "arguments"=>[], "reply_to"=>"director.UUID"}
  22. DR NIC | STARK & WAYNE | THE DEEP MAGIC

    OF BOSH AGENT apply sequence: apply $ bosh ssh redis/0 # sudo grep apply /var/vcap/bosh/log/current INFO: Message: {"method"=>"apply", "arguments"=>[SPEC], "reply_to"=>"director.UUID"}
  23. DR NIC | STARK & WAYNE | THE DEEP MAGIC

    OF BOSH AGENT apply spec --- deployment: redis-solo release: name: redis version: '1' job: name: redis release: redis templates: - name: redis version: '1' sha1: 2df760cb4dbb87ac14a0bdc0c0a5599765eb3562 blobstore_id: 59f2df4e-d074-4361-a423-e20827566955 template: redis version: '1' sha1: 2df760cb4dbb87ac14a0bdc0c0a5599765eb3562 blobstore_id: 59f2df4e-d074-4361-a423-e20827566955 index: 0 networks: default: type: dynamic cloud_properties: security_groups: - default dns: - 10.0.0.2 - 10.0.0.1 default: - dns - gateway ip: 10.0.0.3 netmask: 255.255.255.0 gateway: 10.0.0.1 resource_pool: name: common cloud_properties: instance_type: m1.microbosh stemcell: name: bosh-stemcell version: '693' packages: redis: name: redis version: '1.1' sha1: f067136887d2c36bbb7956e336ed2d7274e595dc blobstore_id: 13db6a1a-c262-4cc1-b765-b401b47cd366 persistent_disk: 0 configuration_hash: 9faf8fefb95ca77e274130d54decf3c54063b2fa properties: redis: port: 6379 password: r3d!s template_hashes: redis: 1611520ec07e62f36ca4e40a9283cb442504cabd actually passed as JSON
  24. DR NIC | STARK & WAYNE | THE DEEP MAGIC

    OF BOSH AGENT apply spec --- deployment: redis-solo release: name: redis version: '1' job: name: redis release: redis templates: - name: redis version: '1' sha1: 2df760cb4dbb87ac14a0bdc0c0a5599765eb3562 blobstore_id: 59f2df4e-d074-4361-a423-e20827566955 template: redis version: '1' sha1: 2df760cb4dbb87ac14a0bdc0c0a5599765eb3562 blobstore_id: 59f2df4e-d074-4361-a423-e20827566955 index: 0 networks: default: type: dynamic cloud_properties: security_groups: - default dns: - 10.0.0.2 - 10.0.0.1 default: - dns - gateway ip: 10.0.0.3 netmask: 255.255.255.0 gateway: 10.0.0.1 resource_pool: name: common cloud_properties: instance_type: m1.microbosh stemcell: name: bosh-stemcell version: '693' packages: redis: name: redis version: '1.1' sha1: f067136887d2c36bbb7956e336ed2d7274e595dc blobstore_id: 13db6a1a-c262-4cc1-b765-b401b47cd366 persistent_disk: 0 configuration_hash: 9faf8fefb95ca77e274130d54decf3c54063b2fa properties: redis: port: 6379 password: r3d!s template_hashes: redis: 1611520ec07e62f36ca4e40a9283cb442504cabd job packages properties
  25. DR NIC | STARK & WAYNE | THE DEEP MAGIC

    OF BOSH AGENT properties: redis: port: 6379 password: r3d!s apply spec properties
  26. DR NIC | STARK & WAYNE | THE DEEP MAGIC

    OF BOSH AGENT apply spec job job: name: redis release: redis templates: - name: redis version: '1' sha1: 2df760cb4dbb87ac14a0bdc0c0a5599765eb3562 blobstore_id: 59f2df4e-d074-4361-a423-e20827566955
  27. DR NIC | STARK & WAYNE | THE DEEP MAGIC

    OF BOSH AGENT packages: redis: name: redis version: '1.1' sha1: f067136887d2c36bbb7956e336ed2d7274e595dc blobstore_id: 13db6a1a-c262-4cc1-b765-b401b47cd366 apply spec packages
  28. DR NIC | STARK & WAYNE | THE DEEP MAGIC

    OF BOSH AGENT packages: redis: name: redis version: '1.1' sha1: f067136887d2c36bbb7956e336ed2d7274e595dc blobstore_id: 13db6a1a-c262-4cc1-b765-b401b47cd366 blobs $ bosh ssh redis/0 # sudo head -n 5 /var/vcap/bosh/log/current ... INFO: loaded new infrastructure settings: {"networks"=>{...}, "blobstore"=>{"provider"=>"dav", "options"=>{"endpoint"=>"http://216.55.141.200:25250", "user"=>"agent", "password"=>"agent"}}, ...} curl -u agent:agent http://216.55.141.200:25250/b3/13db6a1a-c262-4cc1-b765-b401b47cd366
  29. DR NIC | STARK & WAYNE | THE DEEP MAGIC

    OF BOSH AGENT blobstore client $ cat blobstore.yml --- endpoint: http://216.55.141.200:25250 user: agent password: agent $ blobstore_client_console -p dav -c blobstore.yml => Welcome to BOSH blobstore client console You can use 'bsc' to access blobstore client methods bsc.object_exists?("13db6a1a-c262-4cc1-b765-b401b47cd366") => true $ blobstore_client_console -p dav -c blobstore.yml File.open("redis-package.tgz", "w") do |f| bsc.get_file("13db6a1a-c262-4cc1-b765-b401b47cd366", f) end $ tar xfz redis-package.tgz $ ls bin/* bin/redis-benchmark bin/redis-check-aof bin/redis-check-dump bin/redis-cli bin/redis-server
  30. DR NIC | STARK & WAYNE | THE DEEP MAGIC

    OF BOSH AGENT director nats-­‐server monit bosh_agent get_file agent downloads blobs... blobstore
  31. DR NIC | STARK & WAYNE | THE DEEP MAGIC

    OF BOSH AGENT apply spec job: name: redis release: redis templates: - name: redis version: '1' sha1: 2df760cb4dbb87ac14a0bdc0c0a5599765eb3562 blobstore_id: 59f2df4e-d074-4361-a423-e20827566955 job
  32. DR NIC | STARK & WAYNE | THE DEEP MAGIC

    OF BOSH AGENT get job blob $ blobstore_client_console -p dav -c blobstore.yml File.open("redis-job.tgz", "w") do |f| bsc.get_file("59f2df4e-d074-4361-a423-e20827566955", f) end $ tar xfz redis-job.tgz $ ls * job.MF monit templates: bin config data helpers
  33. DR NIC | STARK & WAYNE | THE DEEP MAGIC

    OF BOSH AGENT job manifest $ cat job.MF --- name: redis packages: - redis templates: config/redis.conf.erb: config/redis.conf bin/redis_ctl: bin/redis_ctl bin/monit_debugger: bin/monit_debugger data/properties.sh.erb: data/properties.sh helpers/ctl_setup.sh: helpers/ctl_setup.sh helpers/ctl_utils.sh: helpers/ctl_utils.sh properties: redis.port: description: Port to listen for requests to redis server default: 6379 redis.password: description: Password to access redis server default: "r3d!s"
  34. DR NIC | STARK & WAYNE | THE DEEP MAGIC

    OF BOSH AGENT $ cat job.MF --- name: redis packages: - redis templates: config/redis.conf.erb: config/redis.conf bin/redis_ctl: bin/redis_ctl bin/monit_debugger: bin/monit_debugger data/properties.sh.erb: data/properties.sh helpers/ctl_setup.sh: helpers/ctl_setup.sh helpers/ctl_utils.sh: helpers/ctl_utils.sh properties: redis.port: description: Port to listen for requests to redis default: 6379 redis.password: description: Password to access redis server default: "r3d!s" job spec in bosh release = job.MF in blob
  35. DR NIC | STARK & WAYNE | THE DEEP MAGIC

    OF BOSH AGENT templates $ ls templates/config/* templates/config/redis.conf.erb $ grep '<%=' templates/config/redis.conf.erb port <%= p("redis.port") %> requirepass <%= p("redis.password") %>
  36. DR NIC | STARK & WAYNE | THE DEEP MAGIC

    OF BOSH AGENT properties: redis: port: 6379 password: r3d!s apply spec properties
  37. DR NIC | STARK & WAYNE | THE DEEP MAGIC

    OF BOSH AGENT properties: redis: {} apply spec properties properties: redis: port: 7000 password: supersecret all defaults all overrides
  38. DR NIC | STARK & WAYNE | THE DEEP MAGIC

    OF BOSH AGENT WORKSHOP Watch a bosh agent inside Vagrant Watch next: redis-­‐server monit bosh_agent