Skip to content

Instantly share code, notes, and snippets.

@superseb
Last active August 15, 2018 11:59

Revisions

  1. superseb revised this gist Aug 15, 2018. 2 changed files with 2 additions and 40 deletions.
    2 changes: 2 additions & 0 deletions rancher2customnodecmd.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    # MOVED
    https://gist.github.com/superseb/c363247c879e96c982495daea1125276
    40 changes: 0 additions & 40 deletions rancher2customnodecmd.sh
    Original file line number Diff line number Diff line change
    @@ -1,40 +0,0 @@
    #!/bin/bash
    docker run -d -p 80:80 -p 443:443 --name rancher-server rancher/rancher:latest

    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`

    # Set server-url
    RANCHER_SERVER=https://your_rancher_server.com
    curl -s 'https://127.0.0.1/v3/settings/server-url' -H 'content-type: application/json' -H "Authorization: Bearer $APITOKEN" -X PUT --data-binary '{"name":"server-url","value":"'$RANCHER_SERVER'"}' --insecure > /dev/null

    # 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`

    # Create token
    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 > /dev/null

    # Set role flags
    ROLEFLAGS="--etcd --controlplane --worker"

    # Generate nodecommand
    AGENTCMD=`curl -s 'https://127.0.0.1/v3/clusterregistrationtoken?id="'$CLUSTERID'"' -H 'content-type: application/json' -H "Authorization: Bearer $APITOKEN" --insecure | jq -r '.data[].nodeCommand' | head -1`

    # Concat commands
    DOCKERRUNCMD="$AGENTCMD $ROLEFLAGS"

    # Echo command
    echo $DOCKERRUNCMD
  2. superseb revised this gist Jul 12, 2018. 1 changed file with 13 additions and 12 deletions.
    25 changes: 13 additions & 12 deletions rancher2customnodecmd.sh
    Original file line number Diff line number Diff line change
    @@ -15,25 +15,26 @@ APIRESPONSE=`curl -s 'https://127.0.0.1/v3/token' -H 'content-type: application/
    # Extract and store token
    APITOKEN=`echo $APIRESPONSE | jq -r .token`

    # Set server-url
    RANCHER_SERVER=https://your_rancher_server.com
    curl -s 'https://127.0.0.1/v3/settings/server-url' -H 'content-type: application/json' -H "Authorization: Bearer $APITOKEN" -X PUT --data-binary '{"name":"server-url","value":"'$RANCHER_SERVER'"}' --insecure > /dev/null

    # 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`
    # Create token
    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 > /dev/null

    # Set role flags
    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`
    # Generate nodecommand
    AGENTCMD=`curl -s 'https://127.0.0.1/v3/clusterregistrationtoken?id="'$CLUSTERID'"' -H 'content-type: application/json' -H "Authorization: Bearer $APITOKEN" --insecure | jq -r '.data[].nodeCommand' | head -1`

    # 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 }'`
    # Concat commands
    DOCKERRUNCMD="$AGENTCMD $ROLEFLAGS"

    # 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
    # Echo command
    echo $DOCKERRUNCMD
  3. superseb revised this gist Jul 12, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion rancher2customnodecmd.sh
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    #!/bin/bash
    docker run -d -p 80:80 -p 443:443 --name rancher-server rancher/server:preview
    docker run -d -p 80:80 -p 443:443 --name rancher-server rancher/rancher:latest

    while ! curl -k https://localhost/ping; do sleep 3; done

  4. superseb revised this gist Feb 8, 2018. 1 changed file with 1 addition and 3 deletions.
    4 changes: 1 addition & 3 deletions rancher2customnodecmd.sh
    Original file line number Diff line number Diff line change
    @@ -28,9 +28,7 @@ ROLEFLAGS="--etcd --controlplane --worker"
    RANCHERSERVER="https://rancher_server_address"

    # Generate token (clusterRegistrationToken)
    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
    # Extract the token and save it in $AGENTTOKEN
    AGENTTOKEN=`curl -s 'https://127.0.0.1/v3/clusterregistrationtokens?limit=-1' -H 'content-type: application/json' -H "Authorization: Bearer $APITOKEN" --insecure | jq -r .data[].token`
    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 }'`
  5. superseb revised this gist Feb 8, 2018. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions rancher2customnodecmd.sh
    Original file line number Diff line number Diff line change
    @@ -4,19 +4,19 @@ 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 'https://127.0.0.1/v3-public/authProviders/local?action=login' -H 'content-type: application/json' --data-binary '{"username":"admin","password":"admin"}' --insecure`
    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","name":""}' --insecure`
    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":{"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":"yournewcluster","id":""}' --insecure`
    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`

  6. superseb revised this gist Feb 8, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion rancher2customnodecmd.sh
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@ 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 'https://127.0.0.1/v3-public/localProviders/local?action=login' -H 'content-type: application/json' --data-binary '{"username":"admin","password":"admin"}' --insecure`
    LOGINRESPONSE=`curl 'https://127.0.0.1/v3-public/authProviders/local?action=login' -H 'content-type: application/json' --data-binary '{"username":"admin","password":"admin"}' --insecure`
    LOGINTOKEN=`echo $LOGINRESPONSE | jq -r .token`

    # Change password
  7. superseb revised this gist Feb 8, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion rancher2customnodecmd.sh
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@ 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 'https://127.0.0.1/v3-public/localProviders/local?action=login' -H 'content-type: application/json' -H 'accept: application/json' --data-binary '{"username":"admin","password":"admin"}' --insecure`
    LOGINRESPONSE=`curl '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
  8. superseb revised this gist Feb 8, 2018. 1 changed file with 21 additions and 15 deletions.
    36 changes: 21 additions & 15 deletions rancher2customnodecmd.sh
    Original file line number Diff line number Diff line change
    @@ -4,32 +4,38 @@ 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
    LOGINRESPONSE=`curl 'https://127.0.0.1/v3-public/localProviders/local?action=login' -H 'content-type: application/json' -H 'accept: application/json' --data-binary '{"username":"admin","password":"admin"}' --insecure`
    LOGINTOKEN=`echo $LOGINRESPONSE | jq -r .token`

    # 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
    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
    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`
    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","name":""}' --insecure`
    # Extract and store token
    APITOKEN=`echo $APIRESPONSE | 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`
    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":{"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":"yournewcluster","id":""}' --insecure`
    # Extract clusterid to use for generating the docker run command
    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 }'`
    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"

    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"
    # Generate token (clusterRegistrationToken)
    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
    # Extract the token and save it in $AGENTTOKEN
    AGENTTOKEN=`curl -s 'https://127.0.0.1/v3/clusterregistrationtokens?limit=-1' -H 'content-type: application/json' -H "Authorization: Bearer $APITOKEN" --insecure | jq -r .data[].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
  9. superseb revised this gist Feb 8, 2018. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions rancher2customnodecmd.sh
    Original file line number Diff line number Diff line change
    @@ -28,8 +28,8 @@ AGENTTOKEN=`curl 'https://127.0.0.1/v3/clusterregistrationtokens?limit=-1' -H 'c
    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"
    RANCHERSERVER="https://rancher_server_address"

    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"
    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"

    echo $COMMAND
    echo $AGENTCOMMAND
  10. superseb revised this gist Feb 8, 2018. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion rancher2customnodecmd.sh
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,4 @@
    #!/bin/bash
    docker rm -f rancher-server
    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
  11. superseb revised this gist Feb 8, 2018. 1 changed file with 9 additions and 7 deletions.
    16 changes: 9 additions & 7 deletions rancher2customnodecmd.sh
    Original file line number Diff line number Diff line change
    @@ -1,27 +1,29 @@
    #!/bin/bash
    docker rm -f rancher-server
    docker run -d -p 80:80 -p 443:443 --name rancher-server rancher/server:preview

    while ! curl -k https://localhost/ping; do sleep 0.1; done
    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 'Origin: https://127.0.0.1' -H 'Accept-Encoding: gzip, deflate, br' -H 'Accept-Language: en-US,en;q=0.9,nl;q=0.8' -H 'x-api-action-links: actionLinks' -H 'content-type: application/json' -H 'x-api-no-challenge: true' -H 'accept: application/json' -H 'Referer: https://127.0.0.1/login' -H 'Connection: keep-alive' -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
    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 'x-api-no-challenge: true' -H 'accept: application/json' -H 'x-api-csrf: 000050de82' --data-binary '{"currentPassword":"admin","newPassword":"a"}' --compressed --insecure
    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 'Origin: https://127.0.0.1' -H 'Accept-Encoding: gzip, deflate, br' -H 'Accept-Language: en-US,en;q=0.9,nl;q=0.8' -H 'x-api-action-links: actionLinks' -H 'content-type: application/json' -H 'x-api-no-challenge: true' -H 'accept: application/json' -H 'Referer: https://127.0.0.1/apikeys' -H 'Connection: keep-alive' -H 'x-api-csrf: 000050de82' --data-binary '{"type":"token","ttl":31536000000,"description":"automation","name":""}' --compressed --insecure`
    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 'Origin: https://127.0.0.1' -H 'Accept-Encoding: gzip, deflate, br' -H 'Accept-Language: en-US,en;q=0.9,nl;q=0.8' -H 'x-api-action-links: actionLinks' -H 'content-type: application/json' -H 'x-api-no-challenge: true' -H 'accept: application/json' -H "Authorization: Bearer $TOKEN" -H 'Connection: keep-alive' -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`
    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 'Origin: https://127.0.0.1' -H 'Accept-Encoding: gzip, deflate, br' -H 'Accept-Language: en-US,en;q=0.9,nl;q=0.8' -H 'x-api-action-links: actionLinks' -H 'content-type: application/json' -H 'x-api-no-challenge: true' -H 'accept: application/json' -H 'Referer: https://127.0.0.1/c/cluster-zr4bz/nodes/configure' -H "Authorization: Bearer $TOKEN" -H 'Connection: keep-alive' -H 'x-api-csrf: 000050de82' --data-binary '{"type":"clusterRegistrationToken","clusterId":"'$CLUSTERID'"}' --compressed --insecure
    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 'Accept-Encoding: gzip, deflate, br' -H 'Accept-Language: en-US,en;q=0.9,nl;q=0.8' -H 'x-api-action-links: actionLinks' -H 'content-type: application/json' -H 'x-api-no-challenge: true' -H 'accept: application/json' -H "Authorization: Bearer $TOKEN" -H 'Connection: keep-alive' -H 'x-api-csrf: 000050de82' --compressed --insecure | jq -r .data[].token`
    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`
  12. superseb created this gist Feb 8, 2018.
    34 changes: 34 additions & 0 deletions rancher2customnodecmd.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    #!/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 0.1; done

    # Login
    curl --cookie-jar ranchercookie 'https://127.0.0.1/v3-public/localProviders/local?action=login' -H 'Origin: https://127.0.0.1' -H 'Accept-Encoding: gzip, deflate, br' -H 'Accept-Language: en-US,en;q=0.9,nl;q=0.8' -H 'x-api-action-links: actionLinks' -H 'content-type: application/json' -H 'x-api-no-challenge: true' -H 'accept: application/json' -H 'Referer: https://127.0.0.1/login' -H 'Connection: keep-alive' -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 'x-api-no-challenge: true' -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 'Origin: https://127.0.0.1' -H 'Accept-Encoding: gzip, deflate, br' -H 'Accept-Language: en-US,en;q=0.9,nl;q=0.8' -H 'x-api-action-links: actionLinks' -H 'content-type: application/json' -H 'x-api-no-challenge: true' -H 'accept: application/json' -H 'Referer: https://127.0.0.1/apikeys' -H 'Connection: keep-alive' -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 'Origin: https://127.0.0.1' -H 'Accept-Encoding: gzip, deflate, br' -H 'Accept-Language: en-US,en;q=0.9,nl;q=0.8' -H 'x-api-action-links: actionLinks' -H 'content-type: application/json' -H 'x-api-no-challenge: true' -H 'accept: application/json' -H "Authorization: Bearer $TOKEN" -H 'Connection: keep-alive' -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 'Origin: https://127.0.0.1' -H 'Accept-Encoding: gzip, deflate, br' -H 'Accept-Language: en-US,en;q=0.9,nl;q=0.8' -H 'x-api-action-links: actionLinks' -H 'content-type: application/json' -H 'x-api-no-challenge: true' -H 'accept: application/json' -H 'Referer: https://127.0.0.1/c/cluster-zr4bz/nodes/configure' -H "Authorization: Bearer $TOKEN" -H 'Connection: keep-alive' -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 'Accept-Encoding: gzip, deflate, br' -H 'Accept-Language: en-US,en;q=0.9,nl;q=0.8' -H 'x-api-action-links: actionLinks' -H 'content-type: application/json' -H 'x-api-no-challenge: true' -H 'accept: application/json' -H "Authorization: Bearer $TOKEN" -H 'Connection: keep-alive' -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