Skip to content

Commit

Permalink
Support custom dnsDomain for cluster
Browse files Browse the repository at this point in the history
Signed-off-by: pixiake <guofeng@yunify.com>
  • Loading branch information
pixiake committed Jan 14, 2022
1 parent ec38774 commit c1399e7
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 9 deletions.
4 changes: 2 additions & 2 deletions apis/kubekey/v1alpha2/cluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ type ExternalEtcd struct {

// GenerateCertSANs is used to generate cert sans for cluster.
func (cfg *ClusterSpec) GenerateCertSANs() []string {
clusterSvc := fmt.Sprintf("kubernetes.default.svc.%s", cfg.Kubernetes.ClusterName)
clusterSvc := fmt.Sprintf("kubernetes.default.svc.%s", cfg.Kubernetes.DNSDomain)
defaultCertSANs := []string{"kubernetes", "kubernetes.default", "kubernetes.default.svc", clusterSvc, "localhost", "127.0.0.1"}
extraCertSANs := make([]string, 0)

Expand All @@ -225,7 +225,7 @@ func (cfg *ClusterSpec) GenerateCertSANs() []string {

for _, host := range cfg.Hosts {
extraCertSANs = append(extraCertSANs, host.Name)
extraCertSANs = append(extraCertSANs, fmt.Sprintf("%s.%s", host.Name, cfg.Kubernetes.ClusterName))
extraCertSANs = append(extraCertSANs, fmt.Sprintf("%s.%s", host.Name, cfg.Kubernetes.DNSDomain))
if host.Address != cfg.ControlPlaneEndpoint.Address {
extraCertSANs = append(extraCertSANs, host.Address)
}
Expand Down
4 changes: 4 additions & 0 deletions apis/kubekey/v1alpha2/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const (
DefaultServiceCIDR = "10.233.0.0/18"
DefaultKubeImageNamespace = "kubesphere"
DefaultClusterName = "cluster.local"
DefaultDNSDomain = "cluster.local"
DefaultArch = "amd64"
DefaultEtcdVersion = "v3.4.13"
DefaultEtcdPort = "2379"
Expand Down Expand Up @@ -247,6 +248,9 @@ func SetDefaultClusterCfg(cfg *ClusterSpec) Kubernetes {
if cfg.Kubernetes.ClusterName == "" {
cfg.Kubernetes.ClusterName = DefaultClusterName
}
if cfg.Kubernetes.DNSDomain == "" {
cfg.Kubernetes.DNSDomain = DefaultDNSDomain
}
if cfg.Kubernetes.EtcdBackupDir == "" {
cfg.Kubernetes.EtcdBackupDir = DefaultEtcdBackupDir
}
Expand Down
1 change: 1 addition & 0 deletions apis/kubekey/v1alpha2/kubernetes_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type Kubernetes struct {
Type string `yaml:"type" json:"type,omitempty"`
Version string `yaml:"version" json:"version,omitempty"`
ClusterName string `yaml:"clusterName" json:"clusterName,omitempty"`
DNSDomain string `yaml:"dnsDomain" json:"dnsDomain,omitempty"`
MasqueradeAll bool `yaml:"masqueradeAll" json:"masqueradeAll,omitempty"`
MaxPods int `yaml:"maxPods" json:"maxPods,omitempty"`
NodeCidrMaskSize int `yaml:"nodeCidrMaskSize" json:"nodeCidrMaskSize,omitempty"`
Expand Down
4 changes: 3 additions & 1 deletion config/crd/bases/kubekey.kubesphere.io_clusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,8 @@ spec:
items:
type: string
type: array
dnsDomain:
type: string
etcdBackupDir:
type: string
etcdBackupPeriod:
Expand Down Expand Up @@ -637,7 +639,7 @@ spec:
system:
description: System defines the system config for each node in cluster.
properties:
ntpservers:
ntpServers:
items:
type: string
type: array
Expand Down
2 changes: 1 addition & 1 deletion pkg/common/kube_runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func generateHosts(hostGroups *kubekeyapiv1alpha2.HostGroups, cfg *kubekeyapiv1a

for _, host := range cfg.Hosts {
if host.Name != "" {
hostsList = append(hostsList, fmt.Sprintf("%s %s.%s %s", host.InternalAddress, host.Name, cfg.Kubernetes.ClusterName, host.Name))
hostsList = append(hostsList, fmt.Sprintf("%s %s.%s %s", host.InternalAddress, host.Name, cfg.Kubernetes.DNSDomain, host.Name))
}
}

Expand Down
1 change: 1 addition & 0 deletions pkg/kubernetes/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ func (g *GenerateKubeadmConfig) Execute(runtime connector.Runtime) error {
"CorednsTag": images.GetImage(runtime, g.KubeConf, "coredns").Tag,
"Version": g.KubeConf.Cluster.Kubernetes.Version,
"ClusterName": g.KubeConf.Cluster.Kubernetes.ClusterName,
"DNSDomain": g.KubeConf.Cluster.Kubernetes.DNSDomain,
"AdvertiseAddress": host.GetInternalAddress(),
"ControlPlanPort": g.KubeConf.Cluster.ControlPlaneEndpoint.Port,
"ControlPlaneEndpoint": fmt.Sprintf("%s:%d", g.KubeConf.Cluster.ControlPlaneEndpoint.Domain, g.KubeConf.Cluster.ControlPlaneEndpoint.Port),
Expand Down
6 changes: 3 additions & 3 deletions pkg/kubernetes/templates/v1beta2/kubeadm_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ certificatesDir: /etc/kubernetes/pki
clusterName: {{ .ClusterName }}
controlPlaneEndpoint: {{ .ControlPlaneEndpoint }}
networking:
dnsDomain: {{ .ClusterName }}
dnsDomain: {{ .DNSDomain }}
podSubnet: {{ .PodSubnet }}
serviceSubnet: {{ .ServiceSubnet }}
apiServer:
Expand Down Expand Up @@ -175,7 +175,7 @@ func UpdateFeatureGatesConfiguration(args map[string]string, kubeConf *common.Ku

func GetKubeletConfiguration(runtime connector.Runtime, kubeConf *common.KubeConf, criSock string) map[string]interface{} {
defaultKubeletConfiguration := map[string]interface{}{
"clusterDomain": kubeConf.Cluster.Kubernetes.ClusterName,
"clusterDomain": kubeConf.Cluster.Kubernetes.DNSDomain,
"clusterDNS": []string{kubeConf.Cluster.ClusterDNS()},
"maxPods": kubeConf.Cluster.Kubernetes.MaxPods,
"rotateCertificates": true,
Expand All @@ -190,7 +190,7 @@ func GetKubeletConfiguration(runtime connector.Runtime, kubeConf *common.KubeCon
"podPidsLimit": 1000,
"evictionHard": map[string]string{
"memory.available": "5%",
"pid.available": "10%",
"pid.available": "10%",
},
"evictionSoft": map[string]string{
"memory.available": "10%",
Expand Down
2 changes: 1 addition & 1 deletion pkg/plugins/dns/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (g *GenerateNodeLocalDNSConfigMap) Execute(runtime connector.Runtime) error
Dst: filepath.Join(common.KubeConfigDir, templates.NodeLocalDNSConfigMap.Name()),
Data: util.Data{
"ForwardTarget": clusterIP,
"DndDomain": g.KubeConf.Cluster.Kubernetes.ClusterName,
"DNSDomain": g.KubeConf.Cluster.Kubernetes.DNSDomain,
},
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/plugins/dns/templates/nodelocaldns_configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ metadata:
data:
Corefile: |
{{ .DndDomain }}:53 {
{{ .DNSDomain }}:53 {
errors
cache {
success 9984 30
Expand Down

0 comments on commit c1399e7

Please sign in to comment.