Skip to content

Commit 33a81a7

Browse files
committed
Move kubelet cert generation when starting kubelet
Running local-up-cluster with START_MODE='kubeletonly' requires cert and kubeconfig. Currently, all the certs and the kubeconfig are created in the start_apiserver so it won't be created when only kubelet is started. This change moves the creation of the kubelet cert and kubeconfig to start_kubelet. This is helpful if you want to run kubelet with local-up-cluster and to connect to an existing master node. Change-Id: Iaba0bf975297346fbede44342f163024caa256cf Signed-off-by: Moshe Levi <[email protected]>
1 parent ee50d47 commit 33a81a7

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

hack/local-up-cluster.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,6 @@ function generate_certs {
477477
kube::util::create_serving_certkey "${CONTROLPLANE_SUDO}" "${CERT_DIR}" "server-ca" kube-apiserver kubernetes.default kubernetes.default.svc "localhost" ${API_HOST_IP} ${API_HOST} ${FIRST_SERVICE_CLUSTER_IP}
478478

479479
# Create client certs signed with client-ca, given id, given CN and a number of groups
480-
kube::util::create_client_certkey "${CONTROLPLANE_SUDO}" "${CERT_DIR}" 'client-ca' kubelet system:node:${HOSTNAME_OVERRIDE} system:nodes
481480
kube::util::create_client_certkey "${CONTROLPLANE_SUDO}" "${CERT_DIR}" 'client-ca' kube-proxy system:kube-proxy system:nodes
482481
kube::util::create_client_certkey "${CONTROLPLANE_SUDO}" "${CERT_DIR}" 'client-ca' controller system:kube-controller-manager
483482
kube::util::create_client_certkey "${CONTROLPLANE_SUDO}" "${CERT_DIR}" 'client-ca' scheduler system:kube-scheduler
@@ -492,6 +491,11 @@ function generate_certs {
492491
kube::util::write_client_kubeconfig "${CONTROLPLANE_SUDO}" "${CERT_DIR}" "${ROOT_CA_FILE}" "${API_HOST}" "${API_SECURE_PORT}" kube-aggregator
493492
}
494493

494+
function generate_kubelet_certs {
495+
kube::util::create_client_certkey "${CONTROLPLANE_SUDO}" "${CERT_DIR}" 'client-ca' kubelet system:node:${HOSTNAME_OVERRIDE} system:nodes
496+
kube::util::write_client_kubeconfig "${CONTROLPLANE_SUDO}" "${CERT_DIR}" "${ROOT_CA_FILE}" "${API_HOST}" "${API_SECURE_PORT}" kubelet
497+
}
498+
495499
function start_apiserver {
496500
security_admission=""
497501
if [[ -n "${DENY_SECURITY_CONTEXT_ADMISSION}" ]]; then
@@ -598,7 +602,6 @@ function start_apiserver {
598602
# Create kubeconfigs for all components, using client certs
599603
kube::util::write_client_kubeconfig "${CONTROLPLANE_SUDO}" "${CERT_DIR}" "${ROOT_CA_FILE}" "${API_HOST}" "${API_SECURE_PORT}" admin
600604
${CONTROLPLANE_SUDO} chown "${USER}" "${CERT_DIR}/client-admin.key" # make readable for kubectl
601-
kube::util::write_client_kubeconfig "${CONTROLPLANE_SUDO}" "${CERT_DIR}" "${ROOT_CA_FILE}" "${API_HOST}" "${API_SECURE_PORT}" kubelet
602605
kube::util::write_client_kubeconfig "${CONTROLPLANE_SUDO}" "${CERT_DIR}" "${ROOT_CA_FILE}" "${API_HOST}" "${API_SECURE_PORT}" kube-proxy
603606
kube::util::write_client_kubeconfig "${CONTROLPLANE_SUDO}" "${CERT_DIR}" "${ROOT_CA_FILE}" "${API_HOST}" "${API_SECURE_PORT}" controller
604607
kube::util::write_client_kubeconfig "${CONTROLPLANE_SUDO}" "${CERT_DIR}" "${ROOT_CA_FILE}" "${API_HOST}" "${API_SECURE_PORT}" scheduler
@@ -781,6 +784,10 @@ function start_kubelet {
781784
${KUBELET_FLAGS}
782785
)
783786

787+
if [[ "${REUSE_CERTS}" != true ]]; then
788+
generate_kubelet_certs
789+
fi
790+
784791
if [[ -z "${DOCKERIZE_KUBELET}" ]]; then
785792
sudo -E "${GO_OUT}/hyperkube" kubelet "${all_kubelet_flags[@]}" >"${KUBELET_LOG}" 2>&1 &
786793
KUBELET_PID=$!

0 commit comments

Comments
 (0)