Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[baseimage]: Install Kubernetes packages if enabled in image #4374

Merged
merged 11 commits into from
Apr 13, 2020
5 changes: 5 additions & 0 deletions Makefile.work
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# through http.
# * ENABLE_ZTP: Enables zero touch provisioning.
# * SHUTDOWN_BGP_ON_START: Sets admin-down state for all bgp peerings after restart.
# * INSTALL_KUBERNETES: Allows including Kubernetes
# * ENABLE_PFCWD_ON_START: Enable PFC Watchdog (PFCWD) on server-facing ports
# * by default for TOR switch.
# * ENABLE_SYNCD_RPC: Enables rpc-based syncd builds.
Expand Down Expand Up @@ -176,6 +177,10 @@ SONIC_BUILD_INSTRUCTION := make \
ENABLE_DHCP_GRAPH_SERVICE=$(ENABLE_DHCP_GRAPH_SERVICE) \
ENABLE_ZTP=$(ENABLE_ZTP) \
SHUTDOWN_BGP_ON_START=$(SHUTDOWN_BGP_ON_START) \
INSTALL_KUBERNETES=$(INSTALL_KUBERNETES) \
renukamanavalan marked this conversation as resolved.
Show resolved Hide resolved
KUBERNETES_VERSION=$(KUBERNETES_VERSION) \
K8s_GCR_IO_PAUSE_VERSION=$(K8s_GCR_IO_PAUSE_VERSION) \
K8s_CNI_CALICO_VERSION=$(K8s_CNI_CALICO_VERSION) \
SONIC_ENABLE_PFCWD_ON_START=$(ENABLE_PFCWD_ON_START) \
SONIC_ENABLE_SYNCD_RPC=$(ENABLE_SYNCD_RPC) \
SONIC_INSTALL_DEBUG_TOOLS=$(INSTALL_DEBUG_TOOLS) \
Expand Down
16 changes: 16 additions & 0 deletions build_debian.sh
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,22 @@ sudo LANG=C chroot $FILESYSTEM_ROOT apt-get update
sudo LANG=C chroot $FILESYSTEM_ROOT apt-get -y install docker-ce=${DOCKER_VERSION}
sudo LANG=C chroot $FILESYSTEM_ROOT apt-get -y remove software-properties-common gnupg2

if [ "$INSTALL_KUBERNETES" == "y" ]
renukamanavalan marked this conversation as resolved.
Show resolved Hide resolved
then
## Install Kubernetes
echo '[INFO] Install kubernetes'
sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT curl -fsSL \
https://packages.cloud.google.com/apt/doc/apt-key.gpg | \
sudo LANG=C chroot $FILESYSTEM_ROOT apt-key add -
## Check out the sources list update matches current Debian version
sudo cp files/image_config/kubernetes/kubernetes.list $FILESYSTEM_ROOT/etc/apt/sources.list.d/
sudo LANG=C chroot $FILESYSTEM_ROOT apt-get update
sudo LANG=C chroot $FILESYSTEM_ROOT apt-get -y install kubeadm=${KUBERNETES_VERSION}-00
# kubeadm package auto install kubelet & kubectl
else
echo '[INFO] Skipping Install kubernetes'
fi

## Add docker config drop-in to specify dockerd command line
sudo mkdir -p $FILESYSTEM_ROOT/etc/systemd/system/docker.service.d/
## Note: $_ means last argument of last command
Expand Down
19 changes: 19 additions & 0 deletions files/build_templates/sonic_debian_extension.j2
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,13 @@ sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT pip install azure-s
sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT pip install watchdog
sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT pip install futures

{% if install_kubernetes == "y" %}
# Copy kubelet service files
# Keep it disabled until join, else it continuously restart and as well spew too many
# non-required log lines wasting syslog resources.
sudo LANG=C chroot $FILESYSTEM_ROOT systemctl disable kubelet.service
renukamanavalan marked this conversation as resolved.
Show resolved Hide resolved
{% endif %}

# Copy the buffer configuration template
sudo cp $BUILD_TEMPLATES/buffers_config.j2 $FILESYSTEM_ROOT_USR_SHARE_SONIC_TEMPLATES/

