sh 用于在Openstack上自动部署k8的脚本。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh 用于在Openstack上自动部署k8的脚本。相关的知识,希望对你有一定的参考价值。

#!/bin/bash
#June 18 2017 Patrick Blaas <Patrick@kite4fun.nl>
# 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

以上是关于sh 用于在Openstack上自动部署k8的脚本。的主要内容,如果未能解决你的问题,请参考以下文章

再见 Jenkins!几行脚本搞定自动化部署,这款神器有点厉害

教程get | K8S部署OpenStack容器云(上)

Kubernetes(k8s)安装

Shell脚本自动编译打包Gradle项目并docker部署

k8s部署的vault ,自动解封(unseal)

Jenkins+Rancher自动化部署