Kubernetes networking issue bridged adapter - networking

I am working on setting up a multi-node, multi hardware server Kubernetes Cluster.
I am using Calico and Kubeadm.
So I am trying to use a bridge adapter within VMS to allow visibility over the network to a remote server using promiscuous mode and a static IP address.
The issue is when the VM is created, I cannot ping into it.
I have used to initialize kubeadm:
kubeadm init --apiserver-advertise-address="192.168.2.50" --apiserver-cert-extra-sans="192.168.2.50" --node-name master --pod-network-cidr=192.168.0.0/16
I am asking if there's an additional networking config to enable ping the Vms successfully.
This is the code I've used into the vagrantfile:
s.vm.provider "virtualbox" do |v|
v.name = vM_NAME
v.customize ['modifyvm', :id, '--nictype3', 'Am79C973']
v.customize ['modifyvm', :id, '--nicpromisc3', 'allow-all']
v.memory = 2048
v.gui = false
end
s.vm.network "private_network", ip: "192.168.2.#{i + m - 1}",# netmask: "255.255.255.0",
auto_config: true,
virtualbox__intnet: "k8s-net"
s.vm.network "public_network", bridge: "Intel(R) Ethernet Connection I217-LM", ip: "192.168.2.#{i + m -1}",# netmask: "255.255.255.0",
auto_config: true
Thank you.

While doing kubeadm init add the PUBLIC IP and PORT as part of --control-plane-endpoint parameter.
sudo kubeadm init --apiserver-advertise-address=x.x.x.x --apiserver-cert-extra-sans=x.x.x.x **--control-plane-endpoint=y.y.y.y** --node-name master --pod-network-cidr=z.z.z.z/16
Worker nodes over the network can join the master node using the new generated join-command.

Related

Vagrant Setup with two boxes connected via a third box simulating a switch/bridge

I would like to have a setup as depicted here:
I would like for the two VMs to only be able to talk to each other via a third container simulating a switch, or just a bridge for starters. I care about the host network or outside connectivity only to the extend that I want to ssh into each box.
I tried to build on the tutorial for multiple machines as follows:
Vagrant.configure("2") do |config|
config.vm.define "switch" do |switch|
switch.vm.box = "hashicorp/bionic64"
switch.vm.network "public_network", ip: "192.168.50.6"
end
config.vm.define "interlocking" do |interlocking|
interlocking.vm.box = "hashicorp/bionic64"
interlocking.vm.network "public_network", ip: "192.168.50.5", bridge: "192.168.50.6"
end
config.vm.define "point" do |point|
point.vm.box = "hashicorp/bionic64"
point.vm.network "public_network", ip: "192.168.50.4", bridge: "192.168.50.6"
end
end
But I don't know how to stop the two VMs from just finding each other in the network right away without using the bridge. Can somebody point me in the right direction?
A good way to do this outside of vagrant would also be fine.
I ended up using OpenVSwitch with this configuration in ansible:
- hosts: all
become: true
tasks:
- name: install wireshark
apt:
name: wireshark
- name: install tshark
apt:
name: tshark
- name: install Open vSwitch
apt:
name: openvswitch-switch
- name: create bridge Interface br0
openvswitch_bridge:
bridge: br0
- name: bridging ethNode1
openvswitch_port:
bridge: br0
port: eth1
- name: bridgeing ethNode2
openvswitch_port:
bridge: br0
port: eth2
- name: bridgeing ethNode3
openvswitch_port:
bridge: br0
port: eth3

vagrant Multipe networking

