mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-06 10:43:56 +00:00
Add mode-detecting iptables wrappers to the debian-iptables image
This commit is contained in:
parent
ee681f7bd3
commit
fed582333f
@ -14,10 +14,28 @@
|
|||||||
|
|
||||||
FROM BASEIMAGE
|
FROM BASEIMAGE
|
||||||
|
|
||||||
|
# Install latest iptables package from buster-backports
|
||||||
|
RUN echo deb http://deb.debian.org/debian buster-backports main >> /etc/apt/sources.list; \
|
||||||
|
apt-get update; \
|
||||||
|
apt-get -t buster-backports -y --no-install-recommends install iptables
|
||||||
|
|
||||||
|
# Install other dependencies and then clean up apt caches
|
||||||
RUN clean-install \
|
RUN clean-install \
|
||||||
conntrack \
|
conntrack \
|
||||||
ebtables \
|
ebtables \
|
||||||
ipset \
|
ipset \
|
||||||
iptables \
|
|
||||||
kmod \
|
kmod \
|
||||||
netbase
|
netbase
|
||||||
|
|
||||||
|
# Install iptables wrapper scripts to detect the correct iptables mode
|
||||||
|
# the first time any of them is run
|
||||||
|
COPY iptables-wrapper /usr/sbin/iptables-wrapper
|
||||||
|
|
||||||
|
RUN update-alternatives \
|
||||||
|
--install /usr/sbin/iptables iptables /usr/sbin/iptables-wrapper 100 \
|
||||||
|
--slave /usr/sbin/iptables-restore iptables-restore /usr/sbin/iptables-wrapper \
|
||||||
|
--slave /usr/sbin/iptables-save iptables-save /usr/sbin/iptables-wrapper
|
||||||
|
RUN update-alternatives \
|
||||||
|
--install /usr/sbin/ip6tables ip6tables /usr/sbin/iptables-wrapper 100 \
|
||||||
|
--slave /usr/sbin/ip6tables-restore ip6tables-restore /usr/sbin/iptables-wrapper \
|
||||||
|
--slave /usr/sbin/ip6tables-save ip6tables-save /usr/sbin/iptables-wrapper
|
||||||
|
34
build/debian-iptables/iptables-wrapper
Executable file
34
build/debian-iptables/iptables-wrapper
Executable file
@ -0,0 +1,34 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# Copyright 2019 The Kubernetes Authors.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Detect whether the base system is using iptables-legacy or
|
||||||
|
# iptables-nft. This assumes that some non-containerized process (eg
|
||||||
|
# kubelet) has already created some iptables rules.
|
||||||
|
num_legacy_lines=$( (iptables-legacy-save || true; ip6tables-legacy-save || true) 2>/dev/null | grep '^-' | wc -l)
|
||||||
|
num_nft_lines=$( (iptables-nft-save || true; ip6tables-nft-save || true) 2>/dev/null | grep '^-' | wc -l)
|
||||||
|
if [ "${num_legacy_lines}" -ge "${num_nft_lines}" ]; then
|
||||||
|
mode=legacy
|
||||||
|
else
|
||||||
|
mode=nft
|
||||||
|
fi
|
||||||
|
|
||||||
|
update-alternatives --set iptables "/usr/sbin/iptables-${mode}" > /dev/null
|
||||||
|
update-alternatives --set ip6tables "/usr/sbin/ip6tables-${mode}" > /dev/null
|
||||||
|
|
||||||
|
# Now re-exec the original command with the newly-selected alternative
|
||||||
|
exec "$0" "$@"
|
Loading…
Reference in New Issue
Block a user