diff --git a/kubernetes/metallb/cm-metallb.yaml.erb b/kubernetes/metallb/cm-metallb.yaml.erb new file mode 100644 index 0000000000000000000000000000000000000000..8cd194924fa98dac881a5b42530df7e6f4461be5 --- /dev/null +++ b/kubernetes/metallb/cm-metallb.yaml.erb @@ -0,0 +1,12 @@ +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: metallb-config +data: + config: | + address-pools: + - name: default + protocol: layer2 + addresses: + - <%= rangeStr %> \ No newline at end of file diff --git a/tasks/kube.rb b/tasks/kube.rb index 5791c1b817aa54feb762d307065a85ebba2e33d1..9b301771b47f43856bf64e8636f06f0d6860306e 100644 --- a/tasks/kube.rb +++ b/tasks/kube.rb @@ -1,3 +1,5 @@ +require 'erb' + namespace :kube do desc 'Init master' @@ -99,4 +101,27 @@ namespace :kube do end end + desc 'Deploy metallb' + task :deployMetallb do + subnet = xp.job_with_name(XP5K::Config[:jobname])['resources_by_type']['subnets'].first + ipaddr = IPAddr.new(subnet) + range = ipaddr.to_range.to_a[257..510] + rangeStr = "#{range.first.to_s}-#{range.last.to_s}" + tmpl = ERB.new(File.read('kubernetes/metallb/cm-metallb.yaml.erb')) + cm = tmpl.result(binding) + File.open("kubernetes/metallb/cm-metallb.yaml", 'w') do |file| + file.puts cm + end + ip = clusterDesc()['master']['kubemaster'] + repoLocalPath = Dir.pwd + repoVmPath = repoLocalPath.sub(ENV['HOME'], "/mnt/home") + on(ip, :user => 'root') do + [ + 'kubectl create ns metallb', + "kubectl -n metallb apply -f #{repoVmPath}/kubernetes/metallb/cm-metallb.yaml", + %{helm install -n metallb --namespace metallb stable/metallb} + ] + end + end + end