From bae2ed6d01bdd50f49dfcb7fc8dea935aa8cd1b0 Mon Sep 17 00:00:00 2001 From: Christoph Luenswilken Date: Mon, 23 Aug 2021 20:03:17 +0200 Subject: [PATCH 1/5] Example vagrantfile for Windows Signed-off-by: Christoph Luenswilken --- Vagrantfile_Windows | 82 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 Vagrantfile_Windows diff --git a/Vagrantfile_Windows b/Vagrantfile_Windows new file mode 100644 index 0000000..9cb07f9 --- /dev/null +++ b/Vagrantfile_Windows @@ -0,0 +1,82 @@ +IMAGE_NAME = "bento/ubuntu-20.04" +K8S_NAME = "ditwl-k8s-01" +MASTERS_NUM = 1 +MASTERS_CPU = 2 +MASTERS_MEM = 2048 + +NODES_NUM = 2 +NODES_CPU = 2 +NODES_MEM = 2048 + +IP_BASE = "192.168.50." + +VAGRANT_DISABLE_VBOXSYMLINKCREATE=1 + +# IMPORTANT for WSL2 users: inject your own ssh key from your /home/ directory into the VMs. +# The file must exist WITHIN the file system of your WSL2 distro, and NOT be mounted into the WSL2 distro from windows! +# Otherwise ansible will error with "insecure private key" +# Make sure that the corresponding "*.pub" file is located in the same directory (which it usually is) +SECURE_SSH_PRIVATE_KEY = "~/.ssh/devOps" + +Vagrant.configure("2") do |config| + config.ssh.insert_key = false + + # Insert own ssh key to the machines. + # Taken from: https://stackoverflow.com/questions/30075461/how-do-i-add-my-own-public-key-to-vagrant-vm + vagrant_home_path = ENV["VAGRANT_HOME"] ||= "~/.vagrant.d" + config.ssh.private_key_path = ["#{vagrant_home_path}/insecure_private_key", "#{SECURE_SSH_PRIVATE_KEY}"] + + config.vm.provision "file", source: "#{SECURE_SSH_PRIVATE_KEY}.pub", destination: "/home/vagrant/.ssh/SecureKey.pub" + config.vm.provision :shell, privileged: false do |shell_action| + shell_action.inline = <<-SHELL + cat /home/vagrant/.ssh/SecureKey.pub >> /home/vagrant/.ssh/authorized_keys + SHELL + end + + (1..MASTERS_NUM).each do |i| + config.vm.define "k8s-m-#{i}" do |master| + master.vm.box = IMAGE_NAME + master.vm.network "private_network", ip: "#{IP_BASE}#{i + 10}" + master.vm.hostname = "k8s-m-#{i}" + master.vm.provider "virtualbox" do |v| + v.memory = MASTERS_MEM + v.cpus = MASTERS_CPU + end + master.vm.provision "ansible" do |ansible| + ansible.playbook = "roles/k8s.yml" + #Redefine defaults + ansible.extra_vars = { + k8s_cluster_name: K8S_NAME, + k8s_master_admin_user: "vagrant", + k8s_master_admin_group: "vagrant", + k8s_master_apiserver_advertise_address: "#{IP_BASE}#{i + 10}", + k8s_master_node_name: "k8s-m-#{i}", + k8s_node_public_ip: "#{IP_BASE}#{i + 10}" + } + end + end + end + + (1..NODES_NUM).each do |j| + config.vm.define "k8s-n-#{j}" do |node| + node.vm.box = IMAGE_NAME + node.vm.network "private_network", ip: "#{IP_BASE}#{j + 10 + MASTERS_NUM}" + node.vm.hostname = "k8s-n-#{j}" + node.vm.provider "virtualbox" do |v| + v.memory = NODES_MEM + v.cpus = NODES_CPU + #v.customize ["modifyvm", :id, "--cpuexecutioncap", "20"] + end + node.vm.provision "ansible" do |ansible| + ansible.playbook = "roles/k8s.yml" + #Redefine defaults + ansible.extra_vars = { + k8s_cluster_name: K8S_NAME, + k8s_node_admin_user: "vagrant", + k8s_node_admin_group: "vagrant", + k8s_node_public_ip: "#{IP_BASE}#{j + 10 + MASTERS_NUM}" + } + end + end + end +end From 1bed634dba373dd0a14a5290a361e72953c6cbf2 Mon Sep 17 00:00:00 2001 From: Christoph Luenswilken Date: Mon, 23 Aug 2021 20:07:41 +0200 Subject: [PATCH 2/5] added a windows section Signed-off-by: Christoph Luenswilken --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index b1de4db..40146fb 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,10 @@ See https://www.itwonderlab.com/en/ansible-kubernetes-vagrant-tutorial/ ------------------ +## For Windows users +It is possible to execute the provisioning by leveraging the WSL2 sharing functionalities of Windows. Take a look [here](https://gist.github.com/pr3l14t0r/8b350fc7052ccee30a456596fa017c33) for further requirements and explanation. +Take the slightly modified [Vagrantfile for Windows](Vagrantfile_Windows) as an example for the kubernetes cluster deployment. + ## Creación de un Clúster de Kubernetes 1.22 Containerd e Istio usando Vagrant y Ansible (1 maestro N nodos) Creación de un **clúster Kubernetes con múltiples nodos usando Vagrant, Ansible y Virtualbox**. Especialmente indicado para entornos de desarrollo local realistas. From 2c63930542f3fe91fec9b9fa62bdbbce157d228e Mon Sep 17 00:00:00 2001 From: Christoph Luenswilken Date: Mon, 23 Aug 2021 20:25:00 +0200 Subject: [PATCH 3/5] merged changes into Vagrantfile Signed-off-by: Christoph Luenswilken --- Vagrantfile | 20 ++++++++++++++++++++ Vagrantfile_Windows | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Vagrantfile b/Vagrantfile index 10655e3..4454429 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -12,9 +12,29 @@ IP_BASE = "192.168.50." VAGRANT_DISABLE_VBOXSYMLINKCREATE=1 +# IMPORTANT for Windows WSL2 users: inject your own ssh key from your /home/ directory into the VMs. +# The file must exist WITHIN the file system of your WSL2 distro, and NOT be mounted into the WSL2 distro from windows! +# Otherwise ansible will error with "insecure private key" +# Make sure that the corresponding "*.pub" file is located in the same directory (which it usually is) +# Uncomment the next line: +#SECURE_SSH_PRIVATE_KEY = "~/.ssh/NewKey" + Vagrant.configure("2") do |config| config.ssh.insert_key = false + # Insert own ssh key to the machines. + # Taken from: https://stackoverflow.com/questions/30075461/how-do-i-add-my-own-public-key-to-vagrant-vm + # uncomment the next block + # vagrant_home_path = ENV["VAGRANT_HOME"] ||= "~/.vagrant.d" + # config.ssh.private_key_path = ["#{vagrant_home_path}/insecure_private_key", "#{SECURE_SSH_PRIVATE_KEY}"] + + # config.vm.provision "file", source: "#{SECURE_SSH_PRIVATE_KEY}.pub", destination: "/home/vagrant/.ssh/SecureKey.pub" + # config.vm.provision :shell, privileged: false do |shell_action| + # shell_action.inline = <<-SHELL + # cat /home/vagrant/.ssh/SecureKey.pub >> /home/vagrant/.ssh/authorized_keys + # SHELL + # end + (1..MASTERS_NUM).each do |i| config.vm.define "k8s-m-#{i}" do |master| master.vm.box = IMAGE_NAME diff --git a/Vagrantfile_Windows b/Vagrantfile_Windows index 9cb07f9..69eba21 100644 --- a/Vagrantfile_Windows +++ b/Vagrantfile_Windows @@ -16,7 +16,7 @@ VAGRANT_DISABLE_VBOXSYMLINKCREATE=1 # The file must exist WITHIN the file system of your WSL2 distro, and NOT be mounted into the WSL2 distro from windows! # Otherwise ansible will error with "insecure private key" # Make sure that the corresponding "*.pub" file is located in the same directory (which it usually is) -SECURE_SSH_PRIVATE_KEY = "~/.ssh/devOps" +SECURE_SSH_PRIVATE_KEY = "~/.ssh/NewKey" Vagrant.configure("2") do |config| config.ssh.insert_key = false From 47bb9ce51bc12b2b6360a78a9112e0adbafbe1f2 Mon Sep 17 00:00:00 2001 From: Christoph Luenswilken Date: Mon, 23 Aug 2021 20:30:03 +0200 Subject: [PATCH 4/5] modified contents Signed-off-by: Christoph Luenswilken --- Vagrantfile | 24 ++++++------- Vagrantfile_Windows | 82 --------------------------------------------- 2 files changed, 11 insertions(+), 95 deletions(-) delete mode 100644 Vagrantfile_Windows diff --git a/Vagrantfile b/Vagrantfile index 4454429..2dea551 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -12,11 +12,8 @@ IP_BASE = "192.168.50." VAGRANT_DISABLE_VBOXSYMLINKCREATE=1 -# IMPORTANT for Windows WSL2 users: inject your own ssh key from your /home/ directory into the VMs. -# The file must exist WITHIN the file system of your WSL2 distro, and NOT be mounted into the WSL2 distro from windows! -# Otherwise ansible will error with "insecure private key" -# Make sure that the corresponding "*.pub" file is located in the same directory (which it usually is) -# Uncomment the next line: +# Windows WSL users should use an own ssh private key and inject its corresponding public-key into the VM. +# uncomment the next line, providing a path to your ssh private key within the WSL2 distro #SECURE_SSH_PRIVATE_KEY = "~/.ssh/NewKey" Vagrant.configure("2") do |config| @@ -25,15 +22,16 @@ Vagrant.configure("2") do |config| # Insert own ssh key to the machines. # Taken from: https://stackoverflow.com/questions/30075461/how-do-i-add-my-own-public-key-to-vagrant-vm # uncomment the next block - # vagrant_home_path = ENV["VAGRANT_HOME"] ||= "~/.vagrant.d" - # config.ssh.private_key_path = ["#{vagrant_home_path}/insecure_private_key", "#{SECURE_SSH_PRIVATE_KEY}"] + + #vagrant_home_path = ENV["VAGRANT_HOME"] ||= "~/.vagrant.d" + #config.ssh.private_key_path = ["#{vagrant_home_path}/insecure_private_key", "#{SECURE_SSH_PRIVATE_KEY}"] - # config.vm.provision "file", source: "#{SECURE_SSH_PRIVATE_KEY}.pub", destination: "/home/vagrant/.ssh/SecureKey.pub" - # config.vm.provision :shell, privileged: false do |shell_action| - # shell_action.inline = <<-SHELL - # cat /home/vagrant/.ssh/SecureKey.pub >> /home/vagrant/.ssh/authorized_keys - # SHELL - # end + #config.vm.provision "file", source: "#{SECURE_SSH_PRIVATE_KEY}.pub", destination: "/home/vagrant/.ssh/SecureKey.pub" + #config.vm.provision :shell, privileged: false do |shell_action| + # shell_action.inline = <<-SHELL + # cat /home/vagrant/.ssh/SecureKey.pub >> /home/vagrant/.ssh/authorized_keys + # SHELL + # end (1..MASTERS_NUM).each do |i| config.vm.define "k8s-m-#{i}" do |master| diff --git a/Vagrantfile_Windows b/Vagrantfile_Windows deleted file mode 100644 index 69eba21..0000000 --- a/Vagrantfile_Windows +++ /dev/null @@ -1,82 +0,0 @@ -IMAGE_NAME = "bento/ubuntu-20.04" -K8S_NAME = "ditwl-k8s-01" -MASTERS_NUM = 1 -MASTERS_CPU = 2 -MASTERS_MEM = 2048 - -NODES_NUM = 2 -NODES_CPU = 2 -NODES_MEM = 2048 - -IP_BASE = "192.168.50." - -VAGRANT_DISABLE_VBOXSYMLINKCREATE=1 - -# IMPORTANT for WSL2 users: inject your own ssh key from your /home/ directory into the VMs. -# The file must exist WITHIN the file system of your WSL2 distro, and NOT be mounted into the WSL2 distro from windows! -# Otherwise ansible will error with "insecure private key" -# Make sure that the corresponding "*.pub" file is located in the same directory (which it usually is) -SECURE_SSH_PRIVATE_KEY = "~/.ssh/NewKey" - -Vagrant.configure("2") do |config| - config.ssh.insert_key = false - - # Insert own ssh key to the machines. - # Taken from: https://stackoverflow.com/questions/30075461/how-do-i-add-my-own-public-key-to-vagrant-vm - vagrant_home_path = ENV["VAGRANT_HOME"] ||= "~/.vagrant.d" - config.ssh.private_key_path = ["#{vagrant_home_path}/insecure_private_key", "#{SECURE_SSH_PRIVATE_KEY}"] - - config.vm.provision "file", source: "#{SECURE_SSH_PRIVATE_KEY}.pub", destination: "/home/vagrant/.ssh/SecureKey.pub" - config.vm.provision :shell, privileged: false do |shell_action| - shell_action.inline = <<-SHELL - cat /home/vagrant/.ssh/SecureKey.pub >> /home/vagrant/.ssh/authorized_keys - SHELL - end - - (1..MASTERS_NUM).each do |i| - config.vm.define "k8s-m-#{i}" do |master| - master.vm.box = IMAGE_NAME - master.vm.network "private_network", ip: "#{IP_BASE}#{i + 10}" - master.vm.hostname = "k8s-m-#{i}" - master.vm.provider "virtualbox" do |v| - v.memory = MASTERS_MEM - v.cpus = MASTERS_CPU - end - master.vm.provision "ansible" do |ansible| - ansible.playbook = "roles/k8s.yml" - #Redefine defaults - ansible.extra_vars = { - k8s_cluster_name: K8S_NAME, - k8s_master_admin_user: "vagrant", - k8s_master_admin_group: "vagrant", - k8s_master_apiserver_advertise_address: "#{IP_BASE}#{i + 10}", - k8s_master_node_name: "k8s-m-#{i}", - k8s_node_public_ip: "#{IP_BASE}#{i + 10}" - } - end - end - end - - (1..NODES_NUM).each do |j| - config.vm.define "k8s-n-#{j}" do |node| - node.vm.box = IMAGE_NAME - node.vm.network "private_network", ip: "#{IP_BASE}#{j + 10 + MASTERS_NUM}" - node.vm.hostname = "k8s-n-#{j}" - node.vm.provider "virtualbox" do |v| - v.memory = NODES_MEM - v.cpus = NODES_CPU - #v.customize ["modifyvm", :id, "--cpuexecutioncap", "20"] - end - node.vm.provision "ansible" do |ansible| - ansible.playbook = "roles/k8s.yml" - #Redefine defaults - ansible.extra_vars = { - k8s_cluster_name: K8S_NAME, - k8s_node_admin_user: "vagrant", - k8s_node_admin_group: "vagrant", - k8s_node_public_ip: "#{IP_BASE}#{j + 10 + MASTERS_NUM}" - } - end - end - end -end From 0285487e29b572cbcda8bdc71e64658bc05178f7 Mon Sep 17 00:00:00 2001 From: Christoph Luenswilken Date: Mon, 23 Aug 2021 20:39:00 +0200 Subject: [PATCH 5/5] removed broken link Signed-off-by: Christoph Luenswilken --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 40146fb..be5f21a 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ See https://www.itwonderlab.com/en/ansible-kubernetes-vagrant-tutorial/ ## For Windows users It is possible to execute the provisioning by leveraging the WSL2 sharing functionalities of Windows. Take a look [here](https://gist.github.com/pr3l14t0r/8b350fc7052ccee30a456596fa017c33) for further requirements and explanation. -Take the slightly modified [Vagrantfile for Windows](Vagrantfile_Windows) as an example for the kubernetes cluster deployment. +Uncomment the Windows related lines in the Vagrantfile in order to inject a ssh key from your WSL2 distribution into the VMs. ## Creación de un Clúster de Kubernetes 1.22 Containerd e Istio usando Vagrant y Ansible (1 maestro N nodos)