intelligent infrastructure with saltstack

31
Intelligent Infrastructure with SaltStack Love Billingskog Nyberg Infrastructure and Opera=ons Team Lead Event > React > Orchestrate

Upload: love-nyberg

Post on 25-Jan-2017

433 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Intelligent infrastructure with SaltStack

Intelligent Infrastructure with SaltStack

Love Billingskog Nyberg Infrastructure and Opera=ons Team Lead

Event > React > Orchestrate

Page 2: Intelligent infrastructure with SaltStack

Hi!

Love @jacksoncage

Page 3: Intelligent infrastructure with SaltStack

bloglovintens of millions of monthly unique visitors hundred of millions requests per day couple of million stories parsed per day

hybrid bare-metal servers/cloud vm’s 4 salt masters ~90 salt minions

Page 4: Intelligent infrastructure with SaltStack

salt @ bloglovinParts we use!

States/Pillars/Grains Pillarstack* Orchestrate Reactor Beacons Engines

Page 5: Intelligent infrastructure with SaltStack

Parallel execu=on to run all the resources concurrently

Event driven to monitor and react dynamically only to changes

Next genera=on

Page 6: Intelligent infrastructure with SaltStack

Next genera=on

Page 7: Intelligent infrastructure with SaltStack

Parallel execu=on

root@salt-dev:~# salt '*' test.ping web101: True db101: True ship101: True master: True

Easy to target remote execu5on against mul5ple targets

Page 8: Intelligent infrastructure with SaltStack

Parallel execu=onRun commands via execu5on modules

root@salt-dev:~# salt web* service.stop nginx web101: True

Page 9: Intelligent infrastructure with SaltStack

Tradi=onal configura=onSe;ng state on interval or on run

Page 10: Intelligent infrastructure with SaltStack

Event driven configura=onSe;ng state when needed or change has happened

Page 11: Intelligent infrastructure with SaltStack

GoalsMonitoring - How can salt react to monitoring events and adjust

system without any manual interference

Minions - When a new device is connected get it’s data and no=fy me, chat Vw!

Containers - When a new container starts, update load balancer for that cluster and start sending traffic. Also when a container stops, get logs and restart and send logs to team

Page 12: Intelligent infrastructure with SaltStack

Eventssalt/job/20160413070418586332/new { "_stamp": "2016-04-13T11:04:18.587129", "arg": [], "fun": "test.ping", "jid": "20160413070418586332", "minions": [ "web101" ], "tgt": "web101", "tgt_type": "glob", "user": "sudo_love" }

salt-run state.event pretty=True

Page 13: Intelligent infrastructure with SaltStack

Eventssalt/job/20160413070418586332/ret/web101 { "_stamp": "2016-04-13T11:04:18.789831", "cmd": "_return", "fun": "test.ping", "fun_args": [], "id": "web101", "jid": "20160413070418586332", "retcode": 0, "return": true, "success": true }

Page 14: Intelligent infrastructure with SaltStack

State eventsEnabling state events causes the Salt minion to send progress events as

each func5on in a state run completes execu5on.

state_events: True

minion

Page 15: Intelligent infrastructure with SaltStack

State eventsWhich can become an over load, let’s fire only on specific states

installed/vim: pkg.installed: - name: vim - fire_event: installed/vim

minion

Page 16: Intelligent infrastructure with SaltStack

Custom eventEnabling state events causes the Salt minion to send progress events as

each func5on in a state run completes execu5on.salt-call event.send /deploy/test/case '{"data": "Ready"}'

/deploy/test/case { "_stamp": "2016-04-13T11:01:24.553140", "cmd": "_minion_event", "data": { "__pub_fun": "event.send", "__pub_jid": "20160413070124500641", "__pub_pid": 17046, "__pub_tgt": "salt-call", "data": "Ready" …

minion

Page 17: Intelligent infrastructure with SaltStack

Beacons

beacons: service: nginx: onchangeonly: True

Hook into system processes. Translate external events into the salt event bus

minion

Page 18: Intelligent infrastructure with SaltStack

Engines

engines: docker_events: docker_url: unix://var/run/docker.sock

Salt Engines are long-running, external system processes that leverage Salt.

minion

Page 19: Intelligent infrastructure with SaltStack

Great! Events for everything!

Page 20: Intelligent infrastructure with SaltStack

ReactorSalt’s Reactor system gives you the ability to trigger ac5ons in response to any event.

reactor: # Master config section "reactor"

- 'salt/minion/*/start': # Match tag "salt/minion/*/start" - /srv/reactor/start.sls # Things to do when a minion starts

- 'deploy/containers': # Match tag "deploy/containers" - /srv/reactor/deploy-containers.sls # Things to do when a container is deployed

- 'salt/netapi/hook/api/devlovin/create': # Listing on salt api for /devlovin/create - /srv/reactor/devlovin-create.sls # Things to do when a create request is sent

master

Page 21: Intelligent infrastructure with SaltStack

ReactorSalt’s Reactor system gives you the ability to trigger ac5ons in response to any event.

Remote execu=on: run an execu=on module on the targeted minions.

Runners: These are tasks you would start using salt-run.

Wheel: Wheel commands manage your Salt environment.

master

Page 22: Intelligent infrastructure with SaltStack

ReactorSalt’s Reactor system gives you the ability to trigger ac5ons in response to any event.

<section id>: local.<function>: - tgt: <target> - arg: <arguments>

master

Page 23: Intelligent infrastructure with SaltStack

# This script is to be called from the reactor system {%- set application = data['data']['application'] %} {%- set container = data['data']['container'] %} {%- set target = data['data']['target'] %} {%- set tag = data['data']['tag'] %}

sync-states: local.saltutil.sync_states: - tgt: {{ target }} deploy-containers: local.state.sls: - tgt: {{ target }} - arg: - containers.{{ container }} - kwarg: pillar: containers: imagetag: {{ application }}: {{ tag }}

master

Page 24: Intelligent infrastructure with SaltStack

highstate_run: local.state.highstate: - tgt: db101

call_some_orchestrate_file: runner.state.orchestrate: - mods: some_orchestrate_file - pillar: stuff: things

Highstate run

Star5ng a orchestrator runner

master

Page 25: Intelligent infrastructure with SaltStack

OrchestrateThe orchestrate runner generalizes the Salt state system to a Salt master context.

master

Page 26: Intelligent infrastructure with SaltStack

# Create AWS EC2 instance create-instance: salt.state: - tgt: {{ master }} - sls: devlovin.cloud.create - concurrent: True - pillar: devlovinreact: instancename: {{ basename }}{{ username }}

# Run highstate highstate-run: salt.state: - tgt: {{ basename }}{{ username }} - highstate: True - pillar: devlovinreact: username: {{ username }} - require: - salt: create-instance

master

Page 27: Intelligent infrastructure with SaltStack

Demo

Monitoring - How can salt react to monitoring events and adjust system without any manual interference

Page 28: Intelligent infrastructure with SaltStack

Demo

Minions - When a new device is connected get it’s data and no=fy me, chat Vw!

Page 29: Intelligent infrastructure with SaltStack

Demo

Containers - When a new container starts, update load balancer for that cluster and start sending traffic. Also when a container stops, get logs and restart and send logs to team

Page 30: Intelligent infrastructure with SaltStack

Ques=ons?

Love Billingskog Nyberg @jacksoncage

[email protected]

Page 31: Intelligent infrastructure with SaltStack

Thanks!

Love Billingskog Nyberg @jacksoncage

[email protected]

Use the SaltConf16 event app to provide feedback