项目作者: seatgeek

项目描述 :
Useful tools for working with @hashicorp Nomad at scale
高级语言: Go
项目地址: git://github.com/seatgeek/nomad-helper.git
创建时间: 2017-06-23T17:17:51Z
项目社区:https://github.com/seatgeek/nomad-helper

开源协议:BSD 3-Clause "New" or "Revised" License

下载


nomad-helper

nomad-helper is a tool meant to enable teams to quickly onboard themselves with nomad, by exposing scaling functionality in a simple to use and share yaml format.

Running

The project has build artifacts for linux, darwin and windows in the GitHub releases tab.

A docker container is also provided at seatgeek/nomad-helper

Requirements

  • Go 1.13.1

Building

Recommend environment variables

  1. export GO111MODULE=on
  2. export GOPROXY=https://proxy.golang.org

To build a binary, run the following

  1. # get this repo
  2. go get github.com/seatgeek/nomad-helper
  3. # go to the repo directory
  4. cd $GOPATH/src/github.com/seatgeek/nomad-helper
  5. # install the `nomad-helper` binary into $GOPATH/bin
  6. make install
  7. # install the `nomad-helper` binary ./build/nomad-helper-${GOOS}-${GOARCH}
  8. make install

This will create a nomad-helper binary in your $GOPATH/bin directory.

Configuration

Any NOMAD_* env that the native nomad CLI tool supports are supported by this tool.

The most basic requirement is export NOMAD_ADDR=http://<ip>:4646.

Installation

Binary

Source

  • make sure Go 1.10+ is installed (brew install go)
  • clone the repo into $GOPATH/src/github.com/seatgeek/nomad-helper
  • make install
  • go install / go build / make build

Usage

The nomad-helper binary has several helper subcommands.

attach

Automatically handle discovery of allocation host IP by CLI filters or interactive shell and ssh + attach to the running container.

The tool assume you can SSH to the instance and your ~/.ssh/config is configured with the right configuration for doing so.

  1. NAME:
  2. nomad-helper attach - attach to a specific allocation
  3. USAGE:
  4. nomad-helper attach [command options] [arguments...]
  5. OPTIONS:
  6. --job value List allocations for the job and attach to the selected allocation
  7. --alloc value Partial UUID or the full 36 char UUID to attach to
  8. --task value Task name to auto-select if the allocation has multiple tasks in the allocation group
  9. --host Connect to the host directly instead of attaching to a container
  10. --command value Command to run when attaching to the container (default: "bash")

tail

Automatically handle discovery of allocation and tail both stdout and stderr at the same time

  1. NAME:
  2. nomad-helper tail - tail stdout/stderr from nomad alloc
  3. USAGE:
  4. nomad-helper tail [command options] [arguments...]
  5. OPTIONS:
  6. --job value (optional) list allocations for the job and attach to the selected allocation
  7. --alloc value (optional) partial UUID or the full 36 char UUID to attach to
  8. --task value (optional) the task name to auto-select if the allocation has multiple tasks in the allocation group
  9. --stderr (optional, default: true) tail stderr from nomad
  10. --stdout (optional, default: true) tail stdout from nomad

namespace

namespace specific commands

gc

  1. NAME:
  2. nomad-helper namespace gc - Cleans up empty namespaces
  3. USAGE:
  4. nomad-helper namespace gc [command options] [arguments...]
  5. OPTIONS:
  6. --dry Dry run, just print actions
  7. --ignore-job value Ignore a job ID when marking a namespace as empty. Can be provided multiple times.

If jobs are ignored when removing a namespace, those jobs will be deleted prior to the namespace being removed. A Nomad GC call will be run after any ignored jobs are removed to ensure that the removed state is synced to the cluster.

node