I have installed magento 2 in vagrant with in docker machine, this docker machine have port forwarding concepts, I set private network, with nat and host-only, Now only access magento 2 in hostmachine.
I need to access locally connected remote machine also so, i try to change private network to public network with bridge.
Vagrant File:
Vagrant.configure("2") do |config|
config.vm.box = "machine"
config.ssh.username = "vagrant"
config.vm.hostname = "www.myhost.net"
config.ssh.forward_agent = "true"
config.vm.network "public_network", ip: "192.168.56.40"
config.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--memory", "2048"]
end
if Vagrant::Util::Platform.windows?
config.vm.synced_folder ".", "/vagrant", :mount_options => ["dmode=777", "fmode=777"]
else
config.vm.synced_folder ".", "/vagrant", :nfs => { :mount_options => ["dmode=777", "fmode=777"] }
end
end
But, throw
NFS requires a host-only network to be created.
Please add a host-only network to the machine (with either DHCP or a
static IP) for NFS to work.
I need to add Multiple Network to vagrant
nat
host-onloy(for nfs)
bridge (for access remote machine)
Suggest me How to resolve this.
You need to change your public_network to private_network for nfs to work
If you are using the VirtualBox provider, you will also need to make sure you have a private network set up. This is due to a limitation of VirtualBox's built-in networking. With VMware, you do not need this.
so :
you can change to VMWare (but you have some additional fees)
you do not use nfs
you can setup another network interface for bridge and use this network interface if you need to connect to the remote machine, you should be able to ping (ping -I ethX mylocalmachine) but I am not sure how to work to get connection in

How do you create a host-only network in Vagrant for NFS?

I cannot find any information in the docs about this error message:
NFS requires a host-only network to be created.
Please add a host-only network to the machine (with either DHCP or a
static IP) for NFS to work.
Here is my Vagrant config:
Vagrant.configure(2) do |config|
config.vm.box = "localbox"
config.vm.network "public_network", hostonly: "192.168.33.10"
config.vm.synced_folder ".", "/var/www",
:nfs => true,
:mount_options =>['noacl,nolock,vers=3,udp,noatime,nodiratime,rsize=32768,wsize=32768']
When asked, I pick my Airport connection for the bridge (Wi-Fi (AirPort)).
I cannot find a single usage of hostonly in the Vagrant docs.
Using Vagrant 1.7.4
My goal is simply to be able to access the VM running on one computer in my house, from other computers (and my phone) in my house.
If you want to have NFS and Public/bridge network try this:
Vagrantfile
config.vm.network "private_network", ip: "192.168.10.100"
config.vm.network "public_network", ip: "192.168.20.200"
or
config.vm.network "private_network", ip: "192.168.10.100"
config.vm.network "public_network", ip: "192.168.20.200", bridge: "en1: Wi-Fi (AirPort)"
Replace hostonly by ip in your Vagrantfile
config.vm.network "public_network", ip: "192.168.33.10"

Guest ip is unreachable under Vagrant using private network

