Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Feb 24, 2020. It is now read-only.

Conversation

@alban
Copy link
Member

@alban alban commented Jan 25, 2016

rkt now provides /etc/resolv.conf in each app's chroot if it does not
exist. If the ACI provides such a file, rkt does not touch it.

The "nameserver" entries come from two sources:

  1. as a comma-separated list from the command line (--dns=xx.xx.xx.xx)
  2. from the selected network (--net=...)

If the 'host' network is requested, it copies /etc/resolv.conf from the
host. If another network is requested, it gets the name servers from the CNI
plugins.

Implementation detail: systemd-nspawn can overwrite /etc/resolv.conf. It
is supposed to overwrite it only when the container uses the host
network namespace. However, the container network namespace is created
by rkt via CNI and not by systemd-nspawn, so systemd-nspawn is not aware
of the network configuration. As a consequence, we cannot use stage1's
/etc/resolv.conf. Instead, rkt write /etc/rkt-resolv.conf in stage1 and
prepare-app bind-mounts it in stage2's /etc/resolv.conf.

It works in this way:

> $ cat /etc/rkt/net.d/alban.conf
> {
>   "name": "alban",
>   "type": "ptp",
>   "ipMasq": true,
>   "ipam": {
>       "type": "host-local",
>       "subnet": "172.16.42.0/24",
>       "routes": [
>           { "dst": "0.0.0.0/0" }
>       ]
>   },
>   "dns": [
>       "8.8.4.4",
>       "12.12.12.12"
>   ]
> }
>
> $ sudo rkt run --net=alban --dns=1.1.1.1,2.2.2.2 \
>       sha512-a2fb8f390702 --interactive
> / # cat /etc/resolv.conf
> # Generated by rkt
>
> # Name servers passed on the command line
> nameserver 1.1.1.1
> nameserver 2.2.2.2
>
> # Name servers from CNI
> nameserver 8.8.4.4
> nameserver 12.12.12.12
> / #

TODO:

  • add parameter --dns
  • get dns info from CNI
  • copy /etc/resolv.conf from host for --net=host
  • hard limit of 3 DNS servers (for compatibility with dns resolver)
  • changelog
  • documentation
  • tests

Fixes #660

@alban alban changed the title [WIP] populate /etc/resolv.conf [WIP/RFC] populate /etc/resolv.conf Jan 25, 2016
@alban alban force-pushed the alban/dns-1 branch 2 times, most recently from 56b7d6a to 6d67b61 Compare January 26, 2016 17:37
rkt now provides /etc/resolv.conf in each app's chroot if it does not
exist. If the ACI provides such a file, rkt does not touch it.

The "nameserver" entries come from two sources:
1. as a comma-separated list from the command line (--dns=xx.xx.xx.xx)
2. from the selected network (--net=...)

If the 'host' network is requested, it copies /etc/resolv.conf from the
host. If another network is requested, it gets the name servers from the CNI
plugins.

Implementation detail: systemd-nspawn can overwrite /etc/resolv.conf. It
is supposed to overwrite it only when the container uses the host
network namespace.  However, the container network namespace is created
by rkt via CNI and not by systemd-nspawn, so systemd-nspawn is not aware
of the network configuration. As a consequence, we cannot use stage1's
/etc/resolv.conf. Instead, rkt write /etc/rkt-resolv.conf in stage1 and
prepare-app bind-mounts it in stage2's /etc/resolv.conf.

It works in this way:

> $ cat /etc/rkt/net.d/alban.conf
> {
> 	"name": "alban",
> 	"type": "ptp",
> 	"ipMasq": true,
> 	"ipam": {
> 		"type": "host-local",
> 		"subnet": "172.16.42.0/24",
> 		"routes": [
> 			{ "dst": "0.0.0.0/0" }
> 		]
> 	},
> 	"dns": [
> 		"8.8.4.4",
> 		"12.12.12.12"
> 	]
> }
>
> $ sudo rkt run --net=alban --dns=1.1.1.1,2.2.2.2 \
> 		sha512-a2fb8f390702 --interactive
> / # cat /etc/resolv.conf
> # Generated by rkt
>
> # Name servers passed on the command line
> nameserver 1.1.1.1
> nameserver 2.2.2.2
>
> # Name servers from CNI
> nameserver 8.8.4.4
> nameserver 12.12.12.12
> / #
@alban alban added this to the v1.0.0 milestone Jan 26, 2016
@alban alban changed the title [WIP/RFC] populate /etc/resolv.conf populate /etc/resolv.conf Jan 26, 2016
@alban
Copy link
Member Author

alban commented Jan 26, 2016

Depends on containernetworking/cni#99

@yifan-gu
Copy link
Contributor

Add the dns search domains as well?

@steveej
Copy link
Contributor

steveej commented Jan 27, 2016

@yifan-gu good point, we might also want domain in addition to search. See http://linux.die.net/man/5/resolv.conf.

@alban
Copy link
Member Author

alban commented Jan 27, 2016

Postponing this PR: I'll prepare a separate PR for --dns=, --dns-search= etc. without changes on the CNI.

@alban alban modified the milestones: v1+, v1.0.0 Jan 27, 2016
@jonboulle jonboulle modified the milestones: v1.1.0, v1+ Jan 31, 2016
@jonboulle
Copy link
Contributor

@alban @steveej this seem reasonable for 1.1.0?

@alban
Copy link
Member Author

alban commented Feb 1, 2016

Yes, it sounds reasonable.

@iaguis iaguis modified the milestones: v1.2.0, v1.1.0 Feb 25, 2016
@alban alban modified the milestones: v1.3.0, v1.2.0 Mar 18, 2016
@alban alban added this to the v1.4.0 milestone Mar 31, 2016
@alban alban removed this from the v1.3.0 milestone Mar 31, 2016
@jonboulle
Copy link
Contributor

Fixed by #2040

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rkt: /etc/resolv.conf doesn't get populated

5 participants