node specific commands that act on all Nomad clients that match the filters provided, rather than a single node

  1. NAME:
  2. nomad-helper node - node specific commands that act on all Nomad clients that match the filters provided, rather than a single node
  3. USAGE:
  4. nomad-helper node command [command options] [arguments...]
  5. COMMANDS:
  6. drain The node drain command is used to toggle drain mode on a given node. Drain mode prevents any new tasks from being allocated to the node, and begins migrating all existing allocations away
  7. eligibility, eligible The eligibility command is used to toggle scheduling eligibility for a given node. By default node's are eligible for scheduling meaning they can receive placements and run new allocations. Node's that have their scheduling eligibility disabled are ineligible for new placements.
  8. OPTIONS:
  9. --filter-prefix ef30d57c Filter nodes by their ID with prefix matching ef30d57c
  10. --filter-class batch-jobs Filter nodes by their node class batch-jobs
  11. --filter-version 0.8.4 Filter nodes by their Nomad version 0.8.4
  12. --filter-eligibility Filter nodes by their scheduling eligibility
  13. --percent Filter only specific percent of nodes
  14. --filter-meta 'aws.instance.availability-zone=us-east-1e' Filter nodes by their meta key/value like 'aws.instance.availability-zone=us-east-1e'. Can be provided multiple times.
  15. --filter-attribute 'driver.docker.version=17.09.0-ce' Filter nodes by their attribute key/value like 'driver.docker.version=17.09.0-ce'. Can be provided multiple times.
  16. --noop Only output nodes that would be drained, don't do any modifications
  17. --help, -h show help

Filter examples

  • nomad-helper node <command> <args>
  • nomad-helper node --noop --filter-meta 'aws.instance.availability-zone=us-east-1e' --filter-attribute 'driver.docker.version=17.09.0-ce' <command> <args>

drain

Filtering options can be found in the main node command help above

  1. USAGE:
  2. nomad-helper node [filter options] drain [command options] [arguments...]
  3. OPTIONS:
  4. --enable Enable node drain mode
  5. --disable Disable node drain mode
  6. --deadline value Set the deadline by which all allocations must be moved off the node. Remaining allocations after the deadline are force removed from the node. Defaults to 1 hour (default: 1h0m0s)
  7. --no-deadline No deadline allows the allocations to drain off the node without being force stopped after a certain deadline
  8. --monitor Enter monitor mode directly without modifying the drain status
  9. --force Force remove allocations off the node immediately
  10. --detach Return immediately instead of entering monitor mode
  11. --ignore-system Ignore system allows the drain to complete without stopping system job allocations. By default system jobs are stopped last.
  12. --keep-ineligible Keep ineligible will maintain the node's scheduling ineligibility even if the drain is being disabled. This is useful when an existing drain is being cancelled but additional scheduling on the node is not desired.
  13. --with-benefits Instead of flipping the regular drain flag it will make instance ineligible and will add a desired constraint to the task groups found on the node
  14. --constraint
  15. --operand
  16. --value
  17. --wait-for-pending will wait for all the moved jobs to reach running state

Examples

  • nomad-helper node drain --enable
  • nomad-helper node --filter-class wrecker --filter-meta 'aws.ami-version=2.0.0-alpha14' --filter-meta 'aws.instance.availability-zone=us-east-1e' drain --noop --enable
  • node --filter-meta "aws.ami-version=1.9.6" drain --enable --with-benefits --constraint meta.aws.ami-version --operand '=' --value 1.9.8 --wait-for-pending

eligibility

Filtering options can be found in the main node command help above

  1. NAME:
  2. nomad-helper node eligibility - The eligibility command is used to toggle scheduling eligibility for a given node. By default node's are eligible for scheduling meaning they can receive placements and run new allocations. Node's that have their scheduling eligibility disabled are ineligible for new placements.
  3. USAGE:
  4. nomad-helper node [filter options] eligibility [command options] [arguments...]
  5. OPTIONS:
  6. --enable Enable scheduling eligibility
  7. --disable Disable scheduling eligibility

Examples

  • nomad-helper node eligibility --enable
  • nomad-helper node --filter-class wrecker --filter-meta 'aws.ami-version=2.0.0-alpha14' --filter-meta 'aws.instance.availability-zone=us-east-1e' eligibility --enable

