Skip to content

Commit e1a3c4a

Browse files
alacukufrisso
authored andcommitted
Update vagrant ansible for pcn-k8s (#253)
* Fixed the host_vars folder missing * Fixed the ssh-keys when a keyring daemon is not used * Minor improvements regarding the network address spaces that can be used * Vagranfile deleted * fixed ssh private key path
1 parent 8098053 commit e1a3c4a

File tree

7 files changed

+38
-15
lines changed

7 files changed

+38
-15
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ build/*
55
swagger-codegen*
66
.vscode/*
77
.idea/*
8+
Vagrantfile

tests/ansible_vagrant/kubernetes-playbooks/group_vars/all/vars.yml

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ apt_packages:
2323
#pub_key_path: /home/aldo/.ssh/vagrant_machines.pub
2424

2525
#pod-network-cidr used in k8s
26-
pod_network_cidr: 10.244.0.0/16
26+
pod_network_cidr: 10.16.0.0/16
27+
28+
#service-cidr used in k8s, change it to suit your needs
29+
30+
service_cidr: 10.96.0.0/12
2731

2832
#user to be added to the k8s group
2933
user: vagrant
@@ -35,20 +39,21 @@ time_zone: Europe/Rome
3539
#Nodes Configuration#
3640
#####################
3741

38-
#Node configuration. The cluster can have only one master node and many worker nodes as needed.
42+
#Node configuration. The cluster can have only one master node and many worker nodes as needed. Please change those values as needed.
3943
k8s_master_nodes_ips:
40-
- 192.168.0.23
44+
- 192.168.1.10
4145

4246
k8s_worker_nodes_ips:
43-
- 192.168.0.24
44-
- 192.168.0.25
45-
- 192.168.0.26
46-
- 192.168.0.27
47+
- 192.168.1.11
48+
- 192.168.1.12
49+
50+
#Netmask used for the network to which the node ips belong to
51+
netmask: 255.255.254.0
4752

4853
#theese prefixes are used when generating the names of the nodes. Used in the host_vars files, inventory.ini and in /etc/hosts in the local system.
49-
k8s_master_node_prefix: k8s-master-
54+
k8s_master_node_prefix: k8s-1-master-
5055

51-
k8s_worker_node_prefix: k8s-node-
56+
k8s_worker_node_prefix: k8s-1-node-
5257

5358

5459
############################
@@ -67,6 +72,9 @@ ssh_key_name: vagrant_machines
6772
#path to the public key used to ssh to the machines, if this key does not exist than a new one is generated with the same name
6873
pub_key_path: "{{ssh_key_path}}/{{ssh_key_name}}.pub"
6974

75+
#path to the private key used by vagrant and user to access the vagrant machines
76+
prv_key_path: "{{ssh_key_path}}/{{ssh_key_name}}"
77+
7078
#Amount of RAM memory for a single VM
7179
virtual_memory_size: 4096
7280

tests/ansible_vagrant/kubernetes-playbooks/roles/bootstrap/tasks/main.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717
- name: Refresh inventory to ensure that the new generated one is used
1818
meta: refresh_inventory
1919

20+
- name: Creating host_vars directory if not present
21+
file:
22+
path: ./host_vars
23+
state: directory
24+
mode: '0755'
25+
2026
- name: Find and save in a local variable all host_vars files
2127
find:
2228
paths: ./host_vars

tests/ansible_vagrant/kubernetes-playbooks/roles/bootstrap/templates/VagrantFile.j2

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ Vagrant.configure("2") do |config|
99
v.cpus = {{ virtual_cpus }}
1010
end
1111
{% for node_ip in k8s_master_nodes_ips %}
12-
config.vm.define "k8s-master" do |master|
12+
config.vm.define "{{ k8s_master_node_prefix }}-{{ loop.index }}" do |master|
1313
master.vm.box = IMAGE_NAME
1414
# change the bridge interface to match the one on your host machine
15-
master.vm.network "public_network", bridge: BRIDGE_NIC, ip: "{{ node_ip }}"
15+
master.vm.network "public_network", bridge: BRIDGE_NIC, ip: "{{ node_ip }}", netmask: "{{ netmask }}"
1616
master.vm.hostname = "k8s-master"
1717
master.vm.provision "ansible" do |ansible|
1818
# Configures the ssh-key
@@ -25,10 +25,10 @@ Vagrant.configure("2") do |config|
2525
{% endfor %}
2626

2727
{% for node_ip in k8s_worker_nodes_ips %}
28-
config.vm.define "node-{{ loop.index }}" do |node|
28+
config.vm.define "{{ k8s_worker_node_prefix }}{{ loop.index }}" do |node|
2929
node.vm.box = IMAGE_NAME
3030
# change the bridge interface to match the one on your host machine
31-
node.vm.network "public_network", bridge: BRIDGE_NIC, ip: "{{ node_ip }}"
31+
node.vm.network "public_network", bridge: BRIDGE_NIC, ip: "{{ node_ip }}", netmask: "{{ netmask }}"
3232
node.vm.hostname = "node-{{ loop.index }}"
3333
node.vm.provision "ansible" do |ansible|
3434
# Configures the ssh-key

tests/ansible_vagrant/kubernetes-playbooks/roles/bootstrap/templates/inventory.ini.j2

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@
1010
{{ k8s_worker_node_prefix}}{{ loop.index }}
1111
{% endfor %}
1212

13+
#should work also for the users who do not use an ssh-agent
14+
[k8s_master_nodes:vars]
15+
ansible_ssh_private_key_file={{prv_key_path}}
16+
17+
#should work also for the users who do not use an ssh-agent
18+
[k8s_worker_nodes:vars]
19+
ansible_ssh_private_key_file={{prv_key_path}}
20+
1321
## All nodes
1422
[all_nodes:children]
1523
k8s_master_nodes

tests/ansible_vagrant/kubernetes-playbooks/roles/k8s-master/tasks/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
state: restarted
7171

7272
- name: Initialize the Kubernetes cluster using kubeadm
73-
command: kubeadm init --apiserver-advertise-address="{{ node_ip }}" --apiserver-cert-extra-sans="{{ node_ip }}" --node-name k8s-master --pod-network-cidr="{{ pod_network_cidr }}"
73+
command: kubeadm init --apiserver-advertise-address="{{ node_ip }}" --apiserver-cert-extra-sans="{{ node_ip }}" --node-name k8s-master --pod-network-cidr="{{ pod_network_cidr }}" --service-cidr="{{ service_cidr }}"
7474

7575
- name: Enable the kernel to pass bridged IPv4 traffic to iptables' chains and the forwarding
7676
command: "{{ item }}"

tests/ansible_vagrant/kubernetes-playbooks/roles/vagrant-network-config/templates/50-vagrant.yaml.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ network:
77
{% if hostvars[inventory_hostname]['ansible_'~interface|replace('-','_')]['ipv4']['address'] | default("Not defined") == node_ip %}
88
{{ interface }}:
99
dhcp4: true
10-
addresses: [{{node_ip}}/24] #node_ip defined per host in host_vars
10+
addresses: [{{node_ip}}/23] #node_ip defined per host in host_vars
1111
{% endif %}
1212
{% endfor %}

0 commit comments

Comments
 (0)