4 # Copyright 2020 Samsung Electronics Co., Ltd.
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
22 $0 Automatic configuration using external addresess from nodes
23 $0 --help This message
25 $0 [cluster_ip1] ... [cluster_ipn] Cluster address or ip ranges
30 find_nodes_with_external_addrs()
32 local WORKER_NODES=$(kubectl get no -l node-role.kubernetes.io/worker=true -o jsonpath='{.items..metadata.name}')
33 for worker in $WORKER_NODES; do
34 local external_ip=$(kubectl get no $worker -o jsonpath='{.metadata.annotations.rke\.cattle\.io/external-ip }')
35 local internal_ip=$(kubectl get no $worker -o jsonpath='{.metadata.annotations.rke\.cattle\.io/internal-ip }')
36 if [ $internal_ip != $external_ip ]; then
44 cat <<CNFEOF | kubectl apply -f -
48 namespace: metallb-system
56 $(for value in "$@"; do echo -e " - $value"; done)
60 generate_config_from_single_addr() {
61 generate_config_map "$1 - $1"
65 kubectl apply -f https://raw.githubusercontent.com/google/metallb/v0.9.3/manifests/namespace.yaml
66 kubectl apply -f https://raw.githubusercontent.com/google/metallb/v0.9.3/manifests/metallb.yaml
68 kubectl create secret generic -n metallb-system memberlist --from-literal=secretkey="$(openssl rand -base64 128)"
71 automatic_configuration() {
73 generate_config_from_single_addr $(find_nodes_with_external_addrs)
76 manual_configuration() {
78 generate_config_map $@
81 if [ $# -eq 1 ] && [ "$1" = "-h" ]; then
83 if [ $# -eq 1 ] && [ "$1" = "--help" ]; then
85 elif [ $# -eq 0 ]; then
86 automatic_configuration
88 manual_configuration $@