Skip to content

Instantly share code, notes, and snippets.

@naviat
Forked from pblaas/k8s_setup.sh
Created August 1, 2018 16:39
Show Gist options
  • Save naviat/bfa441e29c70e63820664973ae3483cc to your computer and use it in GitHub Desktop.
Save naviat/bfa441e29c70e63820664973ae3483cc to your computer and use it in GitHub Desktop.
Script used to automaticly deploy k8s on Openstack.
#!/bin/bash
#June 18 2017 Patrick Blaas <[email protected]>
# Terraform, cloudinit_generator wrapper script to initiate a Kubernetes cluster.
IFS=$'\n\t'
#create list of main cluster ips.
echo $(terraform show|grep access_ip_v4|cut -d= -f2) > k8s_cluster_ips.txt
echo Downloading cloudinit_generator.
git clone https://github.com/pblaas/cloudinit_generator.git
MASTER_HOST_IP=$(cat k8s_cluster_ips.txt |awk '{ print $1 }')
MASTER_HOST_FQDN=$(cat k8s_cluster_ips.txt |awk '{ print $1 }')
MASTER_HOST_GW=$(cat k8s_cluster_ips.txt |awk '{ print $1 }'|cut -d. -f1-3).1
WORKER_GW=$(cat k8s_cluster_ips.txt |awk '{ print $1 }'|cut -d. -f1-3).1
WORKER_IP1=$(cat k8s_cluster_ips.txt |awk '{ print $2 }')
WORKER_IP2=$(cat k8s_cluster_ips.txt |awk '{ print $3 }')
WORKER_HOSTS="($WORKER_IP1 $WORKER_IP2)"
K8S_VER=v1.6.4_coreos.0
K8S_SERVICE_IP=10.3.0.1
DNSSERVER=8.8.8.8
CLUSTER_DNS=10.3.0.10
SERVICE_CLUSTER_IP_RANGE=10.3.0.0/24
ETCD_ENDPOINTS_URLS=http://$MASTER_HOST_IP:2379,http://$WORKER_IP1:2379,http://$WORKER_IP2:2379
USER_CORE_PASSWORD=c0mpl3x
USER_CORE_KEY1="ssh-rsa ...."
USER_CORE_KEY2="ssh-rsa ...."
#generate conf.env
echo MASTER_HOST_IP=$MASTER_HOST_IP > cloudinit_generator/config.env
echo MASTER_HOST_FQDN=$MASTER_HOST_FQDN >> cloudinit_generator/config.env
echo MASTER_HOST_GW=$MASTER_HOST_GW >> cloudinit_generator/config.env
echo WORKER_GW=$WORKER_GW >> cloudinit_generator/config.env
echo WORKER_IP1=$WORKER_IP1 >> cloudinit_generator/config.env
echo WORKER_IP2=$WORKER_IP2 >> cloudinit_generator/config.env
echo WORKER_HOSTS=$WORKER_HOSTS >> cloudinit_generator/config.env
echo K8S_VER=$K8S_VER >> cloudinit_generator/config.env
echo K8S_SERVICE_IP=$K8S_SERVICE_IP >> cloudinit_generator/config.env
echo DNSSERVER=$DNSSERVER >> cloudinit_generator/config.env
echo CLUSTER_DNS=$CLUSTER_DNS >> cloudinit_generator/config.env
echo SERVICE_CLUSTER_IP_RANGE=$SERVICE_CLUSTER_IP_RANGE >> cloudinit_generator/config.env
echo ETCD_ENDPOINTS_URLS=$ETCD_ENDPOINTS_URLS >> cloudinit_generator/config.env
echo USER_CORE_PASSWORD=$USER_CORE_PASSWORD >> cloudinit_generator/config.env
echo USER_CORE_KEY1=\"$USER_CORE_KEY1\" >> cloudinit_generator/config.env
echo USER_CORE_KEY2=\"$USER_CORE_KEY2\" >> cloudinit_generator/config.env
cd cloudinit_generator
echo YES | ./create_cloudinit.sh
cd -
for i in `terraform show|grep access_ip_v4|cut -d= -f2|cut -c 2-`; do
ssh -o "StrictHostKeyChecking no" core@$i sudo mkdir /var/lib/coreos-install
ssh -o "StrictHostKeyChecking no" core@$i sudo chown core /var/lib/coreos-install
scp cloudinit_generator/set/node_$i.yaml core@$i:/var/lib/coreos-install/user_data
ssh -o "StrictHostKeyChecking no" core@$i sudo reboot
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment