简体   繁体   中英

How to get Rancher scripts code when add agent to nodes hosts?

Normally, get that code on master host's dashboard:

$ sudo docker run --rm --privileged -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/rancher:/var/lib/rancher rancher/agent:v1.2.2 http://192.168.0.100:8080/v1/scripts/5D8B3FD489C00C7F361A:2483142400000:WvMClyNFLXQnT9pLuii3D0sYA

If want to deploy multiple nodes automatic to other hosts, it's necessary to get this code from master:

5D8B3FD489C00C7F361A:2483142400000:WvMClyNFLXQnT9pLuii3D0sYA

Then every node just add agent with this code is good. Is it right?

But, how to get it by cli from master?

Rancher has API, which enables you to interact with it remotely. What you require is called registrationTokens . Now, how to access them.

First, set up API tokens in your Rancher. Go to API -> Keys -> Add Account API Key and create the keys. If you can't find the buttons, your URL would be 192.168.0.100:8080/env/1a5/api/keys .

Now you know the keys and from remote host you can do something like this:

curl -u "${RANCHER_ACCESS_KEY}:${RANCHER_SECRET_KEY}" \
-X GET \
'http://192.168.0.100:8080/v2-beta/projects/1a5/registrationtokens'

Your result will be a JSON with required data:

{
...
    "data": [
    {
        "id": "1c3",
        "type": "registrationToken",
        "links": {
            ...
        },
        "actions": {
            ...
        },
        ...
        "command": "sudo docker run --rm --privileged -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/rancher:/var/lib/rancher rancher/agent:v1.2.2 http://192.168.0.100:8080/v1/scripts/AAAAAAAAAAAAAAAAAAAA:0000000000000:ZZZZZZZZZZZZZZZZZZZZZZZZZZ",
        ...
    }],
...
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM