Skip to content
Snippets Groups Projects
Commit 04812569 authored by garciadeblas's avatar garciadeblas
Browse files

Update K8s version for community installer to 1.20.11


Change-Id: I835da2f886f5bbf9eb342d52362a8a005710c255
Signed-off-by: default avatargarciadeblas <gerardo.garciadeblas@telefonica.com>
parent d992a95b
No related branches found
No related tags found
No related merge requests found
......@@ -462,17 +462,19 @@ function juju_createcontroller() {
}
function juju_addk8s() {
cat $HOME/.kube/config | juju add-k8s $OSM_VCA_K8S_CLOUDNAME --controller $OSM_STACK_NAME --storage openebs-hostpath
cat $HOME/.kube/config | juju add-k8s $OSM_VCA_K8S_CLOUDNAME --controller $OSM_STACK_NAME --storage openebs-hostpath \
|| FATAL "Failed to add K8s endpoint and credential for controller $OSM_STACK_NAME in cloud $OSM_VCA_K8S_CLOUDNAME"
}
function juju_createcontroller_k8s(){
cat $HOME/.kube/config | juju add-k8s $OSM_VCA_K8S_CLOUDNAME --client
cat $HOME/.kube/config | juju add-k8s $OSM_VCA_K8S_CLOUDNAME --client \
|| FATAL "Failed to add K8s endpoint and credential for client in cloud $OSM_VCA_K8S_CLOUDNAME"
juju bootstrap $OSM_VCA_K8S_CLOUDNAME $OSM_STACK_NAME \
--config controller-service-type=loadbalancer \
--agent-version=$JUJU_AGENT_VERSION
--agent-version=$JUJU_AGENT_VERSION \
|| FATAL "Failed to bootstrap controller $OSM_STACK_NAME in cloud $OSM_VCA_K8S_CLOUDNAME"
}
function juju_addlxd_cloud(){
mkdir -p /tmp/.osm
OSM_VCA_CLOUDNAME="lxd-cloud"
......@@ -513,7 +515,6 @@ EOF
juju controller-config features=[k8s-operators]
}
function juju_createproxy() {
check_install_iptables_persistent
......@@ -802,7 +803,8 @@ function install_kube() {
sudo add-apt-repository "deb https://apt.kubernetes.io/ kubernetes-xenial main"
sudo apt-get update
echo "Installing Kubernetes Packages ..."
sudo apt-get install -y kubelet=1.15.0-00 kubeadm=1.15.0-00 kubectl=1.15.0-00
K8S_VERSION=1.20.11-00
sudo apt-get install -y kubelet=${K8S_VERSION} kubeadm=${K8S_VERSION} kubectl=${K8S_VERSION}
sudo apt-mark hold kubelet kubeadm kubectl
}
......@@ -823,10 +825,9 @@ function kube_config_dir() {
function install_k8s_storageclass() {
echo "Installing OpenEBS"
kubectl create ns openebs
helm repo add openebs https://openebs.github.io/charts
helm repo update
helm install --namespace openebs openebs openebs/openebs --version 1.12.0
helm install --create-namespace --namespace openebs openebs openebs/openebs --version 1.12.0
helm ls -n openebs
local storageclass_timeout=400
local counter=0
......@@ -851,7 +852,8 @@ function install_k8s_storageclass() {
function install_k8s_metallb() {
METALLB_IP_RANGE=$DEFAULT_IP-$DEFAULT_IP
cat ${OSM_DEVOPS}/installers/k8s/metallb/metallb.yaml | kubectl apply -f -
kubectl apply -f ${OSM_DEVOPS}/installers/k8s/metallb/metallb.yaml \
|| FATAL "Cannot install MetalLB"
echo "apiVersion: v1
kind: ConfigMap
metadata:
......@@ -863,8 +865,105 @@ data:
- name: default
protocol: layer2
addresses:
- $METALLB_IP_RANGE" | kubectl apply -f -
- $METALLB_IP_RANGE" | kubectl apply -f - \
|| FATAL "Cannot apply MetalLB ConfigMap"
}
#installs metallb from helm
function install_helm_metallb() {
METALLB_IP_RANGE=$DEFAULT_IP-$DEFAULT_IP
echo "configInline:
address-pools:
- name: default
protocol: layer2
addresses:
- $METALLB_IP_RANGE" | sudo tee -a $OSM_DOCKER_WORK_DIR/metallb-config.yaml
helm repo add metallb https://metallb.github.io/metallb
helm install --create-namespace --namespace metallb-system metallb metallb/metallb -f $OSM_DOCKER_WORK_DIR/metallb-config.yaml
}
#checks openebs and metallb readiness
function check_for_readiness() {
# Default input values
sampling_period=2 # seconds
time_for_readiness=20 # seconds ready
time_for_failure=200 # seconds broken
OPENEBS_NAMESPACE=openebs
METALLB_NAMESPACE=metallb-system
# STACK_NAME=osm # By default, "osm"
# Equivalent number of samples
oks_threshold=$((time_for_readiness/${sampling_period})) # No. ok samples to declare the system ready
failures_threshold=$((time_for_failure/${sampling_period})) # No. nok samples to declare the system broken
failures_in_a_row=0
oks_in_a_row=0
####################################################################################
# Loop to check system readiness
####################################################################################
while [[ (${failures_in_a_row} -lt ${failures_threshold}) && (${oks_in_a_row} -lt ${oks_threshold}) ]]
do
# State of OpenEBS
OPENEBS_STATE=$(kubectl get pod -n ${OPENEBS_NAMESPACE} --no-headers 2>&1)
OPENEBS_READY=$(echo "${OPENEBS_STATE}" | awk '$2=="1/1" || $2=="2/2" {printf ("%s\t%s\t\n", $1, $2)}')
OPENEBS_NOT_READY=$(echo "${OPENEBS_STATE}" | awk '$2!="1/1" && $2!="2/2" {printf ("%s\t%s\t\n", $1, $2)}')
COUNT_OPENEBS_READY=$(echo "${OPENEBS_READY}"| grep -v -e '^$' | wc -l)
COUNT_OPENEBS_NOT_READY=$(echo "${OPENEBS_NOT_READY}" | grep -v -e '^$' | wc -l)
# State of MetalLB
METALLB_STATE=$(kubectl get pod -n ${METALLB_NAMESPACE} --no-headers 2>&1)
METALLB_READY=$(echo "${METALLB_STATE}" | awk '$2=="1/1" || $2=="2/2" {printf ("%s\t%s\t\n", $1, $2)}')
METALLB_NOT_READY=$(echo "${METALLB_STATE}" | awk '$2!="1/1" && $2!="2/2" {printf ("%s\t%s\t\n", $1, $2)}')
COUNT_METALLB_READY=$(echo "${METALLB_READY}" | grep -v -e '^$' | wc -l)
COUNT_METALLB_NOT_READY=$(echo "${METALLB_NOT_READY}" | grep -v -e '^$' | wc -l)
# OK sample
if [[ $((${COUNT_OPENEBS_NOT_READY}+${COUNT_METALLB_NOT_READY})) -eq 0 ]]
then
((++oks_in_a_row))
failures_in_a_row=0
echo -ne ===\> Successful checks: "${oks_in_a_row}"/${oks_threshold}\\r
# NOK sample
else
((++failures_in_a_row))
oks_in_a_row=0
echo
echo Bootstraping... "${failures_in_a_row}" checks of ${failures_threshold}
# Reports failed pods in OpenEBS
if [[ "${COUNT_OPENEBS_NOT_READY}" -ne 0 ]]
then
echo "OpenEBS: Waiting for ${COUNT_OPENEBS_NOT_READY} of $((${COUNT_OPENEBS_NOT_READY}+${COUNT_OPENEBS_READY})) pods to be ready:"
echo "${OPENEBS_NOT_READY}"
echo
fi
# Reports failed statefulsets
if [[ "${COUNT_METALLB_NOT_READY}" -ne 0 ]]
then
echo "MetalLB: Waiting for ${COUNT_METALLB_NOT_READY} of $((${COUNT_METALLB_NOT_READY}+${COUNT_METALLB_READY})) pods to be ready:"
echo "${METALLB_NOT_READY}"
echo
fi
fi
#------------ NEXT SAMPLE
sleep ${sampling_period}
done
####################################################################################
# OUTCOME
####################################################################################
if [[ (${failures_in_a_row} -ge ${failures_threshold}) ]]
then
echo
FATAL "K8S CLUSTER IS BROKEN"
else
echo
echo "K8S CLUSTER IS READY"
fi
}
#deploys flannel as daemonsets
function deploy_cni_provider() {
CNI_DIR="$(mktemp -d -q --tmpdir "flannel.XXXXXX")"
......@@ -1191,8 +1290,9 @@ function install_lightweight() {
track install_helm
install_k8s_storageclass
track k8s_storageclass
install_k8s_metallb
install_helm_metallb
track k8s_metallb
check_for_readiness
else
#install_docker_compose
[ -n "$INSTALL_NODOCKER" ] || init_docker_swarm
......
......@@ -156,7 +156,7 @@ roleRef:
kind: Role
name: leader-election
---
apiVersion: apps/v1beta2
apiVersion: apps/v1
kind: DaemonSet
metadata:
namespace: metallb-system
......@@ -209,7 +209,7 @@ spec:
add:
- net_raw
---
apiVersion: apps/v1beta2
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: metallb-system
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment