Skip to content

Instantly share code, notes, and snippets.

@hunzo
Last active July 3, 2024 03:08
Show Gist options
  • Save hunzo/c7656c851d10cb37cf4fe96b68ea66b6 to your computer and use it in GitHub Desktop.
Save hunzo/c7656c851d10cb37cf4fe96b68ea66b6 to your computer and use it in GitHub Desktop.
install K3s with metallb and nginx-ingress

Install K3s with metallb and nginx-ingress

server ip role
k3s-control.dev.local 192.168.1.100 control-plane
k3s-node-01.dev.local 192.168.1.101 node-01

Setup control-plane

  • disable traefik, servicelb

Install control-plane

curl -sfL https://get.k3s.io | sh -s - server --disable=traefik,servicelb
  • setup auto completion
echo 'alias kubectl="sudo k3s kubectl"' >> ~/.bashrc
echo 'alias k="kubectl"' >> ~/.bashrc
echo "source <(kubectl completion bash)" >> ~/.bashrc
echo "complete -o default -F __start_kubectl k" >> ~/.bashrc

source .bashrc

Get token @control-plane

sudo cat /var/lib/rancher/k3s/server/token
K1070f0efca2cc2f23adfe6ad2a1a58133903e17bfe9ffd15d7648940c483f0c21f::server:00296542ce6f21970fecd8b4964e16fe

Install node-01

export TOKEN=K1070f0efca2cc2f23adfe6ad2a1a58133903e17bfe9ffd15d7648940c483f0c21f::server:00296542ce6f21970fecd8b4964e16fe
export K3S_URL=https://192.168.1.100:6443

curl -sfL https://get.k3s.io | K3S_URL=$K3S_URL K3S_TOKEN=$TOKEN sh -

Install Metallb

kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.14.5/config/manifests/metallb-native.yaml
  • create ipppool.yaml
apiVersion: metallb.io/v1beta1
kind: IPAddressPool
metadata:
  name: production
  namespace: metallb-system
spec:
  addresses:
    - 192.168.1.200-192.168.1.200
  • create l2advertise.yaml
apiVersion: metallb.io/v1beta1
kind: L2Advertisement
metadata:
  name: example
  namespace: metallb-system
spec:
  ipAddressPools:
    - production

Install nginx-ingress

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

Example Create Application

kubectl create namespace app
kubectl create deployment app --image gcr.io/google-samples/hello-app:1.0 --namespace app
kubectl create svc clusterip app --namespace app --tcp 8080:8080
kubectl create ingress app --class=nginx --namespace app --rule foo.bar/*=app:8080
kubectl create secret docker-registry SECRET_NAME \
    --namespace=YOUR_NAMESPACE \
    --docker-server=docker.io \
    --docker-username=USERNAME \
    --docker-password=PASSWORD \
    --docker-email=EMAIL_ADDRESS \
    --output=yaml \
    --dry-run=client
kubectl annotate service --namespace app app metallb.universe.tf/allow-shared-ip="mgmt"

node taint k3s

kubectl taint node k3s-control-plane-name k3s-controlplane=true:NoSchedule

Single Host k3s with calico

curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="--flannel-backend=none --disable-network-policy --cluster-cidr=192.168.0.0/16" sh -
kubectl apply -f https://raw.githubusercontent.com/projectcalico/calico/v3.28.0/manifests/calico.yaml

MultiHost k3s with calico and Metallb

Install k3s

curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="--flannel-backend=none --disable-network-policy --disable=traefik,servicelb --cluster-cidr=192.168.0.0/16" sh -

Install Calico

kubectl apply -f https://raw.githubusercontent.com/projectcalico/calico/v3.28.0/manifests/calico.yaml

Get token

export TOKEN=K102a49ba59c8c085641e2067ddbfe3ea139d83843044664bbd7c067f4f5163c165::server:e3389daae45fc2643fdc516b613646f7
export K3S_URL=https://control_plane_ip_address:6443

Install Metallb

kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.14.5/config/manifests/metallb-native.yaml

@Node install k3s

export TOKEN=K102a49ba59c8c085641e2067ddbfe3ea139d83843044664bbd7c067f4f5163c165::server:e3389daae45fc2643fdc516b613646f7
export K3S_URL=https://control_plane_ip_address:6443
curl -sfL https://get.k3s.io | K3S_URL=$K3S_URL K3S_TOKEN=$TOKEN sh -
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment