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

update install_k3s.sh #714

Merged
merged 1 commit into from
May 24, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 28 additions & 24 deletions contribution/k3s/install_k3s.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,44 @@

# create a single-node K3s cluster
if [ -x "$(command -v docker)" ]; then # docker
CGROUP_SYSTEMD=$(docker info 2> /dev/null | grep -i cgroup | grep systemd | wc -l)
if [ $CGROUP_SYSTEMD == 1 ]; then
curl -sfL https://get.k3s.io | K3S_KUBECONFIG_MODE="644" INSTALL_K3S_EXEC="--disable=traefik --docker --kubelet-arg cgroup-driver=systemd" sh -
[[ $? != 0 ]] && echo "Failed to install k3s" && exit 1
else # cgroupfs
curl -sfL https://get.k3s.io | K3S_KUBECONFIG_MODE="644" INSTALL_K3S_EXEC="--disable=traefik --docker" sh -
[[ $? != 0 ]] && echo "Failed to install k3s" && exit 1
fi
CGROUP_SYSTEMD=$(docker info 2> /dev/null | grep -i cgroup | grep systemd | wc -l)
if [ $CGROUP_SYSTEMD == 1 ]; then
curl -sfL https://get.k3s.io | K3S_KUBECONFIG_MODE="644" INSTALL_K3S_EXEC="--disable=traefik --docker --kubelet-arg cgroup-driver=systemd" sh -
[[ $? != 0 ]] && echo "Failed to install k3s" && exit 1
else # cgroupfs
curl -sfL https://get.k3s.io | K3S_KUBECONFIG_MODE="644" INSTALL_K3S_EXEC="--disable=traefik --docker" sh -
[[ $? != 0 ]] && echo "Failed to install k3s" && exit 1
fi
else # containerd
curl -sfL https://get.k3s.io | K3S_KUBECONFIG_MODE="644" INSTALL_K3S_EXEC="--disable=traefik" sh -
[[ $? != 0 ]] && echo "Failed to install k3s" && exit 1
curl -sfL https://get.k3s.io | K3S_KUBECONFIG_MODE="644" INSTALL_K3S_EXEC="--disable=traefik" sh -
[[ $? != 0 ]] && echo "Failed to install k3s" && exit 1
fi

KUBEDIR=$HOME/.kube
KUBECONFIG=$KUBEDIR/config

[[ ! -d $KUBEDIR ]] && mkdir $HOME/.kube/
if [ -f $KUBECONFIG ]; then
KUBECONFIGBKP=$KUBEDIR/config.backup
echo "Found $KUBECONFIG already in place ... backing it up to $KUBECONFIGBKP"
cp $KUBECONFIG $KUBECONFIGBKP
if [[ $(hostname) = kubearmor-dev* ]]; then
mkdir -p /home/vagrant/.kube
sudo cp /etc/rancher/k3s/k3s.yaml /home/vagrant/.kube/config
sudo chown -R vagrant:vagrant /home/vagrant/.kube
else
KUBEDIR=$HOME/.kube
KUBECONFIG=$KUBEDIR/config
[[ ! -d $KUBEDIR ]] && mkdir $KUBEDIR
if [ -f $KUBECONFIG ]; then
echo "Found $KUBECONFIG already in place ... backing it up to $KUBECONFIG.backup"
cp $KUBECONFIG $KUBECONFIG.backup
fi
sudo cp /etc/rancher/k3s/k3s.yaml $KUBECONFIG
sudo chown $USER:$USER $KUBECONFIG
fi

cp /etc/rancher/k3s/k3s.yaml $KUBEDIR/config

echo "wait for initialization"
sleep 15

for (( ; ; ))
do
status=$(kubectl get pods -A -o jsonpath={.items[*].status.phase})
[[ $(echo $status | grep -v Running | wc -l) -eq 0 ]] && break
echo "wait for initialization"
sleep 1
status=$(kubectl get pods -A -o jsonpath={.items[*].status.phase})
[[ $(echo $status | grep -v Running | wc -l) -eq 0 ]] && break
echo "wait for initialization"
sleep 1
done

kubectl get pods -A