Created
November 10, 2020 16:03
-
-
Save angelbarrera92/91ac396b5c06843d36d1c0f11cdd39f4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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