Rancher static IP for containers

3/26/2019

I am trying to configure a few containers to use a static IP address added to the host.

I have the server configured with main IP 1.1.1.1 and added a virtual interface (eth0:0) with IP address 2.2.2.2 (1.1.1.1 and 2.2.2.2 are just example IP addresses, to avoid leaving the real ones here).

I have been able to configure 2 containers to use that IP address, using hostports 2.2.2.2:8080 and 2.2.2.2:2222.

I am now trying to add a third container, with hostport 2.2.2.2:80

When I try to do that, I receive the following error:

0/1 nodes are available: 1 node(s) didn't have free ports for the requested pod ports.

What configuration am I missing here? Rancher web interface is replying in 1.1.1.1 and 2.2.2.2, but I would like it to only use 1.1.1.1, leaving the other IP addresses and ports for containers.

These are the commands I used to fire up rancher, and I am not sure if I should change the 80 or 443 part (on the left or the right) to match the correct public IP I want to map to rancher:

docker run -d --restart=unless-stopped -p 80:80 -p 443:443 rancher/rancher
sudo docker run -d --privileged --restart=unless-stopped --net=host -v /etc/kubernetes:/etc/kubernetes -v /var/run:/var/run rancher/rancher-agent:v2.1.7 --server https://[MY_HOST] --token [token] --ca-checksum [ca-chaecksum] --etcd --controlplane --worker
-- Miguel Mesquita Alfaiate
centos
docker
kubernetes
rancher

1 Answer

3/26/2019

Based on the info, I am deducing that you are using the same host to run Rancher and also register in a cluster.

When you specify -p 80:80, it means 0.0.0.0:80:80, so all the IP addresses are used up. Hence when you try to run a container later to expose port 80, it will fail.

To be able to not listen on all IP addresses, you need to specify the IP address to listen on when running the Rancher server container.

Example: docker run -d --restart=unless-stopped -p 1.1.1.1:80:80 -p 1.1.1.1:443:443 rancher/rancher

-- leodotcloud
Source: StackOverflow