Skip to content

Commit

Permalink
Support for ALPINE_NO_RESOLVER env var
Browse files Browse the repository at this point in the history
When this env var is passed to the container, then the container DNS
server will not be started, but resolv.conf will still be changed to
have the nameserver 127.0.0.1. This is a specific workaround making it
possible to run multiple Alpine-Kubernetes images in a single Pod that
shares a common network port stack so that only one DNS server can bind
to localhost port 53.
  • Loading branch information
Jan Broer committed Feb 6, 2016
1 parent 29f70c4 commit 0a4e5a1
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 3 deletions.
9 changes: 8 additions & 1 deletion rootfs/etc/services.d/resolver/run
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#!/usr/bin/execlineb -P

with-contenv
backtick -D "" -n ALPINE_NO_RESOLVER { printcontenv ALPINE_NO_RESOLVER }
importas -u ALPINE_NO_RESOLVER ALPINE_NO_RESOLVER
ifelse { s6-test -n ${ALPINE_NO_RESOLVER} }
{
fdmove -c 2 1
/sbin/kubernetes_multi_pod.sh
}
fdmove -c 2 1
go-dnsmasq --default-resolver --append-search-domains --hostsfile=/etc/hosts
go-dnsmasq --default-resolver --append-search-domains --hostsfile=/etc/hosts
33 changes: 33 additions & 0 deletions rootfs/sbin/kubernetes_multi_pod.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/ash

# Program that changes the systems primary nameserver to 127.0.0.1
# and restores the original resolv.conf on exit

RESOLV=/etc/resolv.conf
BACKUP=/etc/resolv.conf.orig

clean_up() {
if [ -f "$BACKUP" ]
then
cat $BACKUP > $RESOLV
echo "[Alpine-Kubernetes] Restored resolv.conf"
fi
exit
}

trap clean_up SIGHUP SIGINT SIGTERM

echo "[Alpine-Kubernetes] Changed nameserver to 127.0.0.1"

if [ ! -f "$RESOLV" ]
then
echo "Could not stat $RESOLV"
exit 1
fi

cp $RESOLV $BACKUP

echo '# Created by Alpine-Kubernetes' > $RESOLV
echo 'nameserver 127.0.0.1' >> $RESOLV

tail -f /dev/null
9 changes: 8 additions & 1 deletion versions/3.2/rootfs/etc/services.d/resolver/run
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#!/usr/bin/execlineb -P

with-contenv
backtick -D "" -n ALPINE_NO_RESOLVER { printcontenv ALPINE_NO_RESOLVER }
importas -u ALPINE_NO_RESOLVER ALPINE_NO_RESOLVER
ifelse { s6-test -n ${ALPINE_NO_RESOLVER} }
{
fdmove -c 2 1
/sbin/kubernetes_multi_pod.sh
}
fdmove -c 2 1
go-dnsmasq --default-resolver --append-search-domains --hostsfile=/etc/hosts
go-dnsmasq --default-resolver --append-search-domains --hostsfile=/etc/hosts
33 changes: 33 additions & 0 deletions versions/3.2/rootfs/sbin/kubernetes_multi_pod.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/ash

# Program that changes the systems primary nameserver to 127.0.0.1
# and restores the original resolv.conf on exit

RESOLV=/etc/resolv.conf
BACKUP=/etc/resolv.conf.orig

clean_up() {
if [ -f "$BACKUP" ]
then
cat $BACKUP > $RESOLV
echo "[Alpine-Kubernetes] Restored resolv.conf"
fi
exit
}

trap clean_up SIGHUP SIGINT SIGTERM

echo "[Alpine-Kubernetes] Changed nameserver to 127.0.0.1"

if [ ! -f "$RESOLV" ]
then
echo "Could not stat $RESOLV"
exit 1
fi

cp $RESOLV $BACKUP

echo '# Created by Alpine-Kubernetes' > $RESOLV
echo 'nameserver 127.0.0.1' >> $RESOLV

tail -f /dev/null
9 changes: 8 additions & 1 deletion versions/3.3/rootfs/etc/services.d/resolver/run
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#!/usr/bin/execlineb -P

with-contenv
backtick -D "" -n ALPINE_NO_RESOLVER { printcontenv ALPINE_NO_RESOLVER }
importas -u ALPINE_NO_RESOLVER ALPINE_NO_RESOLVER
ifelse { s6-test -n ${ALPINE_NO_RESOLVER} }
{
fdmove -c 2 1
/sbin/kubernetes_multi_pod.sh
}
fdmove -c 2 1
go-dnsmasq --default-resolver --append-search-domains --hostsfile=/etc/hosts
go-dnsmasq --default-resolver --append-search-domains --hostsfile=/etc/hosts
33 changes: 33 additions & 0 deletions versions/3.3/rootfs/sbin/kubernetes_multi_pod.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/ash

# Program that changes the systems primary nameserver to 127.0.0.1
# and restores the original resolv.conf on exit

RESOLV=/etc/resolv.conf
BACKUP=/etc/resolv.conf.orig

clean_up() {
if [ -f "$BACKUP" ]
then
cat $BACKUP > $RESOLV
echo "[Alpine-Kubernetes] Restored resolv.conf"
fi
exit
}

trap clean_up SIGHUP SIGINT SIGTERM

echo "[Alpine-Kubernetes] Changed nameserver to 127.0.0.1"

if [ ! -f "$RESOLV" ]
then
echo "Could not stat $RESOLV"
exit 1
fi

cp $RESOLV $BACKUP

echo '# Created by Alpine-Kubernetes' > $RESOLV
echo 'nameserver 127.0.0.1' >> $RESOLV

tail -f /dev/null

0 comments on commit 0a4e5a1

Please sign in to comment.