Breakdown

  1. NAME:
  2. nomad-helper node breakdown - Break down (count) how many Nomad clients that match a list of key properties
  3. USAGE:
  4. nomad-helper node [filters...] breakdown [command options] [keys...]
  5. DESCRIPTION:
  6. ** Arguments **
  7. * attribute.key will look up key in the "Attributes" Nomad client property
  8. * hostname is an alias for attribute.unique.hostname
  9. * ip / address / ip-address is alias for attribute.unique.network.ip-address
  10. * meta.key will look up key in the "Meta" Nomad client configuration
  11. * class / nodeclass for the Nomad client "NodeClass" property
  12. * id for the Nomad client "ID" property
  13. * datacenter / dc for the Nomad client "Datacenter" property
  14. * drain for the Nomad client "Drain" property
  15. * status for the Nomad client "Status" property
  16. * eligibility / schedulingeligibility for the Nomad client "SchedulingEligibility" property
  17. ** Filters **
  18. --filter-prefix ef30d57c Filter nodes by their ID with prefix matching ef30d57c
  19. --filter-class batch-jobs Filter nodes by their node class batch-jobs
  20. --filter-version 0.8.4 Filter nodes by their Nomad version 0.8.4
  21. --filter-eligibility eligible/ineligible Filter nodes by their eligibility status eligible/ineligible
  22. --filter-meta 'aws.instance.availability-zone=us-east-1e' Filter nodes by their meta key/value like 'aws.instance.availability-zone=us-east-1e'. Flag can be repeated.
  23. --filter-attribute 'driver.docker.version=17.09.0-ce' Filter nodes by their attribute key/value like 'driver.docker.version=17.09.0-ce'. Flag can be repeated.
  24. ** Examples **
  25. * nomad-helper node breakdown class status
  26. * nomad-helper node breakdown attribute.nomad.version attribute.driver.docker
  27. * nomad-helper node breakdown meta.aws.instance.region attribute.nomad.version
  28. OPTIONS:
  29. --output-format value Either "table", "json" or "json-pretty" (default: "table")

List

  1. NAME:
  2. nomad-helper node list - Output list of key properties for a Nomad client
  3. USAGE:
  4. nomad-helper node [filters...] list [command options] [keys...]
  5. DESCRIPTION:
  6. ** Arguments **
  7. * attribute.key will look up key in the "Attributes" Nomad client property
  8. * hostname is an alias for attribute.unique.hostname
  9. * ip / address / ip-address is alias for attribute.unique.network.ip-address
  10. * meta.key will look up key in the "Meta" Nomad client configuration
  11. * class / nodeclass for the Nomad client "NodeClass" property
  12. * id for the Nomad client "ID" property
  13. * datacenter / dc for the Nomad client "Datacenter" property
  14. * drain for the Nomad client "Drain" property
  15. * status for the Nomad client "Status" property
  16. * eligibility / schedulingeligibility for the Nomad client "SchedulingEligibility" property
  17. ** Filters **
  18. --filter-prefix ef30d57c Filter nodes by their ID with prefix matching ef30d57c
  19. --filter-class batch-jobs Filter nodes by their node class batch-jobs
  20. --filter-version 0.8.4 Filter nodes by their Nomad version 0.8.4
  21. --filter-eligibility eligible/ineligible Filter nodes by their eligibility status eligible/ineligible
  22. --filter-meta 'aws.instance.availability-zone=us-east-1e' Filter nodes by their meta key/value like 'aws.instance.availability-zone=us-east-1e'. Flag can be repeated.
  23. --filter-attribute 'driver.docker.version=17.09.0-ce' Filter nodes by their attribute key/value like 'driver.docker.version=17.09.0-ce'. Flag can be repeated.
  24. ** Examples **
  25. * nomad-helper node list class status
  26. * nomad-helper node list attribute.nomad.version attribute.driver.docker
  27. * nomad-helper node list meta.aws.instance.region attribute.nomad.version
  28. OPTIONS:
  29. --output-format table, json or json-pretty Either table, json or json-pretty (default: "table")

Discover

  1. NAME:
  2. nomad-helper node discover - Output the Nomad client Meta and Attribute fields present in your cluster
  3. USAGE:
  4. nomad-helper node [filters...] discover [command options]
  5. OPTIONS:
  6. --output-format value Either "table", "json" or "json-pretty" (default: "table")

job

job specific commands

  1. NAME:
  2. nomad-helper job - job specific commands with a twist
  3. USAGE:
  4. nomad-helper job stop [command options] [arguments...]
  5. COMMANDS:
  6. stop Stop will stop the job with the ability to purge the job from the nomad cluster
  7. move Move will add/append a constraint to the job that will resolve to moving the job
  8. hunt Hunt will look for the jobs with discrepancy in job version between allocations
  9. OPTIONS:
  10. --help, -h show help

stop

  1. USAGE:
  2. nomad-helper job stop [job_name] [command options]
  3. OPTIONS:
  4. --as-prefix Filter jobs by their name with prefix matching api-
  5. --dry Only output jobs that would be stopped, don't do any modifications

Examples

  • nomad-helper job stop api
  • nomad-helper job stop api --as-prefix
  • nomad-helper job stop api --as-prefix --dry

move

  1. USAGE:
  2. nomad-helper job stop [job_name] [command options]
  3. OPTIONS:
  4. --as-prefix Filter jobs by their name with prefix matching api-
  5. --constraint Constraint attribute
  6. --operand Constraint operator
  7. --value Constraint value
  8. --dry Only output jobs that would be stopped, don't do any modifications

