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 | |
curl --cookie-jar ranchercookie 'https://127.0.0.1/v3-public/localProviders/local?action=login' -H 'content-type: application/json' -H 'accept: application/json' -H 'x-api-csrf: 000050de82' -H 'Cookie: CSRF=000050de82' --data-binary '{"username":"admin","password":"admin","description":"UI Session","responseType":"cookie","ttl":57600000,"labels":{"ui-session":"true"}}' --compressed --insecure | |
# Change password | |
curl -b ranchercookie 'https://127.0.0.1/v3/users?action=changepassword' -H 'content-type: application/json' -H 'accept: application/json' -H 'x-api-csrf: 000050de82' --data-binary '{"currentPassword":"admin","newPassword":"a"}' --compressed --insecure | |
# Create API key | |
RESPONSE=`curl -b ranchercookie 'https://127.0.0.1/v3/token' -H 'content-type: application/json' -H 'x-api-no-challenge: true' -H 'accept: application/json' -H 'x-api-csrf: 000050de82' --data-binary '{"type":"token","ttl":31536000000,"description":"automation","name":""}' --compressed --insecure` | |
# Extract token from API key response | |
TOKEN=`echo $RESPONSE | jq -r .token` | |
# Create cluster | |
CLUSTERRESPONSE=`curl 'https://127.0.0.1/v3/cluster' -H 'content-type: application/json' -H 'accept: application/json' -H "Authorization: Bearer $TOKEN" -H 'x-api-csrf: 000050de82' --data-binary '{"type":"cluster","nodes":[],"rancherKubernetesEngineConfig":{"type":"rancherKubernetesEngineConfig","hosts":[],"network":{"options":[],"plugin":"flannel"},"ignoreDockerVersion":true,"services":{"kubeApi":{"serviceClusterIpRange":"10.233.0.0/18","podSecurityPolicy":false,"extraArgs":{"v":"4"}},"kubeController":{"clusterCidr":"10.233.64.0/18","serviceClusterIpRange":"10.233.0.0/18"},"kubelet":{"clusterDnsServer":"10.233.0.3","clusterDomain":"cluster.local","infraContainerImage":"gcr.io/google_containers/pause-amd64:3.0"}},"authentication":{"options":[],"strategy":"x509"}},"googleKubernetesEngineConfig":null,"name":"testcluster2","id":""}' --compressed --insecure` | |
CLUSTERID=`echo $CLUSTERRESPONSE | jq -r .id` | |
# Create and Get agent token for joining cluster | |
curl 'https://127.0.0.1/v3/clusterregistrationtoken' -H 'content-type: application/json' -H 'accept: application/json' -H "Authorization: Bearer $TOKEN" -H 'x-api-csrf: 000050de82' --data-binary '{"type":"clusterRegistrationToken","clusterId":"'$CLUSTERID'"}' --compressed --insecure | |
AGENTTOKEN=`curl 'https://127.0.0.1/v3/clusterregistrationtokens?limit=-1' -H 'content-type: application/json' -H 'accept: application/json' -H "Authorization: Bearer $TOKEN" -H 'x-api-csrf: 000050de82' --compressed --insecure | jq -r .data[].token` | |
# Generate docker run | |
AGENTIMAGE=`curl -s -k -H "Authorization: Bearer $TOKEN" https://127.0.0.1/v3/settings/agent-image | jq -r .value` | |
CACHECKSUM=`curl -s -k -H "Authorization: Bearer $TOKEN" https://127.0.0.1/v3/settings/cacerts | jq -r .value | sha256sum | awk '{ print $1 }'` | |
ROLEFLAGS="--etcd --controlplane --worker" | |
RANCHERSERVER="https://207.154.250.150" | |
COMMAND="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" | |
echo $COMMAND |
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