hoeghh / kubernetes_the_easy_way

Automating Kubernetes the hard way with Vagrant and scripts
MIT License
20 stars 11 forks source link

Simplify install scripts with an install config #46

Open hoeghh opened 6 years ago

hoeghh commented 6 years ago

Right now each host needs to look into a host file and do a lot of jumps to configure itself.

I think it would be smart to generate an install config file that is copied to each host, and used by the install script.

It will make it easier to add more nodes, as it is only to generate a config and then run the same script as the others

It will also make it easier later, to use the scripts outside of this project, or with a provitioning master.

hoeghh commented 6 years ago

I suggest we create/generate a ktew.env file. Use the same name on each host. The file will tell the what kind of node it should install, and all the information it needs.

hoeghh commented 6 years ago

json for etcd test

{
    "type": "etcd",
    "hostname": "k8s-etcd-03",
    "install": {
        "type": "remote",
        "location": "https://lighthouse.net:8000/clusters/4/k8s-etcd-01"
    },
    "etcd_cluster": [{
            "hostname": "k8s-etcd-01",
            "ip": "192.168.0.25",
            "version": "v3.2.11",
            "status": "not-ready"
        },
        {
            "hostname": "k8s-etcd-02",
            "ip": "192.168.0.26",
            "version": "v3.2.11",
            "status": "ready"
        },
        {
            "hostname": "k8s-etcd-03",
            "ip": "192.168.0.27",
            "version": "v3.2.11",
            "status": "ready"
        }
    ]
}

Getting data we need :

export my_hostname=$(cat etcd.json | jq '.hostname' | tr -d \")
export my_ip=$(cat etcd.json | jq '.etcd_cluster[] | select (.hostname=="'$my_hostname'") | .ip' | tr -d \")

export other_ips=$(cat etcd.json | jq '.etcd_cluster[] | select (.hostname=="'$my_hostname'" | not) | .ip' | tr -d \" | tr '\n' ',' |  sed 's/,$//g')

export cluster_list=$(cat etcd.json | jq '.etcd_cluster[] | " \(.hostname)=https://\(.ip)"' | tr -d \" | tr '\n' ',' |  sed 's/,$//g')