Skip to content

Instantly share code, notes, and snippets.

@jdbohrman
Last active January 11, 2025 23:24
Show Gist options
  • Select an option

  • Save jdbohrman/714bb13d8b8404f647174d9132f5f320 to your computer and use it in GitHub Desktop.

Select an option

Save jdbohrman/714bb13d8b8404f647174d9132f5f320 to your computer and use it in GitHub Desktop.

Revisions

  1. jdbohrman renamed this gist Jan 16, 2020. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. jdbohrman revised this gist Jan 14, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion call-rancher.yaml
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    #!/bin/bash -x
    export curl
    export jq
    export RANCHER_IP=# CHANGE ME
    export RANCHER_IP=34.70.139.14
    export CLUSTER_NAME=test-cluster-new
    export OUTPUT_DIR=/var/lib/rancher/k3s/server/manifests

  3. jdbohrman revised this gist Jan 14, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion call-rancher.yaml
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    #!/bin/bash -x
    export curl
    export jq
    export RANCHER_IP=34.70.139.14
    export RANCHER_IP=# CHANGE ME
    export CLUSTER_NAME=test-cluster-new
    export OUTPUT_DIR=/var/lib/rancher/k3s/server/manifests

  4. jdbohrman revised this gist Jan 14, 2020. 1 changed file with 17 additions and 26 deletions.
    43 changes: 17 additions & 26 deletions call-rancher.yaml
    Original file line number Diff line number Diff line change
    @@ -1,45 +1,36 @@
    #!/bin/bash -x
    export curl
    export jq

    export DEBIAN_FRONTEND=noninteractive

    export RANCHER_IP=34.70.139.14
    export CLUSTER_NAME=test-cluster-new
    export OUTPUT_DIR=/var/lib/rancher/k3s/server/manifests

    while true; do
    curl -sLk https://34.70.139.14/ping && break
    curl -sLk https://${RANCHER_IP}/ping && break
    sleep 5
    done

    while true; do

    LOGINRESPONSE=$(curl -s 'https://34.70.139.14/v3-public/localProviders/local?action=login' -H 'content-type: application/json' --data-binary '{"username":"admin","password":"rancher"}' --insecure)
    LOGINTOKEN=$(echo $LOGINRESPONSE | jq -r .token)
    echo "$LOGINTOKEN"
    if [ "$LOGINTOKEN" != "null" ]; then
    LOGIN_RESPONSE=$(curl -s "https://$RANCHER_IP/v3-public/localProviders/local?action=login" -H 'content-type: application/json' --data-binary '{"username":"admin","password":"rancher"}' --insecure)
    LOGIN_TOKEN=$(echo $LOGIN_RESPONSE | jq -r .token)
    echo "$LOGIN_TOKEN"
    if [ "$LOGIN_TOKEN" != "null" ]; then
    break
    else
    sleep 5
    fi
    done

    # Change password
    curl -s 'https://34.70.139.14/v3/users?action=changepassword' -H 'content-type: application/json' -H "Authorization: Bearer $LOGINTOKEN" --data-binary '{"currentPassword":"rancher","newPassword":"${admin_password}"}' --insecure

    # Create API key
    APIRESPONSE='$(curl -s 'https://34.70.139.14/v3/token' -H 'content-type: application/json' -H "Authorization: Bearer $LOGINTOKEN" --data-binary '{"type":"token","description":"automation"} --insecure

    API_RESPONSE=$(curl -s "https://$RANCHER_IP/v3/token" -H 'content-type: application/json' -H "Authorization: Bearer $LOGIN_TOKEN" --data-binary '{"type":"token","description":"automation"}' --insecure)
    # Extract and store token
    APITOKEN=`echo $APIRESPONSE | jq -r .token`

    API_TOKEN=`echo $API_RESPONSE | jq -r .token`
    # Configure server-url
    RANCHER_SERVER="https://$(curl -s http://169.254.169.254/latest/meta-data/public-ipv4)"
    curl -s 'https://34.70.139.14/v3/settings/server-url' -H 'content-type: application/json' -H "Authorization: Bearer $APITOKEN" -X PUT --data-binary '{"name":"server-url","value":"'$RANCHER_SERVER'"}' --insecure

    RANCHER_SERVER_URL="https://$RANCHER_IP/latest/meta-data/public-ipv4"
    curl -s 'https://$RANCHER_IP/v3/settings/server-url' -H 'content-type: application/json' -H "Authorization: Bearer $API_TOKEN" -X PUT --data-binary '{"name":"server-url","value":"'$RANCHER_SERVER_URL'"}' --insecure
    # Create cluster
    CLUSTERRESPONSE=$(curl -s 'https://34.70.139.14/v3/cluster' -H 'content-type: application/json' -H "Authorization: Bearer $APITOKEN" --data-binary '{"dockerRootDir":"/var/lib/docker","enableNetworkPolicy":false,"type":"cluster","rancherKubernetesEngineConfig":{"addonJobTimeout":30,"ignoreDockerVersion":true,"sshAgentAuth":false,"type":"rancherKubernetesEngineConfig","authentication":{"type":"authnConfig","strategy":"x509"},"network":{"type":"networkConfig","plugin":"canal"},"ingress":{"type":"ingressConfig","provider":"nginx"},"monitoring":{"type":"monitoringConfig","provider":"metrics-server"},"services":{"type":"rkeConfigServices","kubeApi":{"podSecurityPolicy":false,"type":"kubeAPIService"},"etcd":{"creation":"12h","extraArgs":{"heartbeat-interval":500,"election-timeout":5000},"retention":"72h","snapshot":false,"type":"etcdService","backupConfig":{"enabled":true,"intervalHours":12,"retention":6,"type":"backupConfig"}}}},"localClusterAuthEndpoint":{"enabled":true,"type":"localClusterAuthEndpoint"},"name":"${cluster_name}"}' --insecure)

    CLUSTER_RESPONSE=$(curl -s "https://$RANCHER_IP/v3/cluster" -H 'content-type: application/json' -H "Authorization: Bearer $API_TOKEN" --data-binary '{"dockerRootDir":"/var/lib/docker","enableNetworkPolicy":false,"type":"cluster","rancherKubernetesEngineConfig":{"addonJobTimeout":30,"ignoreDockerVersion":true,"sshAgentAuth":false,"type":"rancherKubernetesEngineConfig","authentication":{"type":"authnConfig","strategy":"x509"},"network":{"type":"networkConfig","plugin":"canal"},"ingress":{"type":"ingressConfig","provider":"nginx"},"monitoring":{"type":"monitoringConfig","provider":"metrics-server"},"services":{"type":"rkeConfigServices","kubeApi":{"podSecurityPolicy":false,"type":"kubeAPIService"},"etcd":{"creation":"12h","extraArgs":{"heartbeat-interval":500,"election-timeout":5000},"retention":"72h","snapshot":false,"type":"etcdService","backupConfig":{"enabled":true,"intervalHours":12,"retention":6,"type":"backupConfig"}}}},"localClusterAuthEndpoint":{"enabled":true,"type":"localClusterAuthEndpoint"},"name":"'$CLUSTER_NAME'"}' --insecure)
    # Extract clusterid to use for generating the docker run command
    CLUSTERID=`echo $CLUSTERRESPONSE | jq -r .id`

    CLUSTER_ID=`echo $CLUSTER_RESPONSE | jq -r .id`
    # Generate registrationtoken
    curl -s 'https://34.70.139.14/v3/clusterregistrationtoken' -H 'content-type: application/json' -H "Authorization: Bearer $APITOKEN" --data-binary '{"type":"clusterRegistrationToken","clusterId":"'$CLUSTERID'"}' --insecure
    CLUSTER_JSON=$(curl -s "https://$RANCHER_IP/v3/clusterregistrationtoken" -H 'content-type: application/json' -H "Authorization: Bearer $API_TOKEN" --data-binary '{"type":"clusterRegistrationToken","clusterId":"'$CLUSTER_ID'"}' --insecure)
    CLUSTER_TOKEN=`echo $CLUSTER_JSON | jq -r .token`
    curl -o $OUTPUT_DIR/cattle-agent.yaml "https://$RANCHER_IP/v3/import/$CLUSTER_TOKEN.yaml" --insecure
  5. jdbohrman revised this gist Jan 14, 2020. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions call-rancher.yaml
    Original file line number Diff line number Diff line change
    @@ -12,7 +12,7 @@ done

    while true; do

    LOGINRESPONSE=$(curl -s 'https://34.70.139.14/v3-public/localProviders/local?action=login' -H 'content-type: application/json' --data-binary '{"username":"jdbohrman","password":"Flatbush2016"}' --insecure)
    LOGINRESPONSE=$(curl -s 'https://34.70.139.14/v3-public/localProviders/local?action=login' -H 'content-type: application/json' --data-binary '{"username":"admin","password":"rancher"}' --insecure)
    LOGINTOKEN=$(echo $LOGINRESPONSE | jq -r .token)
    echo "$LOGINTOKEN"
    if [ "$LOGINTOKEN" != "null" ]; then
    @@ -23,16 +23,16 @@ while true; do
    done

    # Change password
    curl -s 'https://34.70.139.14/v3/users?action=changepassword' -H 'content-type: application/json' -H "Authorization: Bearer $LOGINTOKEN" --data-binary '{"currentPassword":"Flatbush2016","newPassword":"${admin_password}"}' --insecure
    curl -s 'https://34.70.139.14/v3/users?action=changepassword' -H 'content-type: application/json' -H "Authorization: Bearer $LOGINTOKEN" --data-binary '{"currentPassword":"rancher","newPassword":"${admin_password}"}' --insecure

    # Create API key
    APIRESPONSE=$(curl -s 'https://34.70.139.14/v3/token' -H 'content-type: application/json' -H "Authorization: Bearer $LOGINTOKEN" --data-binary '{"type":"token","description":"automation"}' --insecure)
    APIRESPONSE='$(curl -s 'https://34.70.139.14/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`

    # Configure server-url
    RANCHER_SERVER="$(curl -s http://169.254.169.254/latest/meta-data/public-ipv4)"
    RANCHER_SERVER="https://$(curl -s http://169.254.169.254/latest/meta-data/public-ipv4)"
    curl -s 'https://34.70.139.14/v3/settings/server-url' -H 'content-type: application/json' -H "Authorization: Bearer $APITOKEN" -X PUT --data-binary '{"name":"server-url","value":"'$RANCHER_SERVER'"}' --insecure

    # Create cluster
  6. jdbohrman created this gist Jan 14, 2020.
    45 changes: 45 additions & 0 deletions call-rancher.yaml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,45 @@
    #!/bin/bash -x
    export curl
    export jq

    export DEBIAN_FRONTEND=noninteractive


    while true; do
    curl -sLk https://34.70.139.14/ping && break
    sleep 5
    done

    while true; do

    LOGINRESPONSE=$(curl -s 'https://34.70.139.14/v3-public/localProviders/local?action=login' -H 'content-type: application/json' --data-binary '{"username":"jdbohrman","password":"Flatbush2016"}' --insecure)
    LOGINTOKEN=$(echo $LOGINRESPONSE | jq -r .token)
    echo "$LOGINTOKEN"
    if [ "$LOGINTOKEN" != "null" ]; then
    break
    else
    sleep 5
    fi
    done

    # Change password
    curl -s 'https://34.70.139.14/v3/users?action=changepassword' -H 'content-type: application/json' -H "Authorization: Bearer $LOGINTOKEN" --data-binary '{"currentPassword":"Flatbush2016","newPassword":"${admin_password}"}' --insecure

    # Create API key
    APIRESPONSE=$(curl -s 'https://34.70.139.14/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`

    # Configure server-url
    RANCHER_SERVER="$(curl -s http://169.254.169.254/latest/meta-data/public-ipv4)"
    curl -s 'https://34.70.139.14/v3/settings/server-url' -H 'content-type: application/json' -H "Authorization: Bearer $APITOKEN" -X PUT --data-binary '{"name":"server-url","value":"'$RANCHER_SERVER'"}' --insecure

    # Create cluster
    CLUSTERRESPONSE=$(curl -s 'https://34.70.139.14/v3/cluster' -H 'content-type: application/json' -H "Authorization: Bearer $APITOKEN" --data-binary '{"dockerRootDir":"/var/lib/docker","enableNetworkPolicy":false,"type":"cluster","rancherKubernetesEngineConfig":{"addonJobTimeout":30,"ignoreDockerVersion":true,"sshAgentAuth":false,"type":"rancherKubernetesEngineConfig","authentication":{"type":"authnConfig","strategy":"x509"},"network":{"type":"networkConfig","plugin":"canal"},"ingress":{"type":"ingressConfig","provider":"nginx"},"monitoring":{"type":"monitoringConfig","provider":"metrics-server"},"services":{"type":"rkeConfigServices","kubeApi":{"podSecurityPolicy":false,"type":"kubeAPIService"},"etcd":{"creation":"12h","extraArgs":{"heartbeat-interval":500,"election-timeout":5000},"retention":"72h","snapshot":false,"type":"etcdService","backupConfig":{"enabled":true,"intervalHours":12,"retention":6,"type":"backupConfig"}}}},"localClusterAuthEndpoint":{"enabled":true,"type":"localClusterAuthEndpoint"},"name":"${cluster_name}"}' --insecure)

    # Extract clusterid to use for generating the docker run command
    CLUSTERID=`echo $CLUSTERRESPONSE | jq -r .id`

    # Generate registrationtoken
    curl -s 'https://34.70.139.14/v3/clusterregistrationtoken' -H 'content-type: application/json' -H "Authorization: Bearer $APITOKEN" --data-binary '{"type":"clusterRegistrationToken","clusterId":"'$CLUSTERID'"}' --insecure