Skip to content

Instantly share code, notes, and snippets.

@valentinconan
Created April 17, 2024 12:34
Show Gist options
  • Save valentinconan/147ad4c9e1d16ebc48d4eaa7d48bde48 to your computer and use it in GitHub Desktop.
Save valentinconan/147ad4c9e1d16ebc48d4eaa7d48bde48 to your computer and use it in GitHub Desktop.
Orchestration setup

Install dev environment

Install tools

Install k3s server

curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="--flannel-backend=vxlan" sh -

Without traefik

curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="--disable traefik --flannel-backend=vxlan" sh -

then install incress

kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.10.0/deploy/static/provider/baremetal/deploy.yaml

Install k9s

wget https://github.com/derailed/k9s/releases/download/v0.27.4/k9s_Linux_amd64.tar.gz
tar xvzf k9s_Linux_amd64.tar.gz k9s
sudo cp k9s /usr/local/bin
rm k9s_Linux_amd64.tar.gz

Then copy the configuration in order to manage k3s with k9s


cp /etc/rancher/k3s/k3s.yaml ~/.kube/config

Manage if no systemd

Add theses 2 scripts in the folder /usr/local/bin :

  • k3s-startall.sh
  • k3s-killall.sh

Configuration

Create a file in order to deploy configuration

sudo vim /etc/rancher/k3s/registries.yaml

Add this content

mirrors:
  docker.io:
    endpoint:
      - "https://proxies.docker.com"
insecure_registries:
  - "private-registry-server:port"
sudo touch /etc/rancher/k3s/registries.yaml && cat > /etc/rancher/k3s/registries.yaml <<- EOM
mirrors:
  docker.io:
    endpoint:
      - "https://proxies.docker.com"
insecure_registries:
  - "private-registry-server:port"
EOM

Install helm

#install
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash

#deploy
helm upgrade --install --dependency-update --create-namespace --namespace my-namespace -f values.yaml my-dev .

#uninstall
helm uninstall --namespace my-namespace my-dev
#!/bin/sh
[ $(id -u) -eq 0 ] || exec sudo $0 $@
for bin in /var/lib/rancher/k3s/data/**/bin/; do
[ -d $bin ] && export PATH=$PATH:$bin:$bin/aux
done
set -x
for service in /etc/systemd/system/k3s*.service; do
[ -s $service ] && systemctl stop $(basename $service)
done
for service in /etc/init.d/k3s*; do
[ -x $service ] && $service stop
done
pschildren() {
ps -e -o ppid= -o pid= | \
sed -e 's/^\s*//g; s/\s\s*/\t/g;' | \
grep -w "^$1" | \
cut -f2
}
pstree() {
for pid in $@; do
echo $pid
for child in $(pschildren $pid); do
pstree $child
done
done
}
killtree() {
kill -9 $(
{ set +x; } 2>/dev/null;
pstree $@;
set -x;
) 2>/dev/null
}
remove_interfaces() {
# Delete network interface(s) that match 'master cni0'
ip link show 2>/dev/null | grep 'master cni0' | while read ignore iface ignore; do
iface=${iface%%@*}
[ -z "$iface" ] || ip link delete $iface
done
# Delete cni related interfaces
ip link delete cni0
ip link delete flannel.1
ip link delete flannel-v6.1
ip link delete kube-ipvs0
ip link delete flannel-wg
ip link delete flannel-wg-v6
# Restart tailscale
if [ -n "$(command -v tailscale)" ]; then
tailscale set --advertise-routes=
fi
}
getshims() {
ps -e -o pid= -o args= | sed -e 's/^ *//; s/\s\s*/\t/;' | grep -w 'k3s/data/[^/]*/bin/containerd-shim' | cut -f1
}
killtree $({ set +x; } 2>/dev/null; getshims; set -x)
do_unmount_and_remove() {
set +x
while read -r _ path _; do
case "$path" in $1*) echo "$path" ;; esac
done < /proc/self/mounts | sort -r | xargs -r -t -n 1 sh -c 'umount -f "$0" && rm -rf "$0"'
set -x
}
do_unmount_and_remove '/run/k3s'
do_unmount_and_remove '/var/lib/rancher/k3s'
do_unmount_and_remove '/var/lib/kubelet/pods'
do_unmount_and_remove '/var/lib/kubelet/plugins'
do_unmount_and_remove '/run/netns/cni-'
# Remove CNI namespaces
ip netns show 2>/dev/null | grep cni- | xargs -r -t -n 1 ip netns delete
remove_interfaces
rm -rf /var/lib/cni/
iptables-save | grep -v KUBE- | grep -v CNI- | grep -iv flannel | iptables-restore
ip6tables-save | grep -v KUBE- | grep -v CNI- | grep -iv flannel | ip6tables-restore
# Add this in order to kill k3s instance
pkill -f k3s &
echo $?
#!/bin/sh
k3s server > /tmp/k3s.log 2>&1 &
#exemple
image:
registry: docker.io
backend:
persistence:
storageClassName: "local-path"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment