Skip to content

Instantly share code, notes, and snippets.

@angelbarrera92
Created November 10, 2020 16:03
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save angelbarrera92/91ac396b5c06843d36d1c0f11cdd39f4 to your computer and use it in GitHub Desktop.
Save angelbarrera92/91ac396b5c06843d36d1c0f11cdd39f4 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Create the cluster
kind create cluster --name lb
# Get the configuration
kind get kubeconfig --name lb > /tmp/lb-kubeconfig
# Deploy metallb
KUBECONFIG=/tmp/lb-kubeconfig kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.9.5/manifests/namespace.yaml
KUBECONFIG=/tmp/lb-kubeconfig kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.9.5/manifests/metallb.yaml
KUBECONFIG=/tmp/lb-kubeconfig kubectl create secret generic -n metallb-system memberlist --from-literal=secretkey="$(openssl rand -base64 128)"
# Gather information about local networking
network=$(docker inspect lb-control-plane | jq -r .[0].HostConfig.NetworkMode)
echo "## Docker network: $network"
subnet=$(docker network inspect $network | jq -r .[0].IPAM.Config[0].Subnet)
echo "## Subnet: $subnet"
gw=$(docker network inspect $network | jq -r .[0].IPAM.Config[0].Gateway)
echo "## Gateway: $gw"
read A B C D <<<"${gw//./ }"
# Apply the configuration based on the gathered information
cat << EOF > /tmp/metallb-config.yaml
apiVersion: v1
kind: ConfigMap
metadata:
namespace: metallb-system
name: config
data:
config: |
address-pools:
- name: default
protocol: layer2
addresses:
- $A.$B.255.1-$A.$B.255.200
EOF
KUBECONFIG=/tmp/lb-kubeconfig kubectl apply -f /tmp/metallb-config.yaml
# Ready!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment