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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mirror
Kubespray
Commits
16369795
Unverified
Commit
16369795
authored
11 months ago
by
Kubernetes Prow Robot
Committed by
GitHub
11 months ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #11527 from VannTen/feat/vagrant_multi_inv
Cleanup Vagrantfile and allow to use multiples inventories
parents
893e9cb1
4bf2d7a2
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
Vagrantfile
+6
-18
6 additions, 18 deletions
Vagrantfile
docs/developers/vagrant.md
+30
-57
30 additions, 57 deletions
docs/developers/vagrant.md
tests/Makefile
+2
-1
2 additions, 1 deletion
tests/Makefile
with
38 additions
and
76 deletions
Vagrantfile
+
6
−
18
View file @
16369795
...
@@ -55,6 +55,8 @@ $subnet ||= "172.18.8"
...
@@ -55,6 +55,8 @@ $subnet ||= "172.18.8"
$subnet_ipv6
||=
"fd3c:b398:0698:0756"
$subnet_ipv6
||=
"fd3c:b398:0698:0756"
$os
||=
"ubuntu2004"
$os
||=
"ubuntu2004"
$network_plugin
||=
"flannel"
$network_plugin
||=
"flannel"
$inventory
||=
"inventory/sample"
$inventories
||=
[
$inventory
]
# Setting multi_networking to true will install Multus: https://github.com/k8snetworkplumbingwg/multus-cni
# Setting multi_networking to true will install Multus: https://github.com/k8snetworkplumbingwg/multus-cni
$multi_networking
||=
"False"
$multi_networking
||=
"False"
$download_run_once
||=
"True"
$download_run_once
||=
"True"
...
@@ -93,19 +95,6 @@ if ! SUPPORTED_OS.key?($os)
...
@@ -93,19 +95,6 @@ if ! SUPPORTED_OS.key?($os)
end
end
$box
=
SUPPORTED_OS
[
$os
][
:box
]
$box
=
SUPPORTED_OS
[
$os
][
:box
]
# if $inventory is not set, try to use example
$inventory
=
"inventory/sample"
if
!
$inventory
$inventory
=
File
.
absolute_path
(
$inventory
,
File
.
dirname
(
__FILE__
))
# if $inventory has a hosts.ini file use it, otherwise copy over
# vars etc to where vagrant expects dynamic inventory to be
if
!
File
.
exist?
(
File
.
join
(
File
.
dirname
(
$inventory
),
"hosts.ini"
))
$vagrant_ansible
=
File
.
join
(
File
.
absolute_path
(
$vagrant_dir
),
"provisioners"
,
"ansible"
)
FileUtils
.
mkdir_p
(
$vagrant_ansible
)
if
!
File
.
exist?
(
$vagrant_ansible
)
$vagrant_inventory
=
File
.
join
(
$vagrant_ansible
,
"inventory"
)
FileUtils
.
rm_f
(
$vagrant_inventory
)
FileUtils
.
ln_s
(
$inventory
,
$vagrant_inventory
)
end
if
Vagrant
.
has_plugin?
(
"vagrant-proxyconf"
)
if
Vagrant
.
has_plugin?
(
"vagrant-proxyconf"
)
$no_proxy
=
ENV
[
'NO_PROXY'
]
||
ENV
[
'no_proxy'
]
||
"127.0.0.1,localhost"
$no_proxy
=
ENV
[
'NO_PROXY'
]
||
ENV
[
'no_proxy'
]
||
"127.0.0.1,localhost"
...
@@ -286,14 +275,13 @@ Vagrant.configure("2") do |config|
...
@@ -286,14 +275,13 @@ Vagrant.configure("2") do |config|
ansible
.
playbook
=
$playbook
ansible
.
playbook
=
$playbook
ansible
.
compatibility_mode
=
"2.0"
ansible
.
compatibility_mode
=
"2.0"
ansible
.
verbose
=
$ansible_verbosity
ansible
.
verbose
=
$ansible_verbosity
$ansible_inventory_path
=
File
.
join
(
$inventory
,
"hosts.ini"
)
if
File
.
exist?
(
$ansible_inventory_path
)
ansible
.
inventory_path
=
$ansible_inventory_path
end
ansible
.
become
=
true
ansible
.
become
=
true
ansible
.
limit
=
"all,localhost"
ansible
.
limit
=
"all,localhost"
ansible
.
host_key_checking
=
false
ansible
.
host_key_checking
=
false
ansible
.
raw_arguments
=
[
"--forks=
#{
$num_instances
}
"
,
"--flush-cache"
,
"-e ansible_become_pass=vagrant"
]
ansible
.
raw_arguments
=
[
"--forks=
#{
$num_instances
}
"
,
"--flush-cache"
,
"-e ansible_become_pass=vagrant"
]
+
$inventories
.
map
{
|
inv
|
[
"-i"
,
inv
]}.
flatten
ansible
.
host_vars
=
host_vars
ansible
.
host_vars
=
host_vars
ansible
.
extra_vars
=
$extra_vars
ansible
.
extra_vars
=
$extra_vars
if
$ansible_tags
!=
""
if
$ansible_tags
!=
""
...
...
This diff is collapsed.
Click to expand it.
docs/developers/vagrant.md
+
30
−
57
View file @
16369795
...
@@ -29,7 +29,26 @@ You can override the default settings in the `Vagrantfile` either by
...
@@ -29,7 +29,26 @@ You can override the default settings in the `Vagrantfile` either by
directly modifying the
`Vagrantfile`
or through an override file.
directly modifying the
`Vagrantfile`
or through an override file.
In the same directory as the
`Vagrantfile`
, create a folder called
In the same directory as the
`Vagrantfile`
, create a folder called
`vagrant`
and create
`config.rb`
file in it.
`vagrant`
and create
`config.rb`
file in it.
An example of how to configure this file is given below.
Example:
```
ruby
# vagrant/config.rb
$instance_name_prefix
=
"kub"
$vm_cpus
=
1
$num_instances
=
3
$os
=
"centos8-bento"
$subnet
=
"10.0.20"
$network_plugin
=
"flannel"
$extra_vars
=
{
dns_domain:
my
.
custom
.
domain
}
# or
$extra_vars
=
"path/to/extra/vars/file.yml"
```
For all available options look at the Vagrantfile (search for "CONFIG")
## Use alternative OS for Vagrant
## Use alternative OS for Vagrant
...
@@ -57,73 +76,33 @@ see [download documentation](/docs/advanced/downloads.md).
...
@@ -57,73 +76,33 @@ see [download documentation](/docs/advanced/downloads.md).
## Example use of Vagrant
## Example use of Vagrant
The following is an example of setting up and running kubespray using
`vagrant`
.
The following is an example of setting up and running kubespray using
`vagrant`
.
For repeated runs, you could save the script to a file in the root of the
Customize your settings as shown, above, then run the commands:
kubespray and run it by executing
`source <name_of_the_file>`
.
```
ShellSession
```
ShellSession
# use virtualenv to install all python requirements
# use virtualenv to install all python requirements
VENVDIR=venv
VENVDIR=venv
virtualenv --python=/usr/bin/python3.7 $VENVDIR
$ virtualenv --python=/usr/bin/python3.7 $VENVDIR
source $VENVDIR/bin/activate
$ source $VENVDIR/bin/activate
pip install -r requirements.txt
$ pip install -r requirements.txt
# prepare an inventory to test with
INV=inventory/my_lab
rm -rf ${INV}.bak &> /dev/null
mv ${INV} ${INV}.bak &> /dev/null
cp -a inventory/sample ${INV}
rm -f ${INV}/hosts.ini
# customize the vagrant environment
mkdir vagrant
cat << EOF > vagrant/config.rb
\$instance_name_prefix = "kub"
\$vm_cpus = 1
\$num_instances = 3
\$os = "centos8-bento"
\$subnet = "10.0.20"
\$network_plugin = "flannel"
\$inventory = "$INV"
\$shared_folders = { 'temp/docker_rpms' => "/var/cache/yum/x86_64/7/docker-ce/packages" }
\$extra_vars = {
dns_domain: my.custom.domain
}
# or
\$extra_vars = "path/to/extra/vars/file.yml"
EOF
# make the rpm cache
$ vagrant up
mkdir -p temp/docker_rpms
vagrant up
# Access the cluster
$ export INV=.vagrant/provisionners/ansible/inventory
# make a copy of the downloaded docker rpm, to speed up the next provisioning run
$ export KUBECONFIG=${INV}/artifacts/admin.conf
scp kub-1:/var/cache/yum/x86_64/7/docker-ce/packages/* temp/docker_rpms/
# copy kubectl access configuration in place
mkdir $HOME/.kube/ &> /dev/null
ln -s $PWD/$INV/artifacts/admin.conf $HOME/.kube/config
# make the kubectl binary available
# make the kubectl binary available
sudo ln -s $PWD/$INV/artifacts/kubectl /usr/local/bin/kubectl
$ export PATH=$PATH:$PWD/$INV/artifacts
#or
export PATH=$PATH:$PWD/$INV/artifacts
```
```
If a vagrant run failed and you've made some changes to fix the issue causing
If a vagrant run failed and you've made some changes to fix the issue causing
the fail, here is how you would re-run ansible:
the fail, here is how you would re-run ansible:
```
ShellSession
```
ShellSession
ansible-playbook -vvv -i .
vagrant
/
provision
ers/ansible/inventory/vagrant_ansible_inventory cluster.yml
vagrant
provision
```
```
If all went well, you check if it's all working as expected:
If all went well, you check if it's all working as expected:
```
ShellSession
kubectl get nodes
```
The output should look like this:
```
ShellSession
```
ShellSession
$ kubectl get nodes
$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
NAME STATUS ROLES AGE VERSION
...
@@ -134,12 +113,6 @@ kub-3 Ready <none> 3m7s v1.22.5
...
@@ -134,12 +113,6 @@ kub-3 Ready <none> 3m7s v1.22.5
Another nice test is the following:
Another nice test is the following:
```
ShellSession
kubectl get pods --all-namespaces -o wide
```
Which should yield something like the following:
```
ShellSession
```
ShellSession
$ kubectl get pods --all-namespaces -o wide
$ kubectl get pods --all-namespaces -o wide
NAMESPACE NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
NAMESPACE NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
...
...
This diff is collapsed.
Click to expand it.
tests/Makefile
+
2
−
1
View file @
16369795
...
@@ -35,7 +35,8 @@ cleanup-packet:
...
@@ -35,7 +35,8 @@ cleanup-packet:
create-vagrant
:
create-vagrant
:
vagrant up
vagrant up
cp
$(
CI_PROJECT_DIR
)
/inventory/sample/vagrant_ansible_inventory
$(
INVENTORY
)
cp
$(
CI_PROJECT_DIR
)
/.vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory
$(
INVENTORY
)
delete-vagrant
:
delete-vagrant
:
vagrant destroy
-f
vagrant destroy
-f
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