Add support for deployment via kargo-cli
This commit is contained in:
parent
b9ed54812b
commit
531f611ea3
4 changed files with 69 additions and 6 deletions
33
Vagrantfile
vendored
33
Vagrantfile
vendored
|
@ -2,15 +2,17 @@
|
||||||
# vi: set ft=ruby :
|
# vi: set ft=ruby :
|
||||||
|
|
||||||
ENV["VAGRANT_DEFAULT_PROVIDER"] = "libvirt"
|
ENV["VAGRANT_DEFAULT_PROVIDER"] = "libvirt"
|
||||||
|
pool = ENV["VAGRANT_POOL"] || "10.210.0.0/16"
|
||||||
|
prefix = pool.gsub(/\.\d+\.\d+\/16$/, "")
|
||||||
|
|
||||||
$num_instances = 7
|
$num_instances = 7
|
||||||
$vm_memory = 2048
|
$vm_memory = 2048
|
||||||
$vm_cpus = 2
|
$vm_cpus = 2
|
||||||
|
|
||||||
$user = "adidenko"
|
$user = ENV["USER"]
|
||||||
$public_subnet = "10.210.0"
|
$public_subnet = prefix.to_s + ".0"
|
||||||
$private_subnet = "10.210.1"
|
$private_subnet = prefix.to_s + ".1"
|
||||||
$mgmt_cidr = "10.210.2.0/24"
|
$mgmt_cidr = prefix.to_s + ".2.0/24"
|
||||||
|
|
||||||
$instance_name_prefix = "#{$user}-k8s"
|
$instance_name_prefix = "#{$user}-k8s"
|
||||||
# Boxes with libvirt provider support:
|
# Boxes with libvirt provider support:
|
||||||
|
@ -18,12 +20,23 @@ $instance_name_prefix = "#{$user}-k8s"
|
||||||
#$box = "centos/7"
|
#$box = "centos/7"
|
||||||
$box = "nrclark/xenial64-minimal-libvirt"
|
$box = "nrclark/xenial64-minimal-libvirt"
|
||||||
|
|
||||||
|
nodes=""
|
||||||
|
(1..$num_instances).each do |i|
|
||||||
|
ip = "#{$private_subnet}.#{i+10}"
|
||||||
|
test_vm.vm.network :private_network, :ip => "#{ip}"
|
||||||
|
nodes = "#{nodes}#{ip}\n"
|
||||||
|
end
|
||||||
|
File.open("nodes", 'w') { |file| file.write(nodes) }
|
||||||
|
|
||||||
Vagrant.configure("2") do |config|
|
Vagrant.configure("2") do |config|
|
||||||
(1..$num_instances).each do |i|
|
(1..$num_instances).each do |i|
|
||||||
|
# First node would be master node
|
||||||
if i == 1
|
if i == 1
|
||||||
bootstrap_script = "bootstrap-master.sh"
|
bootstrap_script = "bootstrap-master.sh"
|
||||||
|
master = true
|
||||||
else
|
else
|
||||||
bootstrap_script = "bootstrap-node.sh"
|
bootstrap_script = "bootstrap-node.sh"
|
||||||
|
master = false
|
||||||
end
|
end
|
||||||
config.ssh.insert_key = false
|
config.ssh.insert_key = false
|
||||||
vm_name = "%s-%02d" % [$instance_name_prefix, i]
|
vm_name = "%s-%02d" % [$instance_name_prefix, i]
|
||||||
|
@ -42,11 +55,21 @@ Vagrant.configure("2") do |config|
|
||||||
domain.nic_model_type = "e1000"
|
domain.nic_model_type = "e1000"
|
||||||
domain.management_network_name = "#{$instance_name_prefix}-mgmt-net"
|
domain.management_network_name = "#{$instance_name_prefix}-mgmt-net"
|
||||||
domain.management_network_address = $mgmt_cidr
|
domain.management_network_address = $mgmt_cidr
|
||||||
|
domain.nested = true
|
||||||
|
domain.cpu_mode = "host-passthrough"
|
||||||
|
domain.volume_cache = "unsafe"
|
||||||
|
domain.disk_bus = "virtio"
|
||||||
end
|
end
|
||||||
|
|
||||||
test_vm.vm.network :private_network, :ip => "#{$private_subnet}.#{i+10}"
|
ip = "#{$private_subnet}.#{i+10}"
|
||||||
|
test_vm.vm.network :private_network, :ip => "#{ip}"
|
||||||
|
|
||||||
# Provisioning
|
# Provisioning
|
||||||
|
if master
|
||||||
|
config.vm.provision "file", source: "deploy-k8s.kargo.sh", destination: "~/deploy-k8s.kargo.sh"
|
||||||
|
config.vm.provision "file", source: "custom.yaml", destination: "~/custom.yaml"
|
||||||
|
config.vm.provision "file", source: "nodes", destination: "~/nodes"
|
||||||
|
end
|
||||||
config.vm.provision "file", source: "ssh", destination: "~/ssh"
|
config.vm.provision "file", source: "ssh", destination: "~/ssh"
|
||||||
config.vm.provision :shell, :path => bootstrap_script
|
config.vm.provision :shell, :path => bootstrap_script
|
||||||
|
|
||||||
|
|
|
@ -1,16 +1,35 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
echo master > /var/tmp/role
|
echo master > /var/tmp/role
|
||||||
|
|
||||||
|
# Packages
|
||||||
sudo apt-get --yes update
|
sudo apt-get --yes update
|
||||||
sudo apt-get --yes upgrade
|
sudo apt-get --yes upgrade
|
||||||
sudo apt-get --yes install ansible git screen vim telnet tcpdump
|
sudo apt-get --yes install ansible git screen vim telnet tcpdump python-setuptools gcc python-dev python-pip libssl-dev libffi-dev software-properties-common
|
||||||
|
|
||||||
|
# Kargo and custom inventory
|
||||||
sudo git clone https://github.com/kubespray/kargo /root/kargo
|
sudo git clone https://github.com/kubespray/kargo /root/kargo
|
||||||
sudo git clone https://github.com/adidenko/vagrant-k8s /root/vagrant-k8s
|
sudo git clone https://github.com/adidenko/vagrant-k8s /root/vagrant-k8s
|
||||||
sudo cp -a /root/vagrant-k8s/kargo/inv /root/kargo/inv
|
sudo cp -a /root/vagrant-k8s/kargo/inv /root/kargo/inv
|
||||||
|
|
||||||
|
# Kargo-cli
|
||||||
|
sudo git clone https://github.com/kubespray/kargo-cli.git /root/kargo-cli
|
||||||
|
sudo sh -c 'cd /root/kargo-cli && python setup.py install'
|
||||||
|
|
||||||
|
# Pip
|
||||||
|
sudo pip install kpm
|
||||||
|
|
||||||
|
# k8s deploy script and config
|
||||||
|
sudo sh -c 'cp -a ~/deploy-k8s.kargo.sh /root/ && chmod 755 /root/deploy-k8s.kargo.sh'
|
||||||
|
sudo cp -a ~/custom.yaml /root/kargo/custom.yaml
|
||||||
|
|
||||||
|
# SSH keys and config
|
||||||
sudo rm -rf /root/.ssh
|
sudo rm -rf /root/.ssh
|
||||||
sudo mv ~vagrant/ssh /root/.ssh
|
sudo mv ~vagrant/ssh /root/.ssh
|
||||||
sudo echo -e 'Host 10.210.*\n\tStrictHostKeyChecking no\n\tUserKnownHostsFile=/dev/null' >> /root/.ssh/config
|
sudo echo -e 'Host 10.210.*\n\tStrictHostKeyChecking no\n\tUserKnownHostsFile=/dev/null' >> /root/.ssh/config
|
||||||
sudo chown -R root: /root/.ssh
|
sudo chown -R root: /root/.ssh
|
||||||
|
|
||||||
|
# Save nodes list
|
||||||
|
sudo cp ~/nodes /root/nodes
|
||||||
|
|
||||||
|
# README
|
||||||
sudo echo 'cd /root/kargo ; ansible-playbook -vvv -i inv/inventory.cfg cluster.yml -u root -f 7' > /root/README
|
sudo echo 'cd /root/kargo ; ansible-playbook -vvv -i inv/inventory.cfg cluster.yml -u root -f 7' > /root/README
|
||||||
|
|
2
custom.yaml
Normal file
2
custom.yaml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
kube_network_plugin: "calico"
|
||||||
|
kube_proxy_mode: "iptables"
|
19
deploy-k8s.kargo.sh
Normal file
19
deploy-k8s.kargo.sh
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
custom_opts='--ansible-opts="-e @kargo/custom.yaml"'
|
||||||
|
nodes=""
|
||||||
|
|
||||||
|
i=0
|
||||||
|
for nodeip in `cat /root/nodes` ; do
|
||||||
|
i=$(( $i+1 ))
|
||||||
|
nodes+=" node${i}[ansible_ssh_host=${nodeip},ip=${nodeip}]"
|
||||||
|
done
|
||||||
|
|
||||||
|
kargo prepare -y --nodes $nodes
|
||||||
|
kargo deploy -y $custom_opts
|
||||||
|
deploy_res=$?
|
||||||
|
|
||||||
|
if [ "$deploy_res" -eq "0" ]; then
|
||||||
|
echo "Setting up kubedns..."
|
||||||
|
kpm deploy kube-system/kubedns --namespace=kube-system
|
||||||
|
fi
|
Loading…
Reference in a new issue