1

I am using a Vagrantfile to create a Kubernetes cluster, I start with variables definition of servers and I move on to a loop to shuffle through each server definition creation. Within the loop I do everything I need with provisioners to get the k8s 14.3 up and running (1 master and 3 nodes). My problem is that I want to perform an action on k8s-master after cluster is up and all nodes actions are completed. So I want to get the object of k8s-master server and run an action against, is that possible? Can I assign the context and reuse it after?

Vagrant.configure("2") do |config|

  servers.each do |opts|
    config.vm.define opts[:name] do |config|

      config.vm.box = opts[:box]
      config.vm.box_version = opts[:box_version]
      config.vm.hostname = opts[:name]
      config.vm.network :private_network, ip: opts[:eth1]

      config.vm.provider "virtualbox" do |v|

        v.name = opts[:name]
        v.customize ["modifyvm", :id, "--groups", "/KubernetesCluster"]
        v.customize ["modifyvm", :id, "--memory", opts[:mem]]
        v.customize ["modifyvm", :id, "--cpus", opts[:cpu]]
      end

      config.vm.provision "shell", path: "./scripts/configureBox.sh"
      if opts[:type] == "master"
        config.vm.provision "shell", path: "./scripts/configureMaster.sh"
      else
        config.vm.provision "shell", path: "./scripts/configureNode.sh"
      end
    end
  end
  # need to execute a provisioning action against first node which is named (k8s-master)
  end
end

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.