Expand Down Expand Up @@ -401,6 +408,18 @@ sudo LANG=C chroot $FILESYSTEM_ROOT docker $SONIC_NATIVE_DOCKERD_FOR_DOCKERFS ta
sudo LANG=C chroot $FILESYSTEM_ROOT docker $SONIC_NATIVE_DOCKERD_FOR_DOCKERFS tag {{imagename}}:latest {{imagebasename}}:latest
{% endif %}
{% endfor %}

{% if install_kubernetes == "y" %}
## Pull in kubernetes docker images
echo "pulling universal k8s images ..."
sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT docker pull k8s.gcr.io/pause:${K8s_GCR_IO_PAUSE_VERSION}
sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT docker pull k8s.gcr.io/kube-proxy:v${KUBERNETES_VERSION}
sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT docker pull calico/node:v${K8s_CNI_CALICO_VERSION}
sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT docker pull calico/pod2daemon-flexvol:v${K8s_CNI_CALICO_VERSION}
sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT docker pull calico/cni:v${K8s_CNI_CALICO_VERSION}
echo "docker images pull complete"
{% endif %}

sudo umount $FILESYSTEM_ROOT/target
sudo rm -r $FILESYSTEM_ROOT/target
if [[ $CONFIGURED_ARCH == armhf || $CONFIGURED_ARCH == arm64 ]]; then
Expand Down
4 changes: 4 additions & 0 deletions files/image_config/kubernetes/kubernetes.list
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# The following is as recommended by https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-kubeadm/
# Whenever an OS update from Debian stretch is done, make sure to find the matching k8s sources list
#
deb https://apt.kubernetes.io/ kubernetes-xenial main
renukamanavalan marked this conversation as resolved.
Show resolved Hide resolved
14 changes: 14 additions & 0 deletions rules/config
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,17 @@ ENABLE_RESTAPI = n
# ENABLE_NAT - build docker-sonic-nat for nat support
ENABLE_NAT = y

# INSTALL_KUBERNETES - if set to y kubernetes packages are installed to be able to
# run as worker node in kubernetes cluster.
INSTALL_KUBERNETES = n

# KUBERNETES_VERSION - Set to the required version.
# K8s_GCR_IO_PAUSE_VERSION - Version of k8s universal pause container image
# K8s_CNI_CALICO_VERSION - Calico used as CNI; Appropriate version for this Kubernetes version
# These are Used *only* when INSTALL_KUBERNETES=y
# NOTE: As a worker node it has to run version compatible to kubernetes master.
#
KUBERNETES_VERSION = 1.18.0
K8s_GCR_IO_PAUSE_VERSION = 3.2
K8s_CNI_CALICO_VERSION = 3.12.0

2 changes: 2 additions & 0 deletions slave.mk
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ $(info "USERNAME" : "$(USERNAME)")
$(info "PASSWORD" : "$(PASSWORD)")
$(info "ENABLE_DHCP_GRAPH_SERVICE" : "$(ENABLE_DHCP_GRAPH_SERVICE)")
$(info "SHUTDOWN_BGP_ON_START" : "$(SHUTDOWN_BGP_ON_START)")
$(info "INSTALL_KUBERNETES" : "$(INSTALL_KUBERNETES)")
$(info "ENABLE_PFCWD_ON_START" : "$(ENABLE_PFCWD_ON_START)")
$(info "INSTALL_DEBUG_TOOLS" : "$(INSTALL_DEBUG_TOOLS)")
$(info "ROUTING_STACK" : "$(SONIC_ROUTING_STACK)")
Expand Down Expand Up @@ -769,6 +770,7 @@ $(addprefix $(TARGET_PATH)/, $(SONIC_INSTALLERS)) : $(TARGET_PATH)/% : \
export enable_ztp="$(ENABLE_ZTP)"
export enable_nat="$(ENABLE_NAT)"
export shutdown_bgp_on_start="$(SHUTDOWN_BGP_ON_START)"
export install_kubernetes="$(INSTALL_KUBERNETES)"
export enable_pfcwd_on_start="$(ENABLE_PFCWD_ON_START)"
export installer_debs="$(addprefix $(STRETCH_DEBS_PATH)/,$($*_INSTALLS))"
export lazy_installer_debs="$(foreach deb, $($*_LAZY_INSTALLS),$(foreach device, $($(deb)_PLATFORM),$(addprefix $(device)@, $(STRETCH_DEBS_PATH)/$(deb))))"
Expand Down