mirror of https://github.com/k3s-io/k3s
HA master: fixed removal of master replica w/no suffix (GCE).
HA master (GCE): fixed removal of master replica w/no suffix; fixed api-server flag of kubelets to point to external cluster's IP.pull/6/head
parent
c900a0ed7b
commit
a93e10b342
|
@ -540,14 +540,21 @@ EOF
|
||||||
function write-master-env {
|
function write-master-env {
|
||||||
# If the user requested that the master be part of the cluster, set the
|
# If the user requested that the master be part of the cluster, set the
|
||||||
# environment variable to program the master kubelet to register itself.
|
# environment variable to program the master kubelet to register itself.
|
||||||
if [[ "${REGISTER_MASTER_KUBELET:-}" == "true" ]]; then
|
if [[ "${REGISTER_MASTER_KUBELET:-}" == "true" && -z "${KUBELET_APISERVER:-}" ]]; then
|
||||||
KUBELET_APISERVER="${MASTER_NAME}"
|
KUBELET_APISERVER="${MASTER_NAME}"
|
||||||
fi
|
fi
|
||||||
|
if [[ -z "${KUBERNETES_MASTER_NAME:-}" ]]; then
|
||||||
|
KUBERNETES_MASTER_NAME="${MASTER_NAME}"
|
||||||
|
fi
|
||||||
|
|
||||||
build-kube-env true "${KUBE_TEMP}/master-kube-env.yaml"
|
build-kube-env true "${KUBE_TEMP}/master-kube-env.yaml"
|
||||||
}
|
}
|
||||||
|
|
||||||
function write-node-env {
|
function write-node-env {
|
||||||
|
if [[ -z "${KUBERNETES_MASTER_NAME:-}" ]]; then
|
||||||
|
KUBERNETES_MASTER_NAME="${MASTER_NAME}"
|
||||||
|
fi
|
||||||
|
|
||||||
build-kube-env false "${KUBE_TEMP}/node-kube-env.yaml"
|
build-kube-env false "${KUBE_TEMP}/node-kube-env.yaml"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -582,7 +589,7 @@ SERVER_BINARY_TAR_HASH: $(yaml-quote ${SERVER_BINARY_TAR_HASH})
|
||||||
SALT_TAR_URL: $(yaml-quote ${salt_tar_url})
|
SALT_TAR_URL: $(yaml-quote ${salt_tar_url})
|
||||||
SALT_TAR_HASH: $(yaml-quote ${SALT_TAR_HASH})
|
SALT_TAR_HASH: $(yaml-quote ${SALT_TAR_HASH})
|
||||||
SERVICE_CLUSTER_IP_RANGE: $(yaml-quote ${SERVICE_CLUSTER_IP_RANGE})
|
SERVICE_CLUSTER_IP_RANGE: $(yaml-quote ${SERVICE_CLUSTER_IP_RANGE})
|
||||||
KUBERNETES_MASTER_NAME: $(yaml-quote ${MASTER_NAME})
|
KUBERNETES_MASTER_NAME: $(yaml-quote ${KUBERNETES_MASTER_NAME})
|
||||||
ALLOCATE_NODE_CIDRS: $(yaml-quote ${ALLOCATE_NODE_CIDRS:-false})
|
ALLOCATE_NODE_CIDRS: $(yaml-quote ${ALLOCATE_NODE_CIDRS:-false})
|
||||||
ENABLE_CLUSTER_MONITORING: $(yaml-quote ${ENABLE_CLUSTER_MONITORING:-none})
|
ENABLE_CLUSTER_MONITORING: $(yaml-quote ${ENABLE_CLUSTER_MONITORING:-none})
|
||||||
DOCKER_REGISTRY_MIRROR_URL: $(yaml-quote ${DOCKER_REGISTRY_MIRROR_URL:-})
|
DOCKER_REGISTRY_MIRROR_URL: $(yaml-quote ${DOCKER_REGISTRY_MIRROR_URL:-})
|
||||||
|
|
|
@ -776,6 +776,8 @@ function create-master() {
|
||||||
create-static-ip "${MASTER_NAME}-ip" "${REGION}"
|
create-static-ip "${MASTER_NAME}-ip" "${REGION}"
|
||||||
MASTER_RESERVED_IP=$(gcloud compute addresses describe "${MASTER_NAME}-ip" \
|
MASTER_RESERVED_IP=$(gcloud compute addresses describe "${MASTER_NAME}-ip" \
|
||||||
--project "${PROJECT}" --region "${REGION}" -q --format='value(address)')
|
--project "${PROJECT}" --region "${REGION}" -q --format='value(address)')
|
||||||
|
KUBELET_APISERVER="${MASTER_RESERVED_IP}"
|
||||||
|
KUBERNETES_MASTER_NAME="${MASTER_RESERVED_IP}"
|
||||||
|
|
||||||
create-certs "${MASTER_RESERVED_IP}"
|
create-certs "${MASTER_RESERVED_IP}"
|
||||||
|
|
||||||
|
@ -1165,8 +1167,10 @@ function remove-replica-from-etcd() {
|
||||||
--project "${PROJECT}" \
|
--project "${PROJECT}" \
|
||||||
--zone "${EXISTING_MASTER_ZONE}" \
|
--zone "${EXISTING_MASTER_ZONE}" \
|
||||||
--command \
|
--command \
|
||||||
"curl -s localhost:${port}/v2/members/\$(curl -s localhost:${port}/v2/members -XGET | sed 's/{\\\"id/\n/g' | grep ${REPLICA_NAME} | cut -f 3 -d \\\") -XDELETE -L 2>/dev/null"
|
"curl -s localhost:${port}/v2/members/\$(curl -s localhost:${port}/v2/members -XGET | sed 's/{\\\"id/\n/g' | grep ${REPLICA_NAME}\\\" | cut -f 3 -d \\\") -XDELETE -L 2>/dev/null"
|
||||||
return $?
|
local -r res=$?
|
||||||
|
echo "Removing etcd replica, name: ${REPLICA_NAME}, port: ${port}, result: ${res}"
|
||||||
|
return "${res}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Delete a kubernetes cluster. This is called from test-teardown.
|
# Delete a kubernetes cluster. This is called from test-teardown.
|
||||||
|
@ -1276,14 +1280,15 @@ function kube-down() {
|
||||||
if [[ "${REMAINING_MASTER_COUNT}" == "1" ]]; then
|
if [[ "${REMAINING_MASTER_COUNT}" == "1" ]]; then
|
||||||
if gcloud compute forwarding-rules describe "${MASTER_NAME}" --region "${REGION}" --project "${PROJECT}" &>/dev/null; then
|
if gcloud compute forwarding-rules describe "${MASTER_NAME}" --region "${REGION}" --project "${PROJECT}" &>/dev/null; then
|
||||||
detect-master
|
detect-master
|
||||||
local EXISTING_MASTER_ZONE=$(gcloud compute instances list "${MASTER_NAME}" \
|
local REMAINING_REPLICA_NAME="$(get-replica-name)"
|
||||||
|
local REMAINING_REPLICA_ZONE=$(gcloud compute instances list "${REMAINING_REPLICA_NAME}" \
|
||||||
--project "${PROJECT}" --format="value(zone)")
|
--project "${PROJECT}" --format="value(zone)")
|
||||||
gcloud compute forwarding-rules delete \
|
gcloud compute forwarding-rules delete \
|
||||||
--project "${PROJECT}" \
|
--project "${PROJECT}" \
|
||||||
--region "${REGION}" \
|
--region "${REGION}" \
|
||||||
--quiet \
|
--quiet \
|
||||||
"${MASTER_NAME}"
|
"${MASTER_NAME}"
|
||||||
attach-external-ip "${MASTER_NAME}" "${EXISTING_MASTER_ZONE}" "${KUBE_MASTER_IP}"
|
attach-external-ip "${REMAINING_REPLICA_NAME}" "${REMAINING_REPLICA_ZONE}" "${KUBE_MASTER_IP}"
|
||||||
gcloud compute target-pools delete \
|
gcloud compute target-pools delete \
|
||||||
--project "${PROJECT}" \
|
--project "${PROJECT}" \
|
||||||
--region "${REGION}" \
|
--region "${REGION}" \
|
||||||
|
@ -1326,6 +1331,8 @@ function kube-down() {
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# If there are no more remaining master replicas: delete routes, pd for influxdb and update kubeconfig
|
||||||
|
if [[ "${REMAINING_MASTER_COUNT}" == "0" ]]; then
|
||||||
# Delete routes.
|
# Delete routes.
|
||||||
local -a routes
|
local -a routes
|
||||||
# Clean up all routes w/ names like "<cluster-name>-<node-GUID>"
|
# Clean up all routes w/ names like "<cluster-name>-<node-GUID>"
|
||||||
|
@ -1366,7 +1373,6 @@ function kube-down() {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# If there are no more remaining master replicas, we should update kubeconfig.
|
# If there are no more remaining master replicas, we should update kubeconfig.
|
||||||
if [[ "${REMAINING_MASTER_COUNT}" == "0" ]]; then
|
|
||||||
export CONTEXT="${PROJECT}_${INSTANCE_PREFIX}"
|
export CONTEXT="${PROJECT}_${INSTANCE_PREFIX}"
|
||||||
clear-kubeconfig
|
clear-kubeconfig
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in New Issue