Reputation: 321
I'm trying to create a docker server using rancher on local network ( with many machines, some linux, some windows ). I had installed rancher-server, created a host, added an API to test and created a load balancer to registry this API. Locally, works fine, i can acess the API container like : "http://test.172.17.0.4.xip.io:3000/", but in others machines in my network, i cant acess..
PS:
test
-> API name
172.17.0.4
-> Ip of HOST machine docker ( with rancher-agent )
xip.io
-> public wildcard DNS ( see more in : http://xip.io/ )
3000
-> API port mapped in load balancer
I'vd tryed to change network of the container in rancher UI, didn't work, i read some things about create a docker network, but i'm a bit confused, cuz docker create a defaut netdocker, docker0, is an bridge network.. I'm a little lay in network matters.
EDIT:
I created macvlan using docker network, and now i can ping to my container using others machines, but now, i my container dont have internet connection to download things.
docker network create -d macvlan --subnet=172.16.108.0/26 --gateway=172.16.108.1 -o macvlan_mode=bridge -o parent=enp1s0 rancher
and tried to run a container in this network
EDIT2:
This ifconfig
output
docker0: flags=4099 mtu 1500 inet 172.17.0.1 netmask 255.255.0.0 broadcast 172.17.255.255 ether 02:42:79:4f:fc:66 txqueuelen 0 (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
enp1s0: flags=4163 mtu 1500 inet 172.16.108.1 netmask 255.255.255.192 broadcast 172.16.108.63 inet6 fe80::593f:24d0:31f2:4fd8 prefixlen 64 scopeid 0x20 ether d0:94:66:a5:29:8f txqueuelen 1000 (Ethernet) RX packets 1251 bytes 1024069 (1000.0 KiB) RX errors 0 dropped 5 overruns 0 frame 0 TX packets 980 bytes 157904 (154.2 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73 mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10 loop txqueuelen 1000 (Loopback Local) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
EDIT3:
I tried to specify the ip adress passing the flag --address when start rancher and/or the host, and the result are the same: unknown flag: --address
the commands i tried to do are:
docker run -d --restart=unless-stopped --address 172.16.108.63 -p 8080:8080 rancher/server
To start rancher server. I tried with macvlan too
docker run --privileged --name some-docker1 --address 172.16.108.63 -d docker:stable-dind
To start rancher machine ( to be the future host )
And i tried the same command above, but without the --address. Then, attached in shell of the container, i tried to create the host
docker run -e CATTLE_AGENT_IP="172.17.0.3" --rm --privileged --address 172.16.108.63 -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/rancher:/var/lib/rancher ran
cher/agent:v1.2.11 http://172.17.0.2:8080/v1/scripts/3FA0E7B767770264BCAD:1546214400000:P9NfsauqyhZpoeIBgGyCZIHkKtE
The results are the same..
RESUME: I'm trying to create a rancher-server in my local network to access the applications in my load balancer from other machines in the same network.
Upvotes: 1
Views: 1951
Reputation: 1960
Edit 2: One needs to specify the IP address of the host being added using CATTLE_AGENT_IP. I got the versions wrong in the previous edit.
Edit 1:
When using the same host for running both the rancher server and the agent image, it's important to specify the IP address of the host using the flag --address <IP address>
. Otherwise, the auto detected IP address would be incorrect.
In your case, you need to specify --address 172.16.108.63
when registering the host.
Then xip address generated would reflect the correct IP address.
====
Here is one way to be able to access your application from outside the cluster. This involves use of Ingress. (Check here for more information: https://kubernetes.io/docs/concepts/services-networking/ingress/)
Step 1: Create a deployment (change the image and customize other options according to your needs)
apiVersion: apps/v1
kind: Deployment
metadata:
name: app1
spec:
replicas: 1
selector:
matchLabels:
name: app1
template:
metadata:
labels:
name: app1
spec:
containers:
- name: app1
image: leodotcloud/swiss-army-knife
ports:
- containerPort: 80
name: http
env:
- name: NATO_ALPHABET
value: "a"
Step 2: Create a service (One can directly create the ingress, but I like to keep things segregated)
apiVersion: v1
kind: Service
metadata:
labels:
name: access-app1
name: access-app1
spec:
ports:
- port: 80
targetPort: 80
selector:
name: app1
Step 3: Create Ingress
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: ingress-app1
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- http:
paths:
- path: /app1
backend:
serviceName: access-app1
servicePort: 80
Now your application will be available at http://<HOST_IP_ADDRESS>/app1
Upvotes: 1