Skip to content

Instantly share code, notes, and snippets.

@c0dyhi11
Last active May 31, 2024 19:48
Show Gist options
  • Save c0dyhi11/77360a0e17b45e1abf06517de1f9ed48 to your computer and use it in GitHub Desktop.
Save c0dyhi11/77360a0e17b45e1abf06517de1f9ed48 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Set all Variables
HOSTNAME='tinkerbell.hill.local'
USERNAME='chill'
INTERFACE_NAME='enp1s0'
HOST_IP='192.168.161.1'
HOST_MASK='24'
DEFAULT_ROUTE='192.168.161.254'
DNS_SERVERS='[192.168.161.254,8.8.8.8]'
TINK_LB_IP="192.168.161.2"
NETBOX_LB_IP="192.168.161.3"
# This is from a fresh version of Ubuntu Server 24.04 LTS
# Assuming passwordless sudo is enabled...
# Set static ip
sudo rm -f /etc/netplan/*
cat << EOF | sudo tee /etc/netplan/00-static-ip.yaml
network:
ethernets:
$INTERFACE_NAME:
dhcp4: false
addresses:
- $HOST_IP/$HOST_MASK
routes:
- to: default
via: $DEFAULT_ROUTE
nameservers:
addresses: $DNS_SERVERS
version: 2
EOF
sudo chmod 0600 /etc/netplan/00-static-ip.yaml
sudo netplan apply
# Set hostname before installing K3s
hostname-ctl set-hostname $HOSTNAME
# Install k3s
curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="server --disable traefik --disable local-storage --disable servicelb --disable metrics-server" sh -
mkdir -p $HOME/.kube/
cp /etc/rancher/k3s/k3s.yaml $HOME/.kube/config
sudo chown -R $USERNAME:$USERNAME /home/$USERNAME/.kube
echo "export KUBECONFIG=/home/$USERNAME/.kube/config" >> .bashrc
export KUBECONFIG=/home/$USERNAME/.kube/config
# Install Longhorn
kubectl apply -f https://raw.githubusercontent.com/longhorn/longhorn/v1.6.0/deploy/longhorn.yaml
# Install Helm
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
# Install Tinkerbell
trusted_proxies=$(kubectl get nodes -o jsonpath='{.items[*].spec.podCIDR}' | tr ' ' ',')
helm install tink-stack oci://ghcr.io/tinkerbell/charts/stack --create-namespace --namespace tink-system --wait --set "smee.trustedProxies={${trusted_proxies}}" --set "hegel.trustedProxies={${trusted_proxies}}" --set "stack.loadBalancerIP=$TINK_LB_IP" --set "smee.publicIP=$TINK_LB_IP"
# Download Ubuntu to Hook
kubectl apply -n tink-system -f https://raw.githubusercontent.com/tinkerbell/playground/main/vagrant/ubuntu-download.yaml
# Install netbox
git clone https://github.com/netbox-community/netbox-chart.git
cd netbox-chart/charts/netbox/
helm dependency build
cd ..
helm install netbox netbox/ --create-namespace --namespace netbox --set postgresql.auth.postgresPassword=netbox --set postgresql.auth.password=netbox --set redis.auth.password=netbox --set preferIPv4=true
cat << EOF > netbox-svc-lb.yaml
apiVersion: v1
kind: Service
metadata:
name: netbox-lb
namespace: netbox
spec:
type: LoadBalancer
loadBalancerClass: kube-vip.io/kube-vip-class
loadBalancerIP: $192.168.161.3
ports:
- name: http
port: 80
protocol: TCP
targetPort: http
selector:
app.kubernetes.io/component: netbox
app.kubernetes.io/instance: netbox
app.kubernetes.io/name: netbox
EOF
kubectl apply -f netbox-svc-lb.yaml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment