Skip to content

Instantly share code, notes, and snippets.

@khusseini
Created June 27, 2023 09:20
Show Gist options
  • Save khusseini/2c9da1ebe252ee040a3195ffa6e13cfa to your computer and use it in GitHub Desktop.
Save khusseini/2c9da1ebe252ee040a3195ffa6e13cfa to your computer and use it in GitHub Desktop.

Usage


sudo create-k0s-virtual-network-device.sh $(ip route get 8.8.8.8 | awk -- '{printf $5}')

k0s config create >/tmp/k0s.yaml

yq -i \
  '.spec.extensions.storage.type = "openebs_local_storage" | .spec.extensions.storage.create_default_storage_class = true' \
  /tmp/k0s.yaml
yq -i \
  '.spec.api.address = "192.168.123.1"' /tmp/k0s.yaml
  mv /tmp/k0s.yaml /etc/k0s/k0s.yaml

sudo k0s install controller --single
#!/usr/bin/env bash
TARGET_NAME=${1:-"wlp3s0"}
BRIDGE_IP=${2:-"192.168.123.1/24"}
BRIDGE_NAME=${3:-"br0"}
VETH_NAME=${4:-"vethk0s"}
# Create virtual network device if it doesn't exists
if ! ip link show $VETH_NAME >/dev/null 2>&1; then
# Create the virtual network device pair
ip link add name $VETH_NAME type veth
fi
# Create bridge interface if it doesn't exist
if ! ip link show $BRIDGE_NAME >/dev/null 2>&1; then
brctl addbr $BRIDGE_NAME
ip link set dev $BRIDGE_NAME up
fi
# Connect virtual network device to bridge interface
brctl addif $BRIDGE_NAME $VETH_NAME
# Unique static IP address for the virtual network device
ip addr add $BRIDGE_IP dev $BRIDGE_NAME
# Enable IP forwarding
sysctl net.ipv4.ip_forward=1
# Connect default network device to the bridge interface
brctl addif $BRIDGE_NAME $TARGET_NAME
echo "Virtual network device $VETH_NAME created and linked to $BRIDGE_NAME with IP $BRIDGE_IP."
#!/bin/bash
VETH_NAME="vethk0s"
BRIDGE_NAME="br0"
# Delete bridge interface
ip link set dev $BRIDGE_NAME down
brctl delbr $BRIDGE_NAME
# Delete virtual network device
ip link delete $VETH_NAME
echo "Virtual network device removed"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment