[baseimage]: Install Kubernetes packages if enabled in image (#4374)
* Install kubernetes worker node packages, if enabled. * Minor updates * Added some comments * Updates per review comments. Built a private image to test to work fine. * Remove the removed file. * Update per comments Make a fix, as kubeadm no demands a higher version of kubelet & kubectl. As kubeadm auto install kubectl & kubelet, removing explicit install is an easier/robust fix. * Changes per review comments. * Updates per comments. 1) Dropped helper & pod scripts 2) Made install verbose * Drop creation of pods subdir, as this PR does not use them. * From comments to 'n' per review comments. * 1) kubeadm.conf is created as part of kubeadm package install. Hence dropped explicit copy.
This commit is contained in:
parent
1b8897eec0
commit
f128153706
@ -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.
|
||||
@ -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) \
|
||||
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) \
|
||||
|
@ -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" ]
|
||||
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
|
||||
|
@ -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
|
||||
{% endif %}
|
||||
|
||||
# Copy the buffer configuration template
|
||||
sudo cp $BUILD_TEMPLATES/buffers_config.j2 $FILESYSTEM_ROOT_USR_SHARE_SONIC_TEMPLATES/
|
||||
|
||||
@ -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
|
||||
|
4
files/image_config/kubernetes/kubernetes.list
Normal file
4
files/image_config/kubernetes/kubernetes.list
Normal file
@ -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
|
14
rules/config
14
rules/config
@ -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
slave.mk
2
slave.mk
@ -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)")
|
||||
@ -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))))"
|
||||
|
Loading…
Reference in New Issue
Block a user