Last active
August 15, 2018 11:59
-
-
Save superseb/29af10c2de2a5e75ef816292ef3ae426 to your computer and use it in GitHub Desktop.
MOVED - Add custom node to Rancher 2.0 -> https://gist.github.com/superseb/c363247c879e96c982495daea1125276
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
docker run -d -p 80:80 -p 443:443 --name rancher-server rancher/server:preview | |
while ! curl -k https://localhost/ping; do sleep 3; done | |
# Login | |
LOGINRESPONSE=`curl -s 'https://127.0.0.1/v3-public/localProviders/local?action=login' -H 'content-type: application/json' --data-binary '{"username":"admin","password":"admin"}' --insecure` | |
LOGINTOKEN=`echo $LOGINRESPONSE | jq -r .token` | |
# Change password | |
curl -s 'https://127.0.0.1/v3/users?action=changepassword' -H 'content-type: application/json' -H "Authorization: Bearer $LOGINTOKEN" --data-binary '{"currentPassword":"admin","newPassword":"thisisyournewpassword"}' --insecure | |
# Create API key | |
APIRESPONSE=`curl -s 'https://127.0.0.1/v3/token' -H 'content-type: application/json' -H "Authorization: Bearer $LOGINTOKEN" --data-binary '{"type":"token","description":"automation"}' --insecure` | |
# Extract and store token | |
APITOKEN=`echo $APIRESPONSE | jq -r .token` | |
# Create cluster | |
CLUSTERRESPONSE=`curl -s 'https://127.0.0.1/v3/cluster' -H 'content-type: application/json' -H "Authorization: Bearer $APITOKEN" --data-binary '{"type":"cluster","nodes":[],"rancherKubernetesEngineConfig":{"ignoreDockerVersion":true},"name":"yournewcluster"}' --insecure` | |
# Extract clusterid to use for generating the docker run command | |
CLUSTERID=`echo $CLUSTERRESPONSE | jq -r .id` | |
# Generate docker run | |
AGENTIMAGE=`curl -s -H "Authorization: Bearer $APITOKEN" https://127.0.0.1/v3/settings/agent-image --insecure | jq -r .value` | |
ROLEFLAGS="--etcd --controlplane --worker" | |
RANCHERSERVER="https://rancher_server_address" | |
# Generate token (clusterRegistrationToken) | |
AGENTTOKEN=`curl -s 'https://127.0.0.1/v3/clusterregistrationtoken' -H 'content-type: application/json' -H "Authorization: Bearer $APITOKEN" --data-binary '{"type":"clusterRegistrationToken","clusterId":"'$CLUSTERID'"}' --insecure | jq -r .token` | |
# Retrieve CA certificate and generate checksum | |
CACHECKSUM=`curl -s -H "Authorization: Bearer $APITOKEN" https://127.0.0.1/v3/settings/cacerts --insecure | jq -r .value | sha256sum | awk '{ print $1 }'` | |
# Assemble the docker run command | |
AGENTCOMMAND="docker run -d --restart=unless-stopped -v /var/run/docker.sock:/var/run/docker.sock --net=host $AGENTIMAGE $ROLEFLAGS --server $RANCHERSERVER --token $AGENTTOKEN --ca-checksum $CACHECKSUM" | |
# Show the command | |
echo $AGENTCOMMAND |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
you saved my time, thanks!
https://github.com/insekticid/docker-terraform-hcloud-example/tree/rancher2-deploy
Sometimes token missing, so I made small change
https://github.com/insekticid/docker-terraform-hcloud-example/blob/905709dd23cdca89ad9b9c95029da5db047df22b/terraform/scripts/rancher_change_password.sh#L9