After Part I and Part II, you have a workable DC/OS cluster and a nginx service is running. In this chapter, let’s talk about how to use DC/OS CLI, which is a helpful tool.
Installation
The DC/OS CLI’s version need to be the same as the DC/OS cluster runs. With minidcos, I installed the 1.12.5 so CLI’s version needs to be 1.12 as well. Use the following commands to download the CLI binary.
1 |
> curl https://downloads.dcos.io/binaries/cli/linux/x86-64/dcos-1.12/dcos -o dcos |
Then setup it
1 2 3 4 5 6 |
> ./dcos cluster setup http://172.17.0.2 If your browser didn't open, please follow this link: http://172.17.0.2/login?redirect_uri=urn:ietf:wg:oauth:2.0:oob Enter token from the browser: |
The DC/OS page will be open and log into to get the token. When token is typed in, your CLI is already attached to the running cluster. It’s ready to use it.
Commands
DC/OS CLI provides a lot of useful commands. With it, you can do the same as the GUI does. Here are some examples.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
> ./dcos node HOSTNAME IP ID TYPE REGION ZONE 172.17.0.3 172.17.0.3 41f320ba-c2f6-44db-a454-d31621b1c57c-S1 agent None None 172.17.0.4 172.17.0.4 41f320ba-c2f6-44db-a454-d31621b1c57c-S0 agent None None master.mesos. 172.17.0.2 41f320ba-c2f6-44db-a454-d31621b1c57c master (leader) None None > ./dcos service NAME HOST ACTIVE TASKS CPU MEM DISK ID marathon 172.17.0.2 True 1 0.1 128.0 0.0 41f320ba-c2f6-44db-a454-d31621b1c57c-0001 metronome 172.17.0.2 True 0 0.0 0.0 0.0 41f320ba-c2f6-44db-a454-d31621b1c57c-0000 > ./dcos task NAME HOST USER STATE ID MESOS ID REGION ZONE nginx-service 172.17.0.4 root R nginx-service.97a7d02f-5a21-11eb-8525-70b3d5800002 41f320ba-c2f6-44db-a454-d31621b1c57c-S0 --- --- > ./dcos task log nginx-service /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/ /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh 10-listen-on-ipv6-by-default.sh: Getting the checksum of /etc/nginx/conf.d/default.conf 10-listen-on-ipv6-by-default.sh: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh /docker-entrypoint.sh: Configuration complete; ready for start up > dcos marathon app list ID MEM CPUS TASKS HEALTH DEPLOYMENT WAITING CONTAINER CMD /nginx-service 128 0.1 1/1 N/A --- False DOCKER N/A |
For more details, please use argument “-h” to check.
Let’s use CLI to run a service. I extracted the Nginx service configuration into the JSON file and the id was changed to “/nginx-service2”.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
{ "id": "/nginx-service2", "backoffFactor": 1.15, "backoffSeconds": 1, "container": { "portMappings": [ { "containerPort": 80, "hostPort": 0, "labels": { "VIP_0": "/nginx-service:80" }, "protocol": "tcp", "servicePort": 10000, "name": "nginx-service" } ], "type": "DOCKER", "volumes": [], "docker": { "image": "nginx:stable", "forcePullImage": false, "privileged": false, "parameters": [] } }, "cpus": 0.1, "disk": 0, "instances": 1, "maxLaunchDelaySeconds": 3600, "mem": 128, "gpus": 0, "networks": [ { "mode": "container/bridge" } ], "requirePorts": false, "upgradeStrategy": { "maximumOverCapacity": 1, "minimumHealthCapacity": 1 }, "killSelection": "YOUNGEST_FIRST", "unreachableStrategy": { "inactiveAfterSeconds": 0, "expungeAfterSeconds": 0 }, "healthChecks": [], "fetch": [], "constraints": [] } |
Then use “dcos marathon app add” to create a new service “/nginx-service2”
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
> dcos marathon app add nginx.json Created deployment 149eaeee-2c69-4102-99ca-a7415cd67c55 > dcos marathon app list ID MEM CPUS TASKS HEALTH DEPLOYMENT WAITING CONTAINER CMD /nginx-service 128 0.1 1/1 N/A --- False DOCKER N/A /nginx-service2 128 0.1 1/1 N/A --- False DOCKER N/A > dcos marathon app show /nginx-service2 { "backoffFactor": 1.15, "backoffSeconds": 1, "container": { "docker": { "forcePullImage": false, "image": "nginx:stable", "parameters": [], "privileged": false }, "portMappings": [ { "containerPort": 80, "hostPort": 0, "labels": { "VIP_0": "/nginx-service:80" }, "name": "nginx-service", "protocol": "tcp", "servicePort": 10000 } ], "type": "DOCKER", "volumes": [] }, "cpus": 0.1, "deployments": [], "disk": 0, "executor": "", "gpus": 0, "id": "/nginx-service2", "instances": 1, "killSelection": "YOUNGEST_FIRST", "labels": {}, "maxLaunchDelaySeconds": 3600, "mem": 128, "networks": [ { "mode": "container/bridge" } ], "requirePorts": false, "tasks": [ { "appId": "/nginx-service2", "healthCheckResults": [], "host": "172.17.0.3", "id": "nginx-service2.d327bd30-5a37-11eb-8525-70b3d5800002", "ipAddresses": [ { "ipAddress": "172.18.0.2", "protocol": "IPv4" } ], "localVolumes": [], "ports": [ 29349 ], "servicePorts": [], "slaveId": "41f320ba-c2f6-44db-a454-d31621b1c57c-S1", "stagedAt": "2021-01-19T09:22:17.727Z", "startedAt": "2021-01-19T09:22:33.342Z", "state": "TASK_RUNNING", "version": "2021-01-19T09:22:17.599Z" } ], "tasksHealthy": 0, "tasksRunning": 1, "tasksStaged": 0, "tasksUnhealthy": 0, "unreachableStrategy": { "expungeAfterSeconds": 0, "inactiveAfterSeconds": 0 }, "upgradeStrategy": { "maximumOverCapacity": 1, "minimumHealthCapacity": 1 }, "version": "2021-01-19T09:22:17.599Z", "versionInfo": { "lastConfigChangeAt": "2021-01-19T09:22:17.599Z", "lastScalingAt": "2021-01-19T09:22:17.599Z" } } |
From GUI, you can see the similar status.
All right. Now you know how to install CLI and some basic commands to check the status of cluster/node/services.