Examples

  • job move api --constraint meta.aws.ami-version --operand = --value 1.9.1 --exclude core
  • job move api --as-prefix --constraint meta.aws.ami-version --operand = --value 1.9.1 --exclude core

hunt

  1. USAGE:
  2. nomad-helper job hunt

Examples

  • job hunt

scale

  1. NAME:
  2. nomad-helper scale - Import / Export job -> group -> count values
  3. USAGE:
  4. nomad-helper scale command [command options] [arguments...]
  5. COMMANDS:
  6. export Export nomad job scale config to a local file from Nomad cluster
  7. import Import nomad job scale config from a local file to Nomad cluster
  8. OPTIONS:
  9. --help, -h show help

export

nomad-helper scale export production.yml will read the Nomad cluster job + group + count values and write them to a local production.yml file.

  1. NAME:
  2. nomad-helper scale export - Export nomad job scale config to a local file from Nomad cluster
  3. USAGE:
  4. nomad-helper scale export [arguments...]

import

nomad-helper scale import production.yml will update the Nomad cluster job + group + count values according to the values in a local production.yaml file.

  1. NAME:
  2. nomad-helper scale import - Import nomad job scale config from a local file to Nomad cluster
  3. USAGE:
  4. nomad-helper scale import [arguments...]

Example Scale config

  1. info:
  2. exported_at: Thu, 29 Jun 2017 13:11:19 +0000
  3. exported_by: jippi
  4. nomad_addr: http://nomad.service.consul:4646
  5. jobs:
  6. nginx:
  7. server: 10
  8. api-es:
  9. api-es-1: 1
  10. api-es-2: 1
  11. api-es-3: 1

Server

  1. NAME:
  2. nomad-helper server - Run a webserver exposing various endpoints
  3. USAGE:
  4. nomad-helper server [command options] [arguments...]
  5. DESCRIPTION:
  6. ** Arguments **
  7. * attribute.key will look up key in the "Attributes" Nomad client property
  8. * class / nodeclass for the Nomad client "NodeClass" property
  9. * datacenter / dc for the Nomad client "Datacenter" property
  10. * drain for the Nomad client "Drain" property
  11. * eligibility / schedulingeligibility for the Nomad client "SchedulingEligibility" property
  12. * hostname is an alias for attribute.unique.hostname
  13. * id for the Nomad client "ID" property
  14. * ip / address / ip-address is alias for attribute.unique.network.ip-address
  15. * meta.key will look up key in the "Meta" Nomad client configuration
  16. * name for the Nomad client "Name" property
  17. * status for the Nomad client "Status" property
  18. ** Filters **
  19. Filters are always passed as HTTP query arguments, order doesn't matter
  20. /?filter-attribute=driver.docker.version=17.09.0-ce Filter nodes by their attribute key/value like 'driver.docker.version=17.09.0-ce'.
  21. /?filter-class=batch-jobs Filter nodes by their node class batch-jobs
  22. /?filter-eligibility=eligible/ineligible Filter nodes by their eligibility status eligible/ineligible
  23. /?filter-meta=aws.instance.availability-zone=us-east-1e Filter nodes by their meta key/value like 'aws.instance.availability-zone=us-east-1e'.
  24. /?filter-prefix=ef30d57c Filter nodes by their ID with prefix matching ef30d57c
  25. /?filter-version=0.8.4 Filter nodes by their Nomad version 0.8.4
  26. ** Examples **
  27. Fields are always passed as HTTP path, and processed in order
  28. * /help
  29. * /help/node/breakdown
  30. * /help/node/list
  31. * /help/node/discover
  32. * /help/[command]/[subcommand]
  33. * /node/[breakdown|list]/class/status
  34. * /node/[breakdown|list]/meta.aws.instance.region/attribute.nomad.version
  35. * /node/[breakdown|list]/attribute.nomad.version/attribute.driver.docker
  36. OPTIONS:
  37. --listen value (default: "0.0.0.0:8000") [$LISTEN]

reevaluate-all

  1. NAME:
  2. nomad-helper reevaluate-all - Force re-evaluate all jobs
  3. USAGE:
  4. nomad-helper reevaluate-all [arguments...]

gc

  1. NAME:
  2. nomad-helper gc - Force a cluster GC
  3. USAGE:
  4. nomad-helper gc [arguments...]