Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
Kubespray
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Model registry
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mirror
Kubespray
Commits
9d0786cb
Commit
9d0786cb
authored
6 years ago
by
Johnny Halfmoon
Committed by
Antoine Legrand
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
cleaned up vagrantfile (#3717)
parent
53bde23a
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
Vagrantfile
+79
-71
79 additions, 71 deletions
Vagrantfile
with
79 additions
and
71 deletions
Vagrantfile
+
79
−
71
View file @
9d0786cb
# -*- mode: ruby -*-
# -*- mode: ruby -*-
# # vi: set ft=ruby :
# # vi: set ft=ruby :
# For help on using kubespray with vagrant, check out docs/vagrant.md
require
'fileutils'
require
'fileutils'
Vagrant
.
require_version
">= 2.0.0"
Vagrant
.
require_version
">= 2.0.0"
...
@@ -19,9 +21,10 @@ SUPPORTED_OS = {
...
@@ -19,9 +21,10 @@ SUPPORTED_OS = {
"ubuntu1604"
=>
{
box:
"generic/ubuntu1604"
,
user:
"vagrant"
},
"ubuntu1604"
=>
{
box:
"generic/ubuntu1604"
,
user:
"vagrant"
},
"ubuntu1804"
=>
{
box:
"generic/ubuntu1804"
,
user:
"vagrant"
},
"ubuntu1804"
=>
{
box:
"generic/ubuntu1804"
,
user:
"vagrant"
},
"centos"
=>
{
box:
"centos/7"
,
user:
"vagrant"
},
"centos"
=>
{
box:
"centos/7"
,
user:
"vagrant"
},
"centos-bento"
=>
{
box:
"bento/centos-7.5"
,
user:
"vagrant"
},
"fedora"
=>
{
box:
"fedora/28-cloud-base"
,
user:
"vagrant"
},
"fedora"
=>
{
box:
"fedora/28-cloud-base"
,
user:
"vagrant"
},
"opensuse"
=>
{
box:
"opensuse/openSUSE-42.3-x86_64"
,
use:
"vagrant"
},
"opensuse"
=>
{
box:
"opensuse/openSUSE-42.3-x86_64"
,
use
r
:
"vagrant"
},
"opensuse-tumbleweed"
=>
{
box:
"opensuse/openSUSE-Tumbleweed-x86_64"
,
use:
"vagrant"
},
"opensuse-tumbleweed"
=>
{
box:
"opensuse/openSUSE-Tumbleweed-x86_64"
,
use
r
:
"vagrant"
},
}
}
# Defaults for config options defined in CONFIG
# Defaults for config options defined in CONFIG
...
@@ -50,8 +53,6 @@ $kube_node_instances_with_disks_number = 2
...
@@ -50,8 +53,6 @@ $kube_node_instances_with_disks_number = 2
$playbook
=
"cluster.yml"
$playbook
=
"cluster.yml"
$local_release_dir
=
"/vagrant/temp"
host_vars
=
{}
host_vars
=
{}
if
File
.
exist?
(
CONFIG
)
if
File
.
exist?
(
CONFIG
)
...
@@ -60,13 +61,13 @@ end
...
@@ -60,13 +61,13 @@ end
$box
=
SUPPORTED_OS
[
$os
][
:box
]
$box
=
SUPPORTED_OS
[
$os
][
:box
]
# if $inventory is not set, try to use example
# if $inventory is not set, try to use example
$inventory
=
File
.
join
(
File
.
dirname
(
__FILE__
),
"inventory"
,
"sample"
)
if
!
$inventory
$inventory
=
"inventory/sample"
if
!
$inventory
$inventory
=
File
.
absolute_path
(
$inventory
,
File
.
dirname
(
__FILE__
))
# if $inventory has a hosts file use it, otherwise copy over vars etc
# if $inventory has a hosts.ini file use it, otherwise copy over
# to where vagrant expects dynamic inventory to be.
# vars etc to where vagrant expects dynamic inventory to be
if
!
File
.
exist?
(
File
.
join
(
File
.
dirname
(
$inventory
),
"hosts"
))
if
!
File
.
exist?
(
File
.
join
(
File
.
dirname
(
$inventory
),
"hosts.ini"
))
$vagrant_ansible
=
File
.
join
(
File
.
dirname
(
__FILE__
),
".vagrant"
,
$vagrant_ansible
=
File
.
join
(
File
.
dirname
(
__FILE__
),
".vagrant"
,
"provisioners"
,
"ansible"
)
"provisioners"
,
"ansible"
)
FileUtils
.
mkdir_p
(
$vagrant_ansible
)
if
!
File
.
exist?
(
$vagrant_ansible
)
FileUtils
.
mkdir_p
(
$vagrant_ansible
)
if
!
File
.
exist?
(
$vagrant_ansible
)
if
!
File
.
exist?
(
File
.
join
(
$vagrant_ansible
,
"inventory"
))
if
!
File
.
exist?
(
File
.
join
(
$vagrant_ansible
,
"inventory"
))
FileUtils
.
ln_s
(
$inventory
,
File
.
join
(
$vagrant_ansible
,
"inventory"
))
FileUtils
.
ln_s
(
$inventory
,
File
.
join
(
$vagrant_ansible
,
"inventory"
))
...
@@ -81,80 +82,60 @@ if Vagrant.has_plugin?("vagrant-proxyconf")
...
@@ -81,80 +82,60 @@ if Vagrant.has_plugin?("vagrant-proxyconf")
end
end
Vagrant
.
configure
(
"2"
)
do
|
config
|
Vagrant
.
configure
(
"2"
)
do
|
config
|
# always use Vagrants insecure key
config
.
ssh
.
insert_key
=
false
config
.
vm
.
box
=
$box
config
.
vm
.
box
=
$box
if
SUPPORTED_OS
[
$os
].
has_key?
:box_url
if
SUPPORTED_OS
[
$os
].
has_key?
:box_url
config
.
vm
.
box_url
=
SUPPORTED_OS
[
$os
][
:box_url
]
config
.
vm
.
box_url
=
SUPPORTED_OS
[
$os
][
:box_url
]
end
end
config
.
ssh
.
username
=
SUPPORTED_OS
[
$os
][
:user
]
config
.
ssh
.
username
=
SUPPORTED_OS
[
$os
][
:user
]
# plugin conflict
# plugin conflict
if
Vagrant
.
has_plugin?
(
"vagrant-vbguest"
)
then
if
Vagrant
.
has_plugin?
(
"vagrant-vbguest"
)
then
config
.
vbguest
.
auto_update
=
false
config
.
vbguest
.
auto_update
=
false
end
end
(
1
..
$num_instances
).
each
do
|
i
|
config
.
vm
.
define
vm_name
=
"%s-%02d"
%
[
$instance_name_prefix
,
i
]
do
|
config
|
config
.
vm
.
hostname
=
vm_name
if
Vagrant
.
has_plugin?
(
"vagrant-proxyconf"
)
# always use Vagrants insecure key
config
.
proxy
.
http
=
ENV
[
'HTTP_PROXY'
]
||
ENV
[
'http_proxy'
]
||
""
config
.
ssh
.
insert_key
=
false
config
.
proxy
.
https
=
ENV
[
'HTTPS_PROXY'
]
||
ENV
[
'https_proxy'
]
||
""
config
.
proxy
.
no_proxy
=
$no_proxy
end
if
$expose_docker_tcp
(
1
..
$num_instances
).
each
do
|
i
|
config
.
vm
.
network
"forwarded_port"
,
guest:
2375
,
host:
(
$expose_docker_tcp
+
i
-
1
),
auto_correct:
true
config
.
vm
.
define
vm_name
=
"%s-%01d"
%
[
$instance_name_prefix
,
i
]
do
|
node
|
end
$forwarded_ports
.
each
do
|
guest
,
host
|
node
.
vm
.
hostname
=
vm_name
config
.
vm
.
network
"forwarded_port"
,
guest:
guest
,
host:
host
,
auto_correct:
true
if
Vagrant
.
has_plugin?
(
"vagrant-proxyconf"
)
node
.
proxy
.
http
=
ENV
[
'HTTP_PROXY'
]
||
ENV
[
'http_proxy'
]
||
""
node
.
proxy
.
https
=
ENV
[
'HTTPS_PROXY'
]
||
ENV
[
'https_proxy'
]
||
""
node
.
proxy
.
no_proxy
=
$no_proxy
end
end
[
"vmware_fusion"
,
"vmware_workstation"
].
each
do
|
vmware
|
[
"vmware_fusion"
,
"vmware_workstation"
].
each
do
|
vmware
|
config
.
vm
.
provider
vmware
do
|
v
|
node
.
vm
.
provider
vmware
do
|
v
|
v
.
vmx
[
'memsize'
]
=
$vm_memory
v
.
vmx
[
'memsize'
]
=
$vm_memory
v
.
vmx
[
'numvcpus'
]
=
$vm_cpus
v
.
vmx
[
'numvcpus'
]
=
$vm_cpus
end
end
end
end
config
.
vm
.
synced_folder
"."
,
"/vagrant"
,
type:
"rsync"
,
rsync__args:
[
'--verbose'
,
'--archive'
,
'--delete'
,
'-z'
]
node
.
vm
.
provider
:virtualbox
do
|
vb
|
$shared_folders
.
each
do
|
src
,
dst
|
config
.
vm
.
synced_folder
src
,
dst
,
type:
"rsync"
,
rsync__args:
[
'--verbose'
,
'--archive'
,
'--delete'
,
'-z'
]
end
config
.
vm
.
provider
:virtualbox
do
|
vb
|
vb
.
gui
=
$vm_gui
vb
.
memory
=
$vm_memory
vb
.
memory
=
$vm_memory
vb
.
cpus
=
$vm_cpus
vb
.
cpus
=
$vm_cpus
vb
.
gui
=
$vm_gui
vb
.
linked_clone
=
true
end
end
config
.
vm
.
provider
:libvirt
do
|
lv
|
node
.
vm
.
provider
:libvirt
do
|
lv
|
lv
.
memory
=
$vm_memory
lv
.
memory
=
$vm_memory
lv
.
cpus
=
$vm_cpus
lv
.
default_prefix
=
'kubespray'
# Fix kernel panic on fedora 28
# Fix kernel panic on fedora 28
if
$os
==
"fedora"
if
$os
==
"fedora"
lv
.
cpu_mode
=
"host-passthrough"
lv
.
cpu_mode
=
"host-passthrough"
end
end
end
end
ip
=
"
#{
$subnet
}
.
#{
i
+
100
}
"
host_vars
[
vm_name
]
=
{
"ip"
:
ip
,
"local_release_dir"
=>
$local_release_dir
,
"download_run_once"
:
"False"
,
"kube_network_plugin"
:
$network_plugin
,
"kube_network_plugin_multus"
:
$multi_networking
}
config
.
vm
.
network
:private_network
,
ip:
ip
# Disable swap for each vm
config
.
vm
.
provision
"shell"
,
inline:
"swapoff -a"
if
$kube_node_instances_with_disks
if
$kube_node_instances_with_disks
# Libvirt
# Libvirt
driverletters
=
(
'a'
..
'z'
).
to_a
driverletters
=
(
'a'
..
'z'
).
to_a
config
.
vm
.
provider
:libvirt
do
|
lv
|
node
.
vm
.
provider
:libvirt
do
|
lv
|
# always make /dev/sd{a/b/c} so that CI can ensure that
# always make /dev/sd{a/b/c} so that CI can ensure that
# virtualbox and libvirt will have the same devices to use for OSDs
# virtualbox and libvirt will have the same devices to use for OSDs
(
1
..
$kube_node_instances_with_disks_number
).
each
do
|
d
|
(
1
..
$kube_node_instances_with_disks_number
).
each
do
|
d
|
...
@@ -163,24 +144,51 @@ Vagrant.configure("2") do |config|
...
@@ -163,24 +144,51 @@ Vagrant.configure("2") do |config|
end
end
end
end
# Only execute once the Ansible provisioner,
if
$expose_docker_tcp
# when all the machines are up and ready.
node
.
vm
.
network
"forwarded_port"
,
guest:
2375
,
host:
(
$expose_docker_tcp
+
i
-
1
),
auto_correct:
true
end
$forwarded_ports
.
each
do
|
guest
,
host
|
node
.
vm
.
network
"forwarded_port"
,
guest:
guest
,
host:
host
,
auto_correct:
true
end
node
.
vm
.
synced_folder
"."
,
"/vagrant"
,
disabled:
false
,
type:
"rsync"
,
rsync__args:
[
'--verbose'
,
'--archive'
,
'--delete'
,
'-z'
]
,
rsync__exclude:
[
'.git'
,
'venv'
]
$shared_folders
.
each
do
|
src
,
dst
|
node
.
vm
.
synced_folder
src
,
dst
,
type:
"rsync"
,
rsync__args:
[
'--verbose'
,
'--archive'
,
'--delete'
,
'-z'
]
end
ip
=
"
#{
$subnet
}
.
#{
i
+
100
}
"
node
.
vm
.
network
:private_network
,
ip:
ip
# Disable swap for each vm
node
.
vm
.
provision
"shell"
,
inline:
"swapoff -a"
host_vars
[
vm_name
]
=
{
"ip"
:
ip
,
"kube_network_plugin"
:
$network_plugin
,
"kube_network_plugin_multus"
:
$multi_networking
,
"docker_keepcache"
:
"1"
,
"download_run_once"
:
"True"
,
"download_localhost"
:
"False"
}
# Only execute the Ansible provisioner once, when all the machines are up and ready.
if
i
==
$num_instances
if
i
==
$num_instances
config
.
vm
.
provision
"ansible"
do
|
ansible
|
node
.
vm
.
provision
"ansible"
do
|
ansible
|
ansible
.
playbook
=
$playbook
ansible
.
playbook
=
$playbook
if
File
.
exist?
(
File
.
join
(
File
.
dirname
(
$inventory
)
,
"hosts"
))
if
File
.
exist?
(
File
.
join
(
$inventory
,
"hosts
.ini
"
))
ansible
.
inventory_path
=
$inventory
ansible
.
inventory_path
=
$inventory
end
end
ansible
.
become
=
true
ansible
.
become
=
true
ansible
.
limit
=
"all"
ansible
.
limit
=
"all"
ansible
.
host_key_checking
=
false
ansible
.
host_key_checking
=
false
ansible
.
raw_arguments
=
[
"--forks=
#{
$num_instances
}
"
,
"--flush-cache"
]
ansible
.
raw_arguments
=
[
"--forks=
#{
$num_instances
}
"
,
"--flush-cache"
,
"--ask-become-pass"
]
ansible
.
host_vars
=
host_vars
ansible
.
host_vars
=
host_vars
#ansible.tags = ['download']
#ansible.tags = ['download']
ansible
.
groups
=
{
ansible
.
groups
=
{
"etcd"
=>
[
"
#{
$instance_name_prefix
}
-
0
[1:
#{
$etcd_instances
}
]"
],
"etcd"
=>
[
"
#{
$instance_name_prefix
}
-[1:
#{
$etcd_instances
}
]"
],
"kube-master"
=>
[
"
#{
$instance_name_prefix
}
-
0
[1:
#{
$kube_master_instances
}
]"
],
"kube-master"
=>
[
"
#{
$instance_name_prefix
}
-[1:
#{
$kube_master_instances
}
]"
],
"kube-node"
=>
[
"
#{
$instance_name_prefix
}
-
0
[1:
#{
$kube_node_instances
}
]"
],
"kube-node"
=>
[
"
#{
$instance_name_prefix
}
-[1:
#{
$kube_node_instances
}
]"
],
"k8s-cluster:children"
=>
[
"kube-master"
,
"kube-node"
],
"k8s-cluster:children"
=>
[
"kube-master"
,
"kube-node"
],
}
}
end
end
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment