diff --git a/cmd/kk/apis/kubekey/v1alpha2/cluster_types.go b/cmd/kk/apis/kubekey/v1alpha2/cluster_types.go index b86065480..4dc1cf376 100644 --- a/cmd/kk/apis/kubekey/v1alpha2/cluster_types.go +++ b/cmd/kk/apis/kubekey/v1alpha2/cluster_types.go @@ -74,6 +74,7 @@ type HostCfg struct { type ControlPlaneEndpoint struct { InternalLoadbalancer string `yaml:"internalLoadbalancer" json:"internalLoadbalancer,omitempty"` Domain string `yaml:"domain" json:"domain,omitempty"` + ExternalDNS *bool `yaml:"externalDNS" json:"externalDNS"` Address string `yaml:"address" json:"address,omitempty"` Port int `yaml:"port" json:"port,omitempty"` KubeVip KubeVip `yaml:"kubevip" json:"kubevip,omitempty"` @@ -296,3 +297,11 @@ func (c ControlPlaneEndpoint) IsInternalLBEnabled() bool { func (c ControlPlaneEndpoint) IsInternalLBEnabledVip() bool { return c.InternalLoadbalancer == Kubevip } + +// EnableExternalDNS is used to determine whether to use external dns to resolve kube-apiserver domain. +func (c *ControlPlaneEndpoint) EnableExternalDNS() bool { + if c.ExternalDNS == nil { + return false + } + return *c.ExternalDNS +} diff --git a/cmd/kk/apis/kubekey/v1alpha2/default.go b/cmd/kk/apis/kubekey/v1alpha2/default.go index e3d947826..986410db5 100644 --- a/cmd/kk/apis/kubekey/v1alpha2/default.go +++ b/cmd/kk/apis/kubekey/v1alpha2/default.go @@ -185,9 +185,9 @@ func SetDefaultHostsCfg(cfg *ClusterSpec) []HostCfg { func SetDefaultLBCfg(cfg *ClusterSpec, masterGroup []*KubeHost) ControlPlaneEndpoint { //Check whether LB should be configured - if len(masterGroup) >= 2 && !cfg.ControlPlaneEndpoint.IsInternalLBEnabled() && cfg.ControlPlaneEndpoint.Address == "" { + if len(masterGroup) >= 2 && !cfg.ControlPlaneEndpoint.IsInternalLBEnabled() && cfg.ControlPlaneEndpoint.Address == "" && !cfg.ControlPlaneEndpoint.EnableExternalDNS() { fmt.Println() - fmt.Println("Warning: When there are at least two nodes in the control-plane, you should set the value of the LB address or enable the internal loadbalancer, if the 'ControlPlaneEndpoint.Domain' cannot be resolved in your dns server.") + fmt.Println("Warning: When there are at least two nodes in the control-plane, you should set the value of the LB address or enable the internal loadbalancer, or set 'controlPlaneEndpoint.externalDNS' to 'true' if the 'controlPlaneEndpoint.domain' can be resolved in your dns server.") fmt.Println() } @@ -197,7 +197,7 @@ func SetDefaultLBCfg(cfg *ClusterSpec, masterGroup []*KubeHost) ControlPlaneEndp os.Exit(0) } - if cfg.ControlPlaneEndpoint.Address == "127.0.0.1" { + if (cfg.ControlPlaneEndpoint.Address == "" && !cfg.ControlPlaneEndpoint.EnableExternalDNS()) || cfg.ControlPlaneEndpoint.Address == "127.0.0.1" { cfg.ControlPlaneEndpoint.Address = masterGroup[0].InternalAddress } if cfg.ControlPlaneEndpoint.Domain == "" { diff --git a/docs/config-example.md b/docs/config-example.md index fc3a57843..e6895f793 100644 --- a/docs/config-example.md +++ b/docs/config-example.md @@ -23,8 +23,11 @@ spec: - node1 - node[10:100] # All the nodes in your cluster that serve as the worker nodes. controlPlaneEndpoint: - #Internal loadbalancer for apiservers. Support: haproxy, kube-vip [Default: ""] - internalLoadbalancer: haproxy + # Internal loadbalancer for apiservers. Support: haproxy, kube-vip [Default: ""] + internalLoadbalancer: haproxy + # Determines whether to use external dns to resolve the control-plane domain. + # If 'externalDNS' is set to 'true', the 'address' needs to be set to "". + externalDNS: false domain: lb.kubesphere.local # The IP address of your load balancer. If you use internalLoadblancer in "kube-vip" mode, a VIP is required here. address: ""