Files
italiadatacenter/add-on/Istruzioni_kubeedge.txt
alessandro barucci 6ffb202579 allineamento
2026-07-17 10:00:09 +02:00

296 lines
7.9 KiB
Plaintext

Cloudside:
wget https://github.com/kubeedge/kubeedge/releases/download/v1.17.0/keadm-v1.17.0-linux-amd64.tar.gz
tar -zxvf keadm-v1.17.0-linux-amd64.tar.gz
cp keadm-v1.17.0-linux-amd64/keadm/keadm /usr/local/bin/keadm
keadm init --advertise-address="89.105.78.161" --kubeedge-version=v1.22.0 --kube-config=/root/.kube/config
keadm manifest generate --advertise-address="89.105.78.161" --kube-config=/root/.kube/config > kubeedge-cloudcore.yaml
patch:
cloudcore.yaml: |
apiVersion: cloudcore.config.kubeedge.io/v1alpha2
commonConfig:
monitorServer:
bindAddress: 127.0.0.1:9091
tunnelPort: 10354
featureGates:
requireAuthorization: false
kind: CloudCore
kubectl apply -f kubeedge-cloudcore.yaml -n kubeedge
kubectl apply -f edgenodeport.yaml -n kubeedge
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
Edge Side:
export KUBEEDGE_VERSION=v1.22.0
export CLOUD_MASTER_IP=34.132.113.155
export EDGE_NODE_NAME=edge-node-02
Step 1 : Download & unpack containerd package
Containerd versions can be found in this location : https://github.com/containerd/containerd/releases
Download :
wget https://github.com/containerd/containerd/releases/download/v1.6.14/containerd-1.6.14-linux-amd64.tar.gz
Unpack :
sudo tar Cxzvf /usr/local containerd-1.6.14-linux-amd64.tar.gz
Step 2 : Install runc
Runc is a standardized runtime for spawning and running containers on Linux according to the OCI specification
wget https://github.com/opencontainers/runc/releases/download/v1.1.3/runc.amd64
sudo install -m 755 runc.amd64 /usr/local/sbin/runc
Step 3: Download and install CNI plugins :
wget https://github.com/containernetworking/plugins/releases/download/v1.1.1/cni-plugins-linux-amd64-v1.1.1.tgz
sudo mkdir -p /opt/cni/bin
sudo tar Cxzvf /opt/cni/bin cni-plugins-linux-amd64-v1.1.1.tgz
Step 4: Configure containerd
Create a containerd directory for the configuration file
config.toml is the default configuration file for containerd
Enable systemd group . Use sed command to change the parameter in config.toml instead of using vi editor
Convert containerd into service
sudo mkdir /etc/containerd
containerd config default | sudo tee /etc/containerd/config.toml
sudo sed -i 's/SystemdCgroup \= false/SystemdCgroup \= true/g' /etc/containerd/config.toml
sudo curl -L https://raw.githubusercontent.com/containerd/containerd/main/containerd.service -o /etc/systemd/system/containerd.service
Step 4.1
remove SystemdCgroup = true line from /etc/containerd/config.toml.
Step 4.2
mkdir -p /etc/cni/net.d/
$ cat >/etc/cni/net.d/10-containerd-net.conflist <<EOF
{
"cniVersion": "1.0.0",
"name": "containerd-net",
"plugins": [
{
"type": "bridge",
"bridge": "cni0",
"isGateway": true,
"ipMasq": true,
"promiscMode": true,
"ipam": {
"type": "host-local",
"ranges": [
[{
"subnet": "10.88.0.0/16"
}],
[{
"subnet": "2001:db8:4860::/64"
}]
],
"routes": [
{ "dst": "0.0.0.0/0" },
{ "dst": "::/0" }
]
}
},
{
"type": "portmap",
"capabilities": {"portMappings": true}
}
]
}
EOF
Step 5: Start containerd service
sudo systemctl daemon-reload
sudo systemctl enable --now containerd
sudo systemctl status containerd
step 6: install crictl
VERSION="v1.35.0" # check latest version in /releases page
wget https://github.com/kubernetes-sigs/cri-tools/releases/download/$VERSION/crictl-$VERSION-linux-amd64.tar.gz
sudo tar zxvf crictl-$VERSION-linux-amd64.tar.gz -C /usr/local/bin
rm -f crictl-$VERSION-linux-amd64.tar.gz
Taint:kubectl taint nodes edge-node-2 edgenode=true:NoExecute
Label: kubectl label node edge-node-2 edgeproject=resilki
edge-cleanup.sh:
#!/bin/bash
set -euo pipefail
echo "==== EDGE NODE CLEANUP START ===="
DATE=$(date)
echo "Timestamp: $DATE"
# -------------------------------
# 1. Kill processi orfani (safe)
# -------------------------------
echo "[1] Checking orphan processes..."
ORPHANS=$(ps -eo pid,ppid,cmd | awk '$2 == 1 {print $1}')
for PID in $ORPHANS; do
if [ "$PID" != "1" ]; then
echo "Killing orphan PID: $PID"
kill -9 "$PID" 2>/dev/null || true
fi
done
# -------------------------------
# 2. Cleanup containerd (safe)
# -------------------------------
echo "[2] Cleaning containerd..."
if command -v crictl &> /dev/null; then
echo "Using crictl..."
# rimuove solo container stopped
crictl ps -a --state Exited -q | xargs -r crictl rm || true
# rimuove pod sandbox non più validi
crictl pods --state NotReady -q | xargs -r crictl rmp || true
# pulizia immagini dangling (SAFE)
crictl rmi --prune || true
else
echo "crictl not found, skipping..."
fi
# -------------------------------
# 3. Restart containerd
# -------------------------------
echo "[3] Restarting containerd..."
systemctl restart containerd
# -------------------------------
# 4. Cleanup kubelet (soft)
# -------------------------------
echo "[4] Cleaning kubelet state (soft)..."
# Rimuove solo pod non più esistenti
find /var/lib/kubelet/pods -mindepth 1 -maxdepth 1 -type d -mtime +1 -exec rm -rf {} + || true
# -------------------------------
# 5. Restart kube services
# -------------------------------
echo "[5] Restarting kubelet + edgecore..."
systemctl restart kubelet || true
systemctl restart edgecore || true
# -------------------------------
# 6. Verifica connessione CloudCore
# -------------------------------
echo "[6] Checking connectivity to CloudCore..."
CLOUD_IP="89.105.78.161"
PORT="10002"
if timeout 5 bash -c "</dev/tcp/$CLOUD_IP/$PORT"; then
echo "Cloud reachable"
else
echo "WARNING: Cloud NOT reachable"
fi
# -------------------------------
# 7. Verifica porte MQTT locali
# -------------------------------
echo "[7] Checking MQTT port..."
ss -tulnp | grep 1883 || echo "WARNING: Mosquitto not listening"
echo "==== EDGE NODE CLEANUP DONE ===="
/etc/systemd/system/edge-cleanup.service:
[Unit]
Description=Edge Node Cleanup
After=network.target
[Service]
Type=oneshot
ExecStart=/usr/local/bin/edge-cleanup.sh
RemainAfterExit=true
[Install]
WantedBy=multi-user.target
chmod +x /usr/local/bin/edge-cleanup.sh
systemctl daemon-reload
systemctl enable edge-cleanup
export KUBEEDGE_VERSION=v1.22.0
export CLOUD_MASTER_IP=194.110.57.153
export EDGE_NODE_NAME=edge-node-02
curl -L https://github.com/kubeedge/kubeedge/releases/download/${KUBEEDGE_VERSION}/keadm-${KUBEEDGE_VERSION}-linux-amd64.tar.gz | tar -xz
sudo mv keadm-${KUBEEDGE_VERSION}-linux-amd64/keadm/keadm /usr/local/bin/
sudo keadm join \
--cloudcore-ipport=${CLOUD_MASTER_IP}:10000 \
--edgenode-name=${EDGE_NODE_NAME} \
--token=f871f93cffd630c906bf381dae4496544a111075071abfec060e2db4ab417b6e.eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NzUyOTM2NjJ9.xvMdgApjtPDpPm-GShmR6ghjBgvFTJsJf6JTJLeSK08 \
--kubeedge-version=${KUBEEDGE_VERSION}
kubectl taint nodes edge-node-02 edgenode=true:NoExecute
test sensor:
sudo apt-get install mosquitto-clients
sensor.sh
#!/bin/bash
BROKER="localhost"
TOPIC="sensors/home/livingroom"
while true; do
TEMP=$(awk -v min=20 -v max=30 'BEGIN{srand(); print min+rand()*(max-min)}')
HUM=$(awk -v min=40 -v max=80 'BEGIN{srand(); print min+rand()*(max-min)}')
PAYLOAD=$(printf '{"temperature": %.2f, "humidity": %.2f}' $TEMP $HUM)
echo "Sending: $PAYLOAD"
mosquitto_pub -h $BROKER -t $TOPIC -m "$PAYLOAD"
sleep 5
done
verifica :
mosquitto_sub -h localhost -t sensors/home/livingroom
#### modifiche per rasperry##############################################
#cgroups
vi /boot/firmware/cmdline.txt
Add cgroup parameters:Add the following to the end of the existing line (do not create a new line):
textcgroup_enable=cpuset cgroup_enable=memory cgroup_memory=1
#streaming
su /etc/kubeedge/config/edgecore.yaml
modules:
edgeStream:
enable: true