164164 systemctl restart containerd
165165}
166166
167- # this simply generates a self-signed certificate used for serving by the kubelet
168- configureKubeletServerCert () {
169- KUBELET_SERVER_PRIVATE_KEY_PATH=" /etc/kubernetes/certs/kubeletserver.key"
170- KUBELET_SERVER_CERT_PATH=" /etc/kubernetes/certs/kubeletserver.crt"
171-
172- openssl genrsa -out $KUBELET_SERVER_PRIVATE_KEY_PATH 2048
173- openssl req -new -x509 -days 7300 -key $KUBELET_SERVER_PRIVATE_KEY_PATH -out $KUBELET_SERVER_CERT_PATH -subj " /CN=${NODE_NAME} " -addext " subjectAltName=DNS:${NODE_NAME} "
174- }
175-
176167configureK8s () {
177168 mkdir -p " /etc/kubernetes/certs"
178169
249240 sed -i " /cloudProviderBackoffJitter/d" /etc/kubernetes/azure.json
250241 fi
251242
252- # generate a kubelet serving certificate if we aren't relying on TLS bootstrapping to generate one for us.
253- # NOTE: in the case where ENABLE_KUBELET_SERVING_CERTIFICATE_ROTATION is true but
254- # the customer has disabled serving certificate rotation via nodepool tags,
255- # the self-signed serving certificate will be bootstrapped by the kubelet instead of this function
256- # TODO(cameissner): remove configureKubeletServerCert altogether
257- if [ " ${ENABLE_KUBELET_SERVING_CERTIFICATE_ROTATION} " != " true" ]; then
258- configureKubeletServerCert
259- fi
260-
261243 if [ " ${IS_CUSTOM_CLOUD} " == " true" ]; then
262244 set +x
263245 AKS_CUSTOM_CLOUD_JSON_PATH=" /etc/kubernetes/${TARGET_ENVIRONMENT} .json"
@@ -423,12 +405,25 @@ getPrimaryNicIP() {
423405 echo " $ip "
424406}
425407
426- configureKubeletServingCertificateRotation () {
408+ generateSelfSignedKubeletServingCertificate () {
409+ KUBELET_SERVER_PRIVATE_KEY_PATH=" /etc/kubernetes/certs/kubeletserver.key"
410+ KUBELET_SERVER_CERT_PATH=" /etc/kubernetes/certs/kubeletserver.crt"
411+
412+ openssl genrsa -out $KUBELET_SERVER_PRIVATE_KEY_PATH 2048
413+ openssl req -new -x509 -days 7300 -key $KUBELET_SERVER_PRIVATE_KEY_PATH -out $KUBELET_SERVER_CERT_PATH -subj " /CN=${NODE_NAME} " -addext " subjectAltName=DNS:${NODE_NAME} "
414+ }
415+
416+ configureKubeletServing () {
427417 if [ " ${ENABLE_KUBELET_SERVING_CERTIFICATE_ROTATION} " != " true" ]; then
428- echo " kubelet serving certificate rotation is disabled, nothing to configure"
418+ echo " kubelet serving certificate rotation is disabled, generating self-signed serving certificate with openssl"
419+ generateSelfSignedKubeletServingCertificate
429420 return 0
430421 fi
431422
423+ KUBELET_SERVING_CERTIFICATE_ROTATION_LABEL=" kubernetes.azure.com/kubelet-serving-ca=cluster"
424+ KUBELET_SERVER_PRIVATE_KEY_PATH=" /etc/kubernetes/certs/kubeletserver.key"
425+ KUBELET_SERVER_CERT_PATH=" /etc/kubernetes/certs/kubeletserver.crt"
426+
432427 # check if kubelet serving certificate rotation is disabled by customer-specified nodepool tags
433428 export -f should_disable_kubelet_serving_certificate_rotation
434429 DISABLE_KUBELET_SERVING_CERTIFICATE_ROTATION=$( retrycmd_if_failure_no_stats 10 1 10 bash -cx should_disable_kubelet_serving_certificate_rotation)
@@ -437,27 +432,43 @@ configureKubeletServingCertificateRotation() {
437432 exit $ERR_LOOKUP_DISABLE_KUBELET_SERVING_CERTIFICATE_ROTATION_TAG
438433 fi
439434
440- KUBELET_SERVING_CERTIFICATE_ROTATION_LABEL=" kubernetes.azure.com/kubelet-serving-ca=cluster"
441-
442- if [ " ${DISABLE_KUBELET_SERVING_CERTIFICATE_ROTATION,,} " == " true" ]; then
443- echo " kubelet serving certificate rotation is disabled by nodepool tags, reconfiguring kubelet flags and node labels"
435+ if [ " ${DISABLE_KUBELET_SERVING_CERTIFICATE_ROTATION} " == " true" ]; then
436+ echo " kubelet serving certificate rotation is disabled by nodepool tags"
444437
445- # set the --rotate-server-certificates flag to false if needed
438+ # set --rotate-server-certificates flag and serverTLSBootstrap config file field to false
439+ echo " reconfiguring kubelet flags and config as needed"
446440 KUBELET_FLAGS=" ${KUBELET_FLAGS/ --rotate-server-certificates=true/ --rotate-server-certificates=false} "
447-
448- if [ " ${KUBELET_CONFIG_FILE_ENABLED,,} " == " true" ]; then
441+ if [ " ${KUBELET_CONFIG_FILE_ENABLED} " == " true" ]; then
449442 set +x
450- # set the serverTLSBootstrap property to false if needed
451443 KUBELET_CONFIG_FILE_CONTENT=$( echo " $KUBELET_CONFIG_FILE_CONTENT " | base64 -d | jq ' if .serverTLSBootstrap == true then .serverTLSBootstrap = false else . end' | base64)
452444 set -x
453445 fi
454446
447+ # manually generate kubelet's self-signed serving certificate
448+ echo " generating self-signed serving certificate with openssl"
449+ generateSelfSignedKubeletServingCertificate
450+
451+ # make sure to eliminate the kubelet serving node label
452+ echo " removing node label $KUBELET_SERVING_CERTIFICATE_ROTATION_LABEL "
455453 removeKubeletNodeLabel $KUBELET_SERVING_CERTIFICATE_ROTATION_LABEL
456- return 0
454+ else
455+ echo " kubelet serving certificate rotation is enabled"
456+
457+ # remove the --tls-cert-file and --tls-private-key-file flags, which are incompatible with serving certificate rotation
458+ # NOTE: this step will not be needed once these flags are no longer defaulted by the bootstrapper
459+ echo " removing --tls-cert-file and --tls-private-key-file from kubelet flags"
460+ removeKubeletFlag " --tls-cert-file=$KUBELET_SERVER_CERT_PATH "
461+ removeKubeletFlag " --tls-private-key-file=$KUBELET_SERVER_PRIVATE_KEY_PATH "
462+ if [ " ${KUBELET_CONFIG_FILE_ENABLED} " == " true" ]; then
463+ set +x
464+ KUBELET_CONFIG_FILE_CONTENT=$( echo " $KUBELET_CONFIG_FILE_CONTENT " | base64 -d | jq ' del(.tlsCertFile)' | jq ' del(.tlsPrivateKeyFile)' | base64)
465+ set -x
466+ fi
467+
468+ # make sure to add the kubelet serving node label
469+ echo " adding node label $KUBELET_SERVING_CERTIFICATE_ROTATION_LABEL if needed"
470+ addKubeletNodeLabel $KUBELET_SERVING_CERTIFICATE_ROTATION_LABEL
457471 fi
458-
459- echo " kubelet serving certificate rotation is enabled, will add node label if needed"
460- addKubeletNodeLabel $KUBELET_SERVING_CERTIFICATE_ROTATION_LABEL
461472}
462473
463474ensureKubelet () {
0 commit comments