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