- CLI tools are Composable using pipes (great old school example http://www.youtube.com/watch?v=tc4ROCJYbm0&t=5m32s)
- Great for automation and batch processing
- Fewer mouse clicks. Can go futher using only keyboard
- Avoid cluky UIs especially over poor connections
- I'm insulated from UI changes
- Easier to debug as they are often more verbose than the UI
The DC/OS CLI (https://dcos.io/docs/1.7/usage/cli/)
- The CLI for your data center
- Open source,implementation in python https://github.com/dcos/dcos-cli
- Extensible - you can write your own subcommands (e.g. https://github.com/mesosphere/dcos-helloworld )
- Installable on Linux, Mac and Windows clients (https://dcos.io/docs/1.7/usage/cli/install/)
- Starting 0.4.5 Cli team started shipping binaries (https://github.com/dcos/dcos-cli/releases)
- Has subcommands for doing basic operations on your cluster
- Installing some packages adds more functionality using new subcommands
- Very userful Help docs, can be invoked using
--help
on top or subcommand level
Hidden gems
- Default config file lives in
~/.dcos/dcos.toml
.%USERPROFILE%\.dcos\dcos.toml
on Windows - Code for subcommands lives in
~/.dcos/subcommands
DCOS_CONFIG
environment variable can be used to override the default config file.- If you want to debug a CLI error use
dcos --debug --log-level=debug
to get very verbose output
- jq for pretty printing and processing JSON https://stedolan.github.io/jq/
- HTTPie human friendly
curl
alternative https://github.com/jkbrzt/httpie
curl --header "Authorization:curl --header token=$(dcos config show core.dcos_acs_token)" http://52.21.51.123/mesos/master/state-summary
curl --header "Authorization:curl --header token=$(dcos config show core.dcos_acs_token)" http://52.21.51.123/marathon/v2/leader
curl -skSL -H "Authorization: token=$(dcos config show core.dcos_acs_token)" $(dcos config show core.dcos_url)/mesos/master/slaves | grep slave_public | wc
-
Deploy and update Marathon apps
dcos marathon app add tomcat.json
dcos marathon app update /tomcat < tomcat.json
-
Deploy app on MoM instance instead of root marathon
dcos config set marathon.url $(dcos config show core.dcos_url)/service/marathon-user
dcos marathon app add nginx.json
dcos package install cassandra
dcos task
dcos task ls cassandra
dcos task log cassandra stderr
Doing fancy stuff using dcos node ssh
(https://dcos.io/docs/1.7/administration/sshcluster/)
- SSH into nodes for debugging
dcos node ssh --leader --master-proxy
- Find out which node a service is runnig on
dcos task --json | jq --raw-output '.[] | select(.name == "tomcat") | .slave_id'
dcos node ssh --option StrictHostKeyChecking=no --option LogLevel=quiet --master-proxy --mesos-id=$(dcos task --json | jq --raw-output '.[] | select(.name == "tomcat") | .slave_id') "curl -s ifconfig.co" 2>/dev/null
- Find out public IPs of all Public agents
dcos node --json | jq --raw-output '.[] | select(.reserved_resources.slave_public != null) | .id'
for id in $(dcos node --json | jq --raw-output '.[] | select(.reserved_resources.slave_public != null) | .id'); do dcos node ssh --option StrictHostKeyChecking=no --option LogLevel=quiet --master-proxy --mesos-id=$id "curl -s ifconfig.co" ; done
- First approach
cp ~/.dcos/dcos.toml ~/.dcos/alpha.toml
DCOS_CONFIG=~/.dcos/alpha.toml dcos config set core.dcos_url http://52.38.178.200
alias alpha='DCOS_CONFIG=~/.dcos/alpha.toml dcos'
alpha auth login
alpha marathon app list
- Better approach In .bashrc put the following snippet :
dcos ()
{
# find current working directory
local cwd=$(pwd)
# path for config file in current directory
local config_file="${cwd}/dcos.toml"
# find the location for dcos CLI binary
# \which makes sure we use unaliased which
local dcos_binary="$(\which dcos)"
#check if config file exists in current directory
if [ -f "$config_file" ]
then
# use config file in current directory
DCOS_CONFIG="${config_file}" "$dcos_binary" "$@"
else
# use default config file
"$dcos_binary" "$@"
fi
}
alias dcos='dcos'
mkdir -p clusters/{alpha,beta,gamma}
for dir in clusters/{alpha,beta,gamma}; do cp ~/.dcos/dcos.toml $dir; done
cd clusters/alpha
dcos config set core.dcos_url http://52.38.178.200
dcos auth login