kubernetes: Configuration of kubelet via file

This allows cri-containerd and docker based systems to pass the correct options
via composition of yml files, while keeping the kubelet service stanza common.

Since bind mounts are not conditional on the presence of the source we need to
create an empty file in the docker case.

Signed-off-by: Ian Campbell <ijc@docker.com>
This commit is contained in:
Ian Campbell 2017-09-18 10:23:33 +01:00
parent b6d7f769be
commit b6fbc82e41
4 changed files with 9 additions and 2 deletions

View File

@ -65,6 +65,8 @@ services:
files: files:
- path: /etc/kubernetes - path: /etc/kubernetes
symlink: "/var/lib/kubeadm" symlink: "/var/lib/kubeadm"
- path: /etc/kubelet.conf
contents: ""
- path: /etc/sysctl.d/01-kubernetes.conf - path: /etc/sysctl.d/01-kubernetes.conf
contents: 'net.ipv4.ip_forward = 1' contents: 'net.ipv4.ip_forward = 1'
- path: /opt/cni - path: /opt/cni

View File

@ -63,6 +63,8 @@ services:
files: files:
- path: /etc/kubernetes - path: /etc/kubernetes
symlink: "/var/lib/kubeadm" symlink: "/var/lib/kubeadm"
- path: /etc/kubelet.conf
contents: ""
- path: /etc/sysctl.d/01-kubernetes.conf - path: /etc/sysctl.d/01-kubernetes.conf
contents: 'net.ipv4.ip_forward = 1' contents: 'net.ipv4.ip_forward = 1'
- path: /opt/cni - path: /opt/cni

View File

@ -45,4 +45,4 @@ WORKDIR /
ENTRYPOINT ["/usr/bin/kubelet.sh"] ENTRYPOINT ["/usr/bin/kubelet.sh"]
COPY --from=build /out / COPY --from=build /out /
ENV KUBECONFIG "/etc/kubernetes/admin.conf" ENV KUBECONFIG "/etc/kubernetes/admin.conf"
LABEL org.mobyproject.config='{"binds": ["/dev:/dev", "/etc/resolv.conf:/etc/resolv.conf", "/run:/run:rshared,rbind", "/var:/var:rshared,rbind", "/var/lib/kubeadm:/etc/kubernetes"], "mounts": [{"type": "cgroup", "options": ["rw","nosuid","noexec","nodev","relatime"]}], "capabilities": ["all"], "rootfsPropagation": "shared", "pid": "host", "runtime": {"mkdir": ["/var/lib/kubeadm", "/var/lib/cni/etc", "/var/lib/cni/opt"], "mounts": [{"type": "bind", "source": "/var/lib/cni/opt", "destination": "/opt/cni", "options": ["rw", "bind"]}, {"type": "bind", "source": "/var/lib/cni/etc", "destination": "/etc/cni", "options": ["rw", "bind"]}]}}' LABEL org.mobyproject.config='{"binds": ["/dev:/dev", "/etc/resolv.conf:/etc/resolv.conf", "/run:/run:rshared,rbind", "/var:/var:rshared,rbind", "/var/lib/kubeadm:/etc/kubernetes", "/etc/kubelet.conf:/etc/kubelet.conf"], "mounts": [{"type": "cgroup", "options": ["rw","nosuid","noexec","nodev","relatime"]}], "capabilities": ["all"], "rootfsPropagation": "shared", "pid": "host", "runtime": {"mkdir": ["/var/lib/kubeadm", "/var/lib/cni/etc", "/var/lib/cni/opt"], "mounts": [{"type": "bind", "source": "/var/lib/cni/opt", "destination": "/opt/cni", "options": ["rw", "bind"]}, {"type": "bind", "source": "/var/lib/cni/etc", "destination": "/etc/cni", "options": ["rw", "bind"]}]}}'

View File

@ -4,6 +4,9 @@ if [ ! -e /var/lib/cni/.opt.defaults-extracted ] ; then
tar -xzf /root/cni.tgz -C /var/lib/cni/opt/bin tar -xzf /root/cni.tgz -C /var/lib/cni/opt/bin
touch /var/lib/cni/.opt.defaults-extracted touch /var/lib/cni/.opt.defaults-extracted
fi fi
if [ -e /etc/kubelet.conf ] ; then
. /etc/kubelet.conf
fi
until kubelet --kubeconfig=/var/lib/kubeadm/kubelet.conf \ until kubelet --kubeconfig=/var/lib/kubeadm/kubelet.conf \
--require-kubeconfig=true \ --require-kubeconfig=true \
--pod-manifest-path=/var/lib/kubeadm/manifests \ --pod-manifest-path=/var/lib/kubeadm/manifests \
@ -15,7 +18,7 @@ until kubelet --kubeconfig=/var/lib/kubeadm/kubelet.conf \
--network-plugin=cni \ --network-plugin=cni \
--cni-conf-dir=/var/lib/cni/etc/net.d \ --cni-conf-dir=/var/lib/cni/etc/net.d \
--cni-bin-dir=/var/lib/cni/opt/bin \ --cni-bin-dir=/var/lib/cni/opt/bin \
$@; do $KUBELET_ARGS $@; do
if [ ! -f /var/config/userdata ] ; then if [ ! -f /var/config/userdata ] ; then
sleep 1 sleep 1
else else