1
0

salt_system_architecture.rst 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. .. _salt-system-architecture:
  2. ========================
  3. Salt system architecture
  4. ========================
  5. Overview
  6. ========
  7. This page provides a high-level overview of the Salt system architecture and its
  8. different components.
  9. What is Salt?
  10. =============
  11. Salt is a Python-based open-source remote execution framework used for:
  12. * Configuration management
  13. * Automation
  14. * Provisioning
  15. * Orchestration
  16. The Salt system architecture
  17. ============================
  18. The following diagram shows the primary components of the basic Salt
  19. architecture:
  20. .. image:: /_static/salt-architecture.png
  21. :width: 80%
  22. The following sections describe some of the core components of the Salt
  23. architecture.
  24. Salt Masters and Salt Minions
  25. -----------------------------
  26. Salt uses the master-client model in which a master issues commands to a client
  27. and the client executes the command. In the Salt ecosystem, the Salt Master is a
  28. server that is running the ``salt-master`` service. It issues commands to one or
  29. more Salt Minions, which are servers that are running the ``salt-minion``
  30. service and that are registered with that particular Salt Master.
  31. Another way to describe Salt is as a publisher-subscriber model. The master
  32. publishes jobs that need to be executed and Salt Minions subscribe to those
  33. jobs. When a specific job applies to that minion, it will execute the job.
  34. When a minion finishes executing a job, it sends job return data back to the
  35. master. Salt has two ports used by default for the minions to communicate with
  36. their master(s). These ports work in concert to receive and deliver data to the
  37. Message Bus. Salt’s message bus is ZeroMQ, which creates an asynchronous network
  38. topology to provide the fastest communication possible.
  39. Targets and grains
  40. ------------------
  41. The master indicates which minions should execute the job by defining a
  42. *target*. A target is the group of minions, across one or many masters, that a
  43. job's Salt command applies to.
  44. .. Note::
  45. A master can also be managed like a minion and can be a target if it is
  46. running the ``salt-minion`` service.
  47. The following is an example of one of the many kinds of commands that a master
  48. might issue to a minion. This command indicates that all minions should install
  49. the Vim application:
  50. .. code-block:: bash
  51. salt -v '*' pkg.install vim
  52. In this case the glob ``'*'`` is the target, which indicates that all minions
  53. should execute this command. Many other targeting options are available,
  54. including targeting a specific minion by its ID or targeting minions by their
  55. shared traits or characteristics (called *grains* in Salt).
  56. Salt comes with an interface to derive information about the underlying system.
  57. This is called the *grains interface*, because it presents Salt with grains of
  58. information. Grains are collected for the operating system, domain name,
  59. IP address, kernel, OS type, memory, and many other system properties. You can
  60. also create your own custom grain data.
  61. Grain data is relatively static. However, grain data is refreshed when system
  62. information changes (such as network settings) or when a new value is assigned
  63. to a custom grain.
  64. Open event system (event bus)
  65. -----------------------------
  66. The event system is used for inter-process communication between the Salt Master
  67. and Salt Minions. In the event system:
  68. * Events are seen by both the master and minions.
  69. * Events can be monitored and evaluated by both.
  70. The event bus lays the groundwork for orchestration and real-time monitoring.
  71. All minions see jobs and results by subscribing to events published on the event
  72. system. Salt uses a pluggable event system with two layers:
  73. * **ZeroMQ (0MQ)** - The current default socket-level library providing a
  74. flexible transport layer.
  75. * **Tornado** - Full TCP-based transport layer event system.
  76. One of the greatest strengths of Salt is the speed of execution. The event
  77. system’s communication bus is more efficient than running a higher-level web
  78. service (http). The remote execution system is the component that all components
  79. are built upon, allowing for decentralized remote execution to spread load
  80. across resources.
  81. Salt states
  82. -----------
  83. In addition to remote execution, Salt provides another method for configuring
  84. minions by declaring which *state* a minion should be in, otherwise referred to
  85. as *Salt states*. Salt states make configuration management possible. You can
  86. use Salt states to deploy and manage infrastructure with simple YAML files.
  87. Using states, you can automate recursive and predictable tasks by queueing jobs
  88. for Salt to implement without needing user input. You can also add more complex
  89. conditional logic to state files with Jinja.
  90. To illustrate the subtle differences between remote execution and configuration
  91. management, take the command referenced in the previous section about
  92. `Targets and grains`_ in which Salt installed the application Vim on all
  93. minions:
  94. .. list-table::
  95. :widths: 25 25 50
  96. :header-rows: 1
  97. * - Methodology
  98. - Implementation
  99. - Result
  100. * - Remote execution
  101. - * Run ``salt -v '*' pkg.install vim`` from the terminal
  102. - * Remotely installs Vim on the targeted minions
  103. * - Configuration management
  104. - * Write a YAML state file that checks whether Vim is installed
  105. * This state file is then applied to the targeted minions
  106. - * Ensures that Vim is always installed on the targeted minions
  107. * Salt analyzes the state file and determines what actions need to be
  108. taken to ensure the minion complies with the state declarations
  109. * If Vim is not installed, it automates the processes to install Vim on
  110. the targeted minions
  111. The state file that verifies Vim is installed might look like the following
  112. example:
  113. .. code-block:: yaml
  114. # File:/srv/salt/vim_install.sls
  115. install_vim_now:
  116. pkg.installed:
  117. - pkgs:
  118. - vim
  119. To apply this state to a minion, you would use the ``state.apply`` module, such
  120. as in the following example:
  121. .. code-block:: bash
  122. salt '*' state.apply vim_install
  123. This command applies the ``vim_install`` state to all minions.
  124. *Formulas* are collections of states that work in harmony to configure a minion
  125. or application. For example, one state might trigger another state.
  126. The Top file
  127. ------------
  128. It is not practical to manually run each state individually targeting specific
  129. minions each time. Some environments have hundreds of state files targeting
  130. thousands of minions.
  131. Salt offers two features to help with this scaling problem:
  132. * **The top.sls file** - Maps Salt states to their applicable minions.
  133. * **Highstate execution** - Runs all Salt states outlined in ``top.sls`` in a
  134. single execution.
  135. The top file maps which states should be applied to different minions in certain
  136. environments. The following is an example of a simple top file:
  137. .. code-block:: yaml
  138. # File: /srv/salt/top.sls
  139. base:
  140. '*':
  141. - all_server_setup
  142. '01webserver':
  143. - web_server_setup
  144. In this example, ``base`` refers to the Salt environment, which is the default.
  145. You can specify more than one environment as needed, such as prod, dev, QA, etc.
  146. Groups of minions are specified under the environment, and states are listed for
  147. each set of minions. This top file indicates that a state called
  148. ``all_server_setup`` should be applied to all minions ``'*'`` and the state
  149. called ``web_server_setup`` should be applied to the ``01webserver`` minion.
  150. To run the Salt command, you would use the state.highstate function:
  151. .. code-block:: bash
  152. salt \* state.highstate
  153. This command applies the top file to the targeted minions.
  154. Salt pillar
  155. -----------
  156. Salt’s pillar feature takes data defined on the Salt Master and distributes it
  157. to minions as needed. Pillar is primarily used to store secrets or other highly
  158. sensitive data, such as account credentials, cryptographic keys, or passwords.
  159. Pillar is also useful for storing non-secret data that you don't want to place
  160. directly in your state files, such as configuration data.
  161. Salt pillar brings data into the cluster from the opposite direction as grains.
  162. While grains are data generated from the minion, the pillar is data generated
  163. from the master.
  164. Pillars are organized similarly to states in a Pillar state tree, where
  165. ``top.sls`` acts to coordinate pillar data to environments and minions privy to
  166. the data. Information transferred using pillar has a dictionary generated for
  167. the targeted minion and encrypted with that minion’s key for secure data
  168. transfer. Pillar data is encrypted on a per-minion basis, which makes it useful
  169. for storing sensitive data specific to a particular minion.
  170. Beacons and reactors
  171. --------------------
  172. The beacon system is a monitoring tool that can listen for a variety of system
  173. processes on Salt Minions. Beacons can trigger reactors which can then help
  174. implement a change or troubleshoot an issue. For example, if a service’s
  175. response times out, the reactor system can restart the service.
  176. Beacons are used for a variety of purposes, including:
  177. * Automated reporting
  178. * Error log delivery
  179. * Microservice monitoring
  180. * User shell activity
  181. * Resource monitoring
  182. When coupled with reactors, beacons can create automated pre-written responses
  183. to infrastructure and application issues. Reactors expand Salt with automated
  184. responses using pre-written remediation states.
  185. Reactors can be applied in a variety of scenarios:
  186. * Infrastructure scaling
  187. * Notifying administrators
  188. * Restarting failed applications
  189. * Automatic rollback
  190. When both beacons and reactors are used together , you can create unique states
  191. customized to your specific needs.
  192. Salt runners and orchestration
  193. ------------------------------
  194. Salt runners are convenience applications executed with the ``salt-run``
  195. command. Salt runners work similarly to Salt execution modules. However, they
  196. execute on the Salt Master instead of the Salt Minions. A Salt runner can be a
  197. simple client call or a complex application.
  198. Salt provides the ability to orchestrate system administrative tasks throughout
  199. the enterprise. Orchestration makes it possible to coordinate the activities of
  200. multiple machines from a central place. It has the added advantage of being able
  201. to control the sequence of when certain configuration events occur.
  202. Orchestration states execute on the master using the state runner module.