Skip to content

Commit bb9cf0f

Browse files
committed
fix vagrant issues
1 parent b50385f commit bb9cf0f

File tree

5 files changed

+28
-33
lines changed

5 files changed

+28
-33
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ ansible/tmp
44
*.retry
55
.vagrant
66
vagrant/tmp
7+
vagrant/*.log

.ssh/config

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,16 @@ Host k8s-worker-03
3333
# vagrant
3434
#
3535
Host vk8s-master
36-
Hostname 10.0.70.10
36+
Hostname 192.168.50.10
3737
IdentityFile ~/.ssh/id_rsa
3838
User vagrant
3939

4040
Host vk8s-worker-01
41-
Hostname 10.0.70.11
41+
Hostname 192.168.50.11
4242
IdentityFile ~/.ssh/id_rsa
4343
User vagrant
4444

4545
Host vk8s-worker-02
46-
Hostname 10.0.70.12
46+
Hostname 192.168.50.12
4747
IdentityFile ~/.ssh/id_rsa
4848
User vagrant
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
k8s_subnet: "10.0.70.0/16"
2-
k8s_node_00_ip: "10.0.70.10"
3-
k8s_node_01_ip: "10.0.70.11"
4-
k8s_node_02_ip: "10.0.70.12"
1+
k8s_subnet: "192.168.0.0/16"
2+
k8s_node_00_ip: "192.168.50.10"
3+
k8s_node_01_ip: "192.168.50.11"
4+
k8s_node_02_ip: "192.168.50.12"
55
os_username: "vagrant"

ansible/playbooks/roles/k8s/tasks/config.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,26 @@
1111
state: directory
1212
become_user: "{{ os_username }}"
1313
when: ansible_host in groups['k8s_masters']
14-
tags: init
14+
tags: init, config
1515

1616
- name: copy | config - Copy kubernetes config to local
1717
copy:
1818
src: /etc/kubernetes/admin.conf
19-
dest: /home/ubuntu/.kube/config
19+
dest: "/home/{{ os_username }}/.kube/config"
2020
remote_src: yes
2121
owner: "{{ os_username }}"
2222
group: "{{ os_username }}"
2323
become: yes
2424
when: ansible_host in groups['k8s_masters']
25-
tags: init
25+
tags: init, config
2626

2727
- name: shell | config - Apply calico network
2828
shell: kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml
2929
environment:
30-
KUBECONFIG: /home/ubuntu/.kube/config
30+
KUBECONFIG: "/home/{{ os_username }}/.kube/config"
3131
become_user: "{{ os_username }}"
3232
when: ansible_host in groups['k8s_masters']
33-
tags: init
33+
tags: init, config
3434

3535
- name: shell | config - Generate join command
3636
shell: kubeadm token create --print-join-command 2>/dev/null

vagrant/Vagrantfile

+15-21
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
k8s_master_ip = '10.0.70.10'
2-
k8s_worker_01_ip = '10.0.70.11'
3-
k8s_worker_02_ip = '10.0.70.12'
1+
ip_range = '192.168.50'
2+
nodes = 2
43

54
$script = <<SCRIPT
5+
swapoff -a
66
if [ ! -d /home/vagrant/.ssh ]; then mkdir /home/vagrant/.ssh; fi
77
echo $(cat /vagrant/tmp/id_rsa.pub) >> /home/vagrant/.ssh/authorized_keys
88
chmod 600 /home/vagrant/.ssh/authorized_keys && chmod 700 /home/vagrant/.ssh
@@ -23,31 +23,25 @@ Vagrant.configure("2") do |config|
2323
if Vagrant.has_plugin?("vagrant-cachier")
2424
config.cache.scope = :machine
2525
config.cache.auto_detect = false
26-
config.cache.enable :gem
27-
config.cache.enable :npm
2826
config.cache.enable :apt
2927
end
3028

31-
config.vm.define "router" do |rt|
32-
rt.vm.box = "eugenmayer/opnsense"
33-
end
29+
# config.vm.define "router" do |rt|
30+
# rt.vm.box = "eugenmayer/opnsense"
31+
# end
3432

35-
config.vm.define "k8s-master" do |km|
33+
config.vm.define "master" do |km|
3634
km.vm.hostname = "vk8s-master"
37-
km.vm.network "private_network", ip: k8s_master_ip
35+
km.vm.network "private_network", ip: "#{ip_range}.10"
3836
km.vm.provision "shell", inline: $script
3937
end
4038

41-
config.vm.define "k8s-worker-01" do |w01|
42-
w01.vm.hostname = "vk8s-worker-01"
43-
w01.vm.network "private_network", ip: k8s_worker_01_ip
44-
w01.vm.provision "shell", inline: $script
45-
end
46-
47-
config.vm.define "k8s-worker-02" do |w02|
48-
w02.vm.hostname = "vk8s-worker-02"
49-
w02.vm.network "private_network", ip: k8s_worker_02_ip
50-
w02.vm.provision "shell", inline: $script
51-
end
39+
(1..nodes).each do |i|
40+
config.vm.define "worker-#{i}" do |node|
41+
node.vm.hostname = "vk8s-worker-01"
42+
node.vm.network "private_network", ip: "#{ip_range}.#{10 + i}"
43+
node.vm.provision "shell", inline: $script
44+
end
45+
end
5246

5347
end

0 commit comments

Comments
 (0)