From c83ffd7c612794facbb472b2da7c0467b885b435 Mon Sep 17 00:00:00 2001 From: Christoph Kleineweber Date: Mon, 18 Jan 2021 14:26:07 +0100 Subject: [PATCH 1/2] Add virtual IP address for API server in vSphere example Set up keepalived on control plane nodes in vSphere Terraform example to establish virtual IP address for Kubernetes API. API endpoint in Terraform output is set to first control plane node if no IP address is specified. The existing Gobetween load-balancer is removed. --- examples/terraform/vsphere/etc_gobetween.tpl | 26 ------ .../etc_keepalived_check_apiserver_sh.tpl | 11 +++ .../etc_keepalived_keepalived_conf.tpl | 27 ++++++ examples/terraform/vsphere/gobetween.sh | 60 ------------- examples/terraform/vsphere/keepalived.sh | 33 +++++++ examples/terraform/vsphere/main.tf | 90 +++++++------------ examples/terraform/vsphere/outputs.tf | 2 +- examples/terraform/vsphere/variables.tf | 14 +++ 8 files changed, 117 insertions(+), 146 deletions(-) delete mode 100644 examples/terraform/vsphere/etc_gobetween.tpl create mode 100644 examples/terraform/vsphere/etc_keepalived_check_apiserver_sh.tpl create mode 100644 examples/terraform/vsphere/etc_keepalived_keepalived_conf.tpl delete mode 100755 examples/terraform/vsphere/gobetween.sh create mode 100755 examples/terraform/vsphere/keepalived.sh diff --git a/examples/terraform/vsphere/etc_gobetween.tpl b/examples/terraform/vsphere/etc_gobetween.tpl deleted file mode 100644 index fdaae71a7..000000000 --- a/examples/terraform/vsphere/etc_gobetween.tpl +++ /dev/null @@ -1,26 +0,0 @@ -[api] -enabled = false - -[servers.default] -protocol = "tcp" -bind = "0.0.0.0:6443" -balance = "roundrobin" -max_connections = 10000 -client_idle_timeout = "10m" -backend_idle_timeout = "10m" -backend_connection_timeout = "2s" - -[servers.default.discovery] -kind = "static" -static_list = [ - %{ for target in lb_targets ~} - "${target}:6443", - %{ endfor ~} -] - -[servers.default.healthcheck] -kind = "ping" -interval = "10s" -timeout = "2s" -fails = 2 -passes = 1 diff --git a/examples/terraform/vsphere/etc_keepalived_check_apiserver_sh.tpl b/examples/terraform/vsphere/etc_keepalived_check_apiserver_sh.tpl new file mode 100644 index 000000000..b5f3bd7f7 --- /dev/null +++ b/examples/terraform/vsphere/etc_keepalived_check_apiserver_sh.tpl @@ -0,0 +1,11 @@ +#!/bin/sh + +errorExit() { + echo "*** $*" 1>&2 + exit 1 +} + +curl --silent --max-time 2 --insecure https://localhost:6443/healthz -o /dev/null || errorExit "Error GET https://localhost:6443/healthz" +if ip addr | grep -q ${APISERVER_VIP}; then + curl --silent --max-time 2 --insecure https://${APISERVER_VIP}:6443/healthz -o /dev/null || errorExit "Error GET https://${APISERVER_VIP}:6443/healthz" +fi diff --git a/examples/terraform/vsphere/etc_keepalived_keepalived_conf.tpl b/examples/terraform/vsphere/etc_keepalived_keepalived_conf.tpl new file mode 100644 index 000000000..165e39cd1 --- /dev/null +++ b/examples/terraform/vsphere/etc_keepalived_keepalived_conf.tpl @@ -0,0 +1,27 @@ +global_defs { + router_id LVS_DEVEL +} +vrrp_script check_apiserver { + script "/etc/keepalived/check_apiserver.sh" + interval 3 + weight -2 + fall 10 + rise 2 +} + +vrrp_instance VI_1 { + state ${STATE} + interface ${INTERFACE} + virtual_router_id ${ROUTER_ID} + priority ${PRIORITY} + authentication { + auth_type PASS + auth_pass ${AUTH_PASS} + } + virtual_ipaddress { + ${APISERVER_VIP} + } + track_script { + check_apiserver + } +} diff --git a/examples/terraform/vsphere/gobetween.sh b/examples/terraform/vsphere/gobetween.sh deleted file mode 100755 index 4a8da2204..000000000 --- a/examples/terraform/vsphere/gobetween.sh +++ /dev/null @@ -1,60 +0,0 @@ -#!/usr/bin/env bash - -# Copyright 2019 The KubeOne Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# This script is mostly used in CI -# It installs dependencies and starts the tests - -set -euf -o pipefail - -GOBETWEEN_VERSION=0.7.0 - -noop() { : "didn't detected package manager, noop"; } - -PKG_MANAGER="noop" - -[ "$(command -v yum)" ] && PKG_MANAGER=yum -[ "$(command -v apt-get)" ] && PKG_MANAGER=apt-get - -sudo ${PKG_MANAGER} install tar -y - -mkdir -p /tmp/gobetween -cd /tmp/gobetween -curl -L -o gobetween_${GOBETWEEN_VERSION}_linux_amd64.tar.gz \ - https://github.com/yyyar/gobetween/releases/download/${GOBETWEEN_VERSION}/gobetween_${GOBETWEEN_VERSION}_linux_amd64.tar.gz -tar xvf gobetween_${GOBETWEEN_VERSION}_linux_amd64.tar.gz -sudo mkdir -p /opt/bin -sudo mv gobetween /opt/bin/gobetween -sudo chown root:root /opt/bin/gobetween - -cat < Date: Mon, 18 Jan 2021 15:29:55 +0100 Subject: [PATCH 2/2] Update vSphere example README for virtual API IP --- examples/terraform/vsphere/README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/examples/terraform/vsphere/README.md b/examples/terraform/vsphere/README.md index dd590183d..b9d568ca8 100644 --- a/examples/terraform/vsphere/README.md +++ b/examples/terraform/vsphere/README.md @@ -40,12 +40,15 @@ See the [Terraform loadbalancers in examples document][docs-tf-loadbalancer]. | ssh\_username | SSH user, used only in output | string | `"root"` | no | | template\_name | template name | string | `"ubuntu-18.04"` | no | | worker\_os | OS to run on worker machines | string | `"ubuntu"` | no | +| api_vip | Virtual IP address for Kubernetes API, established by keepalived" | string | `""` | no | +| vrrp_interface | NIC to establish API IP address | string | `"ens192"` | no | +| vrrp_router_id | Unique router id for VRRP protocol | int | 43 | no | ## Outputs | Name | Description | |------|-------------| -| kubeone\_api | kube-apiserver LB endpoint | +| kubeone\_api | kube-apiserver endpoint. Either configured virtual IP or first node | | kubeone\_hosts | Control plane endpoints to SSH to | | kubeone\_workers | Workers definitions, that will be transformed into MachineDeployment object |