Skip to content

Commit 9578a41

Browse files
committed
kubeadm: add HTTPEndpoints field to ExternalEtcd that can be used to configure the HTTP endpoints for etcd communication.
1 parent 1b5fb46 commit 9578a41

File tree

12 files changed

+124
-28
lines changed

12 files changed

+124
-28
lines changed

cmd/kubeadm/app/apis/kubeadm/types.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,10 +316,24 @@ type LocalEtcd struct {
316316

317317
// ExternalEtcd describes an external etcd cluster
318318
type ExternalEtcd struct {
319-
320-
// Endpoints of etcd members. Useful for using external etcd.
319+
// Endpoints of etcd members. Required when using external etcd.
320+
// Specifies the client URLs (usually gRPC endpoints) for etcd communication.
321+
// By default, these endpoints handle both gRPC traffic (primary etcd protocol)
322+
// and HTTP traffic (metrics, health checks). However, if HTTPEndpoints is configured,
323+
// the gRPC and HTTP traffic can be separated for better security and performance.
324+
// Corresponds to etcd's --listen-client-urls configuration.
321325
// If not provided, kubeadm will run etcd in a static pod.
322326
Endpoints []string
327+
328+
// HTTPEndpoints are the dedicated HTTP endpoints for etcd communication.
329+
// When configured, HTTP traffic (such as /metrics and /health endpoints) is separated
330+
// from the gRPC traffic handled by Endpoints. This separation allows for better access
331+
// control, as HTTP endpoints can be exposed without exposing the primary gRPC interface.
332+
// Corresponds to etcd's --listen-client-http-urls configuration.
333+
// If not provided, Endpoints will be used for both gRPC and HTTP traffic.
334+
// +optional
335+
HTTPEndpoints []string
336+
323337
// CAFile is an SSL Certificate Authority file used to secure etcd communication.
324338
CAFile string
325339
// CertFile is an SSL certification file used to secure etcd communication.

cmd/kubeadm/app/apis/kubeadm/v1beta3/conversion.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package v1beta3
1818

1919
import (
2020
"sort"
21+
unsafe "unsafe"
2122

2223
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2324
"k8s.io/apimachinery/pkg/conversion"
@@ -161,3 +162,21 @@ func convertFromArgs(in []kubeadm.Arg) map[string]string {
161162
func Convert_v1beta3_APIServer_To_kubeadm_APIServer(in *APIServer, out *kubeadm.APIServer, s conversion.Scope) error {
162163
return autoConvert_v1beta3_APIServer_To_kubeadm_APIServer(in, out, s)
163164
}
165+
166+
// Convert_kubeadm_ExternalEtcd_To_v1beta3_ExternalEtcd converts a private ExternalEtcd to public ExternalEtcd.
167+
func Convert_kubeadm_ExternalEtcd_To_v1beta3_ExternalEtcd(in *kubeadm.ExternalEtcd, out *ExternalEtcd, s conversion.Scope) error {
168+
return autoConvert_kubeadm_ExternalEtcd_To_v1beta3_ExternalEtcd(in, out, s)
169+
}
170+
171+
// Convert_v1beta3_ExternalEtcd_To_kubeadm_ExternalEtcd converts a public ExternalEtcd to private ExternalEtcd.
172+
// It is required due to missing HTTPEndpoints in v1beta3.
173+
func Convert_v1beta3_ExternalEtcd_To_kubeadm_ExternalEtcd(in *ExternalEtcd, out *kubeadm.ExternalEtcd, s conversion.Scope) error {
174+
out.Endpoints = *(*[]string)(unsafe.Pointer(&in.Endpoints))
175+
// set the HTTPEndpoints to the same as the Endpoints
176+
// this is to maintain backwards compatibility with the v1beta3 API
177+
out.HTTPEndpoints = *(*[]string)(unsafe.Pointer(&in.Endpoints))
178+
out.CAFile = in.CAFile
179+
out.CertFile = in.CertFile
180+
out.KeyFile = in.KeyFile
181+
return nil
182+
}

cmd/kubeadm/app/apis/kubeadm/v1beta3/zz_generated.conversion.go

Lines changed: 29 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/kubeadm/app/apis/kubeadm/v1beta4/defaults.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,19 @@ func SetDefaults_Etcd(obj *ClusterConfiguration) {
130130
obj.Etcd.Local.DataDir = DefaultEtcdDataDir
131131
}
132132
}
133+
if obj.Etcd.External != nil {
134+
SetDefaults_ExternalEtcd(obj.Etcd.External)
135+
}
136+
}
137+
138+
// SetDefaults_ExternalEtcd assigns default values for the external etcd
139+
func SetDefaults_ExternalEtcd(obj *ExternalEtcd) {
140+
// If HTTPEndpoints is not set, default it to Endpoints
141+
// This allows HTTP traffic (metrics, health checks) to use the same endpoints as gRPC traffic
142+
if len(obj.HTTPEndpoints) == 0 && len(obj.Endpoints) > 0 {
143+
obj.HTTPEndpoints = make([]string, len(obj.Endpoints))
144+
copy(obj.HTTPEndpoints, obj.Endpoints)
145+
}
133146
}
134147

135148
// SetDefaults_JoinConfiguration assigns default values to a regular node

cmd/kubeadm/app/apis/kubeadm/v1beta4/doc.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ limitations under the License.
2323
// This version improves on the v1beta3 format by fixing some minor issues and adding a few new fields.
2424
//
2525
// A list of changes since v1beta3:
26+
// v1.35:
27+
// - Add `HTTPEndpoints` field to `ExternalEtcd` that can be used to configure the HTTP endpoints for etcd communication in v1beta4.
28+
// This field is used to separate the HTTP traffic (such as /metrics and /health endpoints) from the gRPC traffic handled by Endpoints.
29+
// This separation allows for better access control, as HTTP endpoints can be exposed without exposing the primary gRPC interface.
30+
// Corresponds to etcd's --listen-client-http-urls configuration.
31+
// If not provided, Endpoints will be used for both gRPC and HTTP traffic.
2632
//
2733
// v1.34:
2834
// - Add "ECDSA-P384" to the allowed encryption algorithm options for `ClusterConfiguration.EncryptionAlgorithm`.

cmd/kubeadm/app/apis/kubeadm/v1beta4/types.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,9 +343,24 @@ type LocalEtcd struct {
343343
// ExternalEtcd describes an external etcd cluster.
344344
// Kubeadm has no knowledge of where certificate files live and they must be supplied.
345345
type ExternalEtcd struct {
346-
// Endpoints of etcd members. Required for ExternalEtcd.
346+
// Endpoints of etcd members. Required when using external etcd.
347+
// Specifies the client URLs (usually gRPC endpoints) for etcd communication.
348+
// By default, these endpoints handle both gRPC traffic (primary etcd protocol)
349+
// and HTTP traffic (metrics, health checks). However, if HTTPEndpoints is configured,
350+
// the gRPC and HTTP traffic can be separated for better security and performance.
351+
// Corresponds to etcd's --listen-client-urls configuration.
352+
// If not provided, kubeadm will run etcd in a static pod.
347353
Endpoints []string `json:"endpoints"`
348354

355+
// HTTPEndpoints are the dedicated HTTP endpoints for etcd communication.
356+
// When configured, HTTP traffic (such as /metrics and /health endpoints) is separated
357+
// from the gRPC traffic handled by Endpoints. This separation allows for better access
358+
// control, as HTTP endpoints can be exposed without exposing the primary gRPC interface.
359+
// Corresponds to etcd's --listen-client-http-urls configuration.
360+
// If not provided, Endpoints will be used for both gRPC and HTTP traffic.
361+
// +optional
362+
HTTPEndpoints []string `json:"httpEndpoints,omitempty"`
363+
349364
// CAFile is an SSL Certificate Authority file used to secure etcd communication.
350365
// Required if using a TLS connection.
351366
CAFile string `json:"caFile"`

cmd/kubeadm/app/apis/kubeadm/v1beta4/zz_generated.conversion.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/kubeadm/app/apis/kubeadm/v1beta4/zz_generated.deepcopy.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/kubeadm/app/apis/kubeadm/v1beta4/zz_generated.defaults.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/kubeadm/app/apis/kubeadm/validation/validation.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,14 @@ func ValidateEtcd(e *kubeadm.Etcd, fldPath *field.Path) field.ErrorList {
329329
allErrs = append(allErrs, field.Invalid(externalPath, "", "setting .Etcd.External.CertFile and .Etcd.External.KeyFile requires .Etcd.External.CAFile"))
330330
}
331331

332-
allErrs = append(allErrs, ValidateURLs(e.External.Endpoints, requireHTTPS, externalPath.Child("endpoints"))...)
332+
if len(e.External.Endpoints) == 0 {
333+
allErrs = append(allErrs, field.Invalid(externalPath.Child("endpoints"), "", "at least one endpoint must be specified"))
334+
} else {
335+
allErrs = append(allErrs, ValidateURLs(e.External.Endpoints, requireHTTPS, externalPath.Child("endpoints"))...)
336+
}
337+
338+
allErrs = append(allErrs, ValidateURLs(e.External.HTTPEndpoints, false /* requireHTTPS */, externalPath.Child("httpEndpoints"))...)
339+
333340
if e.External.CAFile != "" {
334341
allErrs = append(allErrs, ValidateAbsolutePath(e.External.CAFile, externalPath.Child("caFile"))...)
335342
}

0 commit comments

Comments
 (0)