config.vm.usable_port_range applies globally
Vagrant version
Vagrant 2.2.19
Host operating system
Linux Mint 20.3
Guest operating system
Ubuntu 22.04 LTS
Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
ENV['VAGRANT_NO_PARALLEL'] = 'yes'
LBCount = 1
MasterCount = 2
NodeCount = 2
Vagrant.configure(2) do |config|
config.vm.network "forwarded_port", guest: 5910, host: 5910, auto_correct: true
config.vm.usable_port_range = 5910..5920
config.vm.box = "bento/ubuntu-22.04" #"ubuntu/focal64"
if Vagrant.has_plugin?("vagrant-vbguest") then
config.vbguest.auto_update = false
end
# Load Balancer Node(s)
(1..LBCount).each do |i|
config.vm.define "staging-lb#{i}" do |lb|
lb.vm.network "private_network", ip: "192.168.56.100"
lb.vm.provider "virtualbox" do |v|
if LBCount == 1 then
v.name = "staging-lb"
lb.vm.hostname = "staging-lb.introvert.beaslnet.space"
else
v.name = "staging-lb#{i}"
lb.vm.hostname = "staging-lb#{i}.introvert.beaslnet.space"
end
v.memory = 1024
v.cpus = 1
end
end
end
end
Vagrant.configure(2) do |config|
config.vm.box = "bento/ubuntu-22.04" #"ubuntu/focal64"
if Vagrant.has_plugin?("vagrant-vbguest") then
config.vbguest.auto_update = false
end
# Kubernetes Master Nodes
(1..MasterCount).each do |i|
config.vm.define "k8s-StageC1M#{i}" do |masternode|
masternode.vm.hostname = "k8s-StageC1M#{i}.introvert.beaslnet.space"
masternode.vm.network "private_network", ip: "192.168.56.10#{i}"
masternode.vm.provider "virtualbox" do |v|
v.name = "k8s-StageC1M#{i}"
v.memory = 2048
v.cpus = 2
end
end
end
end
Debug output
https://gist.github.com/MBfromOK/75a59c24e4fdc6a93acfd30fe231d8b1
Expected behavior
This particular port mapping should have detected a collision and then used the custom port range to shift just this port mapping as needed This port mapping: Machine 1 - Guest: 5910 Host: 5910 Machine 2 - Guest: 5910 Host: 5911 Machine 3 - Guest: 5910 Host: 5912
ssh: Machine 1 - Guest: 22 Host: 2222 Machine 2 - Guest: 22 Host: 2223 Machine 3 - Guest: 22 Host: 2224
Actual behavior
Machines provision as expected, but now other colliding forwarded ports are shifted into this range ie the ssh auto correct shifts from 2200 range to 59[10-20] range specified for this port mapping
This port mapping: Machine 1 - Guest: 5910 Host: 5910 Machine 2 - Guest: 5910 Host: 5911 Machine 3 - Guest: 5910 Host: 5913
ssh: Machine 1 - Guest: 22 Host: 2222 Machine 2 - Guest: 22 Host: 5912 Machine 3 - Guest: 22 Host: 5914
Steps to reproduce
- vagrant reload or vagrant destroy -f
- vagrant up
References - related (side issue)
- GH-12800
Hi there,
This behavior is working as intended. The usable port range setting is used to provide the valid list of available ports which can be used for forwarding. The behavior you are expecting is an isolated range applied to a single port forward entry, which is not currently supported within Vagrant.
Cheers!
I'd second @MBfromOK expectation and, inspired by https://github.com/pr3sto/vagrant-port-range, I'd request the forwarded_port host parameter to support a range value when auto_correct is enabled.
Thanks in advance :)