Skip to content

Commit

Permalink
Add script to generate MetalLB IPAddressPool for docker network.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikenairn committed Nov 22, 2023
1 parent c2fe928 commit f076e65
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 55 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ deploy-dependencies: kustomize dependencies-manifests ## Deploy dependencies to
install-metallb: $(KUSTOMIZE) ## Installs the metallb load balancer allowing use of an LoadBalancer type with a gateway
$(KUSTOMIZE) build config/metallb | kubectl apply -f -
kubectl -n metallb-system wait --for=condition=ready pod --selector=app=metallb --timeout=60s
./utils/docker-network-ipaddresspool.sh kind | kubectl apply -n metallb-system -f -

.PHONY: uninstall-metallb
uninstall-metallb: $(KUSTOMIZE)
Expand Down
27 changes: 0 additions & 27 deletions doc/user-guides/gateway-dns.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,33 +31,6 @@ Install metallb:
make install-metallb
```

Fetch the current kind networks subnet:
```shell
docker network inspect kind -f '{{ (index .IPAM.Config 0).Subnet }}'
```
Response:
```shell
"172.18.0.0/16"
```

Create IPAddressPool within kind network(Fetched by the command above) e.g. 172.18.200
```shell
kubectl -n metallb-system apply -f -<<EOF
apiVersion: metallb.io/v1beta1
kind: IPAddressPool
metadata:
name: kuadrant-local
spec:
addresses:
- 172.18.200.0/24
---
apiVersion: metallb.io/v1beta1
kind: L2Advertisement
metadata:
name: empty
EOF
```

Create a namespace:
```shell
kubectl create namespace my-gateways
Expand Down
29 changes: 1 addition & 28 deletions doc/user-guides/gateway-tls.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,33 +30,6 @@ Install metallb:
make install-metallb
```

Fetch the current kind networks subnet:
```shell
docker network inspect kind -f '{{ (index .IPAM.Config 0).Subnet }}'
```
Response:
```shell
"172.18.0.0/16"
```

Create IPAddressPool within kind network(Fetched by the command above) e.g. 172.18.200
```shell
kubectl -n metallb-system apply -f -<<EOF
apiVersion: metallb.io/v1beta1
kind: IPAddressPool
metadata:
name: kuadrant-local
spec:
addresses:
- 172.18.200.0/24
---
apiVersion: metallb.io/v1beta1
kind: L2Advertisement
metadata:
name: empty
EOF
```

Create a namespace:
```shell
kubectl create namespace my-gateways
Expand Down Expand Up @@ -199,7 +172,7 @@ EOF

Verify we can access the service via TLS:
```shell
curl -k https://api.toystore.local --resolve 'api.toystore.local:443:172.18.200.0'
curl -vkI https://api.toystore.local --resolve 'api.toystore.local:443:172.18.200.0'
```

## Cleanup
Expand Down
31 changes: 31 additions & 0 deletions utils/docker-network-ipaddresspool.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

# Generates a MetalLB IpAddressPool for the given docker network.
# https://metallb.org/configuration/#defining-the-ips-to-assign-to-the-load-balancer-services
#
# Example:
# ./utils/docker-network-ipaddresspool.sh kind | kubectl apply -n metallb-system -f -

set -euo pipefail

networkName=$1

subnet=`docker network inspect $networkName -f '{{ (index .IPAM.Config 0).Subnet }}'`
# shellcheck disable=SC2206
subnetParts=(${subnet//./ })
cidr="${subnetParts[0]}.${subnetParts[1]}.200.0/24"

cat <<EOF
apiVersion: metallb.io/v1beta1
kind: IPAddressPool
metadata:
name: kuadrant-local
spec:
addresses:
- $cidr
---
apiVersion: metallb.io/v1beta1
kind: L2Advertisement
metadata:
name: empty
EOF

0 comments on commit f076e65

Please sign in to comment.