I have next vagrant file on my windows host
Vagrant.configure(2) do |config|
config.vm.provider :virtualbox do |v|
v.customize [
"modifyvm", :id,
"--memory", 1024,
"--cpus", 1,
]
end
config.vm.box = "ubuntu/trusty64"
config.vm.network "private_network", ip: "192.168.0.101"
end
Virtual machine starts normally but is unreachable from host by "192.168.0.101" ip. /etc/network/interface on guest is
auto lo
iface lo inet loopback
source /etc/network/interfaces.d/*.cfg
#VAGRANT-BEGIN
# The contents below are automatically generated by Vagrant. Do not modify.
auto eth1
iface eth1 inet static
address 192.168.0.101
netmask 255.255.255.0
#VAGRANT-END
and /etc/network/interfaces.d/eth0.cfg is
auto eth0
iface eth0 inet dhcp
Additionally after each run that vagrant, the new virtual network adapter is created and inside Virtualbox UI tool I see info about that new network - real IP is diffrent and random i.e. 169.254.173.8. I had >20 virtual networks :) By that IP guest machine is pinged and from itself also. But after restart vagrant the new network will be created with new IP
How to run vagrant machine with static unchangable IP? I need to build cluster with several nodes and each node must know about IP of each one
Update:
On Linux host machine all it's OK. I can ping all guests from my host and guets see each other
On Windows guests can't ping other guests i.e. 192.168.0.101 can't see 192.168.0.102
The private network is just that, private to the guest(s), and it's created in addition to the default NAT-ed adapter. If you have several guests, they can interact with each other on the private network.
Regarding the nodes interacting, there are a number of plugins that can help you manage that, both with actual DNS as well as more simply using /etc/hosts. I tried a few and settled on vagrant-hosts.

Can Multiple Vagrant VMs communicate by VM hostname?

I am managing multiple VMs with Vagrant. Networks are configured as private, ip addresses have been set and hostnames are assigned. As shown in the Vagrantfile below.
The VMs can communicate with each other via the IP address, but I would like to know how to allow VMs to communicate using their assigned hostname. I.e. How to make ping comtest2 work from comtest1?
Vagrantfile:
Vagrant.configure("2") do |config|
config.vm.define "comtest1" do |comtest1|
comtest1.vm.box = "precise32"
comtest1.vm.hostname = "comtest1"
comtest1.vm.network "private_network", ip: "192.168.10.21"
end
config.vm.define "comtest2" do |comtest2|
comtest2.vm.box = "precise32"
comtest2.vm.hostname = "comtest2"
comtest2.vm.network "private_network", ip: "192.168.10.22"
end
end
Cheat the dns resolution with https://github.com/adrienthebo/vagrant-hosts ?
You can use Zeroconf. It broadcasts the host name in network and makes it available to the other hosts on the local network. That way you can access your hosts using test1.local, test2.local, etc.
Just install avahi-daemon and libnss-mdns!
Example
Vagrantfile:
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/bionic64"
config.vm.define "vm1" do |machine|
machine.vm.hostname = "vm1"
machine.vm.network "private_network", type: "dhcp"
end
config.vm.define "vm2" do |machine|
machine.vm.hostname = "vm2"
machine.vm.network "private_network", type: "dhcp"
end
# allow guests to reach each other by hostname
config.vm.provision "allow_guest_host_resolution",
type: "shell",
inline: <<-SHELL
apt update
apt install -y avahi-daemon libnss-mdns
SHELL
end
Test
$ vagrant up
...
$ vagrant ssh vm1 -- ping -c 1 vm2.local
PING vm2.local (172.28.128.8) 56(84) bytes of data.
64 bytes from 172.28.128.8 (172.28.128.8): icmp_seq=1 ttl=64 time=0.333 ms
$ vagrant ssh vm2 -- ping -c 1 vm1.local
PING vm1.local (172.28.128.7) 56(84) bytes of data.
64 bytes from 172.28.128.7 (172.28.128.7): icmp_seq=1 ttl=64 time=0.254 ms
It isn't the most elegant solution in the world but it is very simple, how about something like:
Vagrant.configure("2") do |config|
config.vm.define "comtest1" do |comtest1|
comtest1.vm.box = "precise32"
comtest1.vm.hostname = "comtest1"
comtest1.vm.network "private_network", ip: "192.168.10.21"
comtest1.vm.provision "shell", inline: <<-SHELL
sed -i '$ a 192.168.10.22 comtest2' /etc/hosts
SHELL
end
config.vm.define "comtest2" do |comtest2|
comtest2.vm.box = "precise32"
comtest2.vm.hostname = "comtest2"
comtest2.vm.network "private_network", ip: "192.168.10.22"
end
end
If the host resolves DNS correctly, then you can configure Virtualbox to use the host as the DNS resolver.
config.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
end
See https://serverfault.com/a/506206/250071
We use a local Ansible task to automatically add the provisioned box to the host /etc/hosts file. It is a little awkward, but has been very robust.
- setup:
gather_subset: [network]
- name: Add host mapping to local /etc/hosts
delegate_to: 127.0.0.1
lineinfile: dest=/etc/hosts regexp=".+{{ vm.hostname }}$" line="{{ ansible_all_ipv4_addresses|sort|last }} {{ vm.hostname }}"
Check out landrush on Github.
It will setup a DNS for your vagrant private network.

Resources