diff --git a/pkg/minikube/bootstrapper/kubeadm/kubeadm.go b/pkg/minikube/bootstrapper/kubeadm/kubeadm.go index 9bdadab1b45b..ebc0ec8f963c 100644 --- a/pkg/minikube/bootstrapper/kubeadm/kubeadm.go +++ b/pkg/minikube/bootstrapper/kubeadm/kubeadm.go @@ -698,6 +698,7 @@ func generateConfig(k8s config.KubernetesConfig, r cruntime.Manager) ([]byte, er KubernetesVersion string EtcdDataDir string NodeName string + DNSDomain string CRISocket string ImageRepository string ExtraArgs []ComponentExtraArgs @@ -717,6 +718,7 @@ func generateConfig(k8s config.KubernetesConfig, r cruntime.Manager) ([]byte, er ExtraArgs: extraComponentConfig, FeatureArgs: kubeadmFeatureArgs, NoTaintMaster: false, // That does not work with k8s 1.12+ + DNSDomain: k8s.DNSDomain, } if k8s.ServiceCIDR != "" { diff --git a/pkg/minikube/bootstrapper/kubeadm/kubeadm_test.go b/pkg/minikube/bootstrapper/kubeadm/kubeadm_test.go index 56273da233f8..8a880dc49afc 100644 --- a/pkg/minikube/bootstrapper/kubeadm/kubeadm_test.go +++ b/pkg/minikube/bootstrapper/kubeadm/kubeadm_test.go @@ -235,6 +235,67 @@ func recentReleases() ([]string, error) { return versions, nil } +/** +Need a separate test function to test the DNS server IP +as v1.11 yaml file is very different compared to v1.12+. +This test case has only 1 thing to test and that is the +nnetworking/dnsDomain value +*/ +func TestGenerateConfigDNS(t *testing.T) { + versions := []string{"v1.16", "v1.15", "v1.14", "v1.13", "v1.12"} + tests := []struct { + name string + runtime string + shouldErr bool + cfg config.KubernetesConfig + }{ + {"dns", "docker", false, config.KubernetesConfig{DNSDomain: "1.1.1.1"}}, + } + for _, version := range versions { + for _, tc := range tests { + runtime, err := cruntime.New(cruntime.Config{Type: tc.runtime}) + if err != nil { + t.Fatalf("runtime: %v", err) + } + tname := tc.name + "_" + version + t.Run(tname, func(t *testing.T) { + cfg := tc.cfg + cfg.NodeIP = "1.1.1.1" + cfg.NodeName = "mk" + cfg.KubernetesVersion = version + ".0" + + got, err := generateConfig(cfg, runtime) + if err != nil && !tc.shouldErr { + t.Fatalf("got unexpected error generating config: %v", err) + } + if err == nil && tc.shouldErr { + t.Fatalf("expected error but got none, config: %s", got) + } + if tc.shouldErr { + return + } + expected, err := ioutil.ReadFile(fmt.Sprintf("testdata/%s/%s.yaml", version, tc.name)) + if err != nil { + t.Fatalf("unable to read testdata: %v", err) + } + diff, err := difflib.GetUnifiedDiffString(difflib.UnifiedDiff{ + A: difflib.SplitLines(string(expected)), + B: difflib.SplitLines(string(got)), + FromFile: "Expected", + ToFile: "Got", + Context: 1, + }) + if err != nil { + t.Fatalf("diff error: %v", err) + } + if diff != "" { + t.Errorf("unexpected diff:\n%s\n===== [RAW OUTPUT] =====\n%s", diff, got) + } + }) + } + } +} + func TestGenerateConfig(t *testing.T) { extraOpts := getExtraOpts() extraOptsPodCidr := getExtraOptsPodCidr() diff --git a/pkg/minikube/bootstrapper/kubeadm/templates.go b/pkg/minikube/bootstrapper/kubeadm/templates.go index 9c3887f0dd78..5f5325c15295 100644 --- a/pkg/minikube/bootstrapper/kubeadm/templates.go +++ b/pkg/minikube/bootstrapper/kubeadm/templates.go @@ -84,7 +84,7 @@ etcd: dataDir: {{.EtcdDataDir}} kubernetesVersion: {{.KubernetesVersion}} networking: - dnsDomain: cluster.local + dnsDomain: {{if .DNSDomain}}{{.DNSDomain}}{{else}}cluster.local{{end}} podSubnet: {{if .PodSubnet}}{{.PodSubnet}}{{else}}""{{end}} serviceSubnet: {{.ServiceCIDR}} --- @@ -138,7 +138,7 @@ etcd: dataDir: {{.EtcdDataDir}} kubernetesVersion: {{.KubernetesVersion}} networking: - dnsDomain: cluster.local + dnsDomain: {{if .DNSDomain}}{{.DNSDomain}}{{else}}cluster.local{{end}} podSubnet: "" serviceSubnet: {{.ServiceCIDR}} --- diff --git a/pkg/minikube/bootstrapper/kubeadm/testdata/v1.12/dns.yaml b/pkg/minikube/bootstrapper/kubeadm/testdata/v1.12/dns.yaml new file mode 100644 index 000000000000..a4a813404c50 --- /dev/null +++ b/pkg/minikube/bootstrapper/kubeadm/testdata/v1.12/dns.yaml @@ -0,0 +1,39 @@ +apiVersion: kubeadm.k8s.io/v1alpha3 +kind: InitConfiguration +apiEndpoint: + advertiseAddress: 1.1.1.1 + bindPort: 8443 +bootstrapTokens: + - groups: + - system:bootstrappers:kubeadm:default-node-token + ttl: 24h0m0s + usages: + - signing + - authentication +nodeRegistration: + criSocket: /var/run/dockershim.sock + name: mk + taints: [] +--- +apiVersion: kubeadm.k8s.io/v1alpha3 +kind: ClusterConfiguration +apiServerExtraArgs: + enable-admission-plugins: "Initializers,NamespaceLifecycle,LimitRanger,ServiceAccount,DefaultStorageClass,DefaultTolerationSeconds,NodeRestriction,MutatingAdmissionWebhook,ValidatingAdmissionWebhook,ResourceQuota" +certificatesDir: /var/lib/minikube/certs +clusterName: kubernetes +controlPlaneEndpoint: localhost:8443 +etcd: + local: + dataDir: /var/lib/minikube/etcd +kubernetesVersion: v1.12.0 +networking: + dnsDomain: 1.1.1.1 + podSubnet: "" + serviceSubnet: 10.96.0.0/12 +--- +apiVersion: kubelet.config.k8s.io/v1beta1 +kind: KubeletConfiguration +evictionHard: + nodefs.available: "0%" + nodefs.inodesFree: "0%" + imagefs.available: "0%" diff --git a/pkg/minikube/bootstrapper/kubeadm/testdata/v1.13/dns.yaml b/pkg/minikube/bootstrapper/kubeadm/testdata/v1.13/dns.yaml new file mode 100644 index 000000000000..cdf2a0405fe0 --- /dev/null +++ b/pkg/minikube/bootstrapper/kubeadm/testdata/v1.13/dns.yaml @@ -0,0 +1,39 @@ +apiVersion: kubeadm.k8s.io/v1alpha3 +kind: InitConfiguration +apiEndpoint: + advertiseAddress: 1.1.1.1 + bindPort: 8443 +bootstrapTokens: + - groups: + - system:bootstrappers:kubeadm:default-node-token + ttl: 24h0m0s + usages: + - signing + - authentication +nodeRegistration: + criSocket: /var/run/dockershim.sock + name: mk + taints: [] +--- +apiVersion: kubeadm.k8s.io/v1alpha3 +kind: ClusterConfiguration +apiServerExtraArgs: + enable-admission-plugins: "Initializers,NamespaceLifecycle,LimitRanger,ServiceAccount,DefaultStorageClass,DefaultTolerationSeconds,NodeRestriction,MutatingAdmissionWebhook,ValidatingAdmissionWebhook,ResourceQuota" +certificatesDir: /var/lib/minikube/certs +clusterName: kubernetes +controlPlaneEndpoint: localhost:8443 +etcd: + local: + dataDir: /var/lib/minikube/etcd +kubernetesVersion: v1.13.0 +networking: + dnsDomain: 1.1.1.1 + podSubnet: "" + serviceSubnet: 10.96.0.0/12 +--- +apiVersion: kubelet.config.k8s.io/v1beta1 +kind: KubeletConfiguration +evictionHard: + nodefs.available: "0%" + nodefs.inodesFree: "0%" + imagefs.available: "0%" diff --git a/pkg/minikube/bootstrapper/kubeadm/testdata/v1.14/dns.yaml b/pkg/minikube/bootstrapper/kubeadm/testdata/v1.14/dns.yaml new file mode 100644 index 000000000000..93ce010c2ac4 --- /dev/null +++ b/pkg/minikube/bootstrapper/kubeadm/testdata/v1.14/dns.yaml @@ -0,0 +1,43 @@ +apiVersion: kubeadm.k8s.io/v1beta1 +kind: InitConfiguration +localAPIEndpoint: + advertiseAddress: 1.1.1.1 + bindPort: 8443 +bootstrapTokens: + - groups: + - system:bootstrappers:kubeadm:default-node-token + ttl: 24h0m0s + usages: + - signing + - authentication +nodeRegistration: + criSocket: /var/run/dockershim.sock + name: mk + taints: [] +--- +apiVersion: kubeadm.k8s.io/v1beta1 +kind: ClusterConfiguration +apiServer: + extraArgs: + enable-admission-plugins: "NamespaceLifecycle,LimitRanger,ServiceAccount,DefaultStorageClass,DefaultTolerationSeconds,NodeRestriction,MutatingAdmissionWebhook,ValidatingAdmissionWebhook,ResourceQuota" +certificatesDir: /var/lib/minikube/certs +clusterName: kubernetes +controlPlaneEndpoint: localhost:8443 +dns: + type: CoreDNS +etcd: + local: + dataDir: /var/lib/minikube/etcd +kubernetesVersion: v1.14.0 +networking: + dnsDomain: 1.1.1.1 + podSubnet: "" + serviceSubnet: 10.96.0.0/12 +--- +apiVersion: kubelet.config.k8s.io/v1beta1 +kind: KubeletConfiguration +imageGCHighThresholdPercent: 100 +evictionHard: + nodefs.available: "0%" + nodefs.inodesFree: "0%" + imagefs.available: "0%" diff --git a/pkg/minikube/bootstrapper/kubeadm/testdata/v1.15/dns.yaml b/pkg/minikube/bootstrapper/kubeadm/testdata/v1.15/dns.yaml new file mode 100644 index 000000000000..d6474d3bee3f --- /dev/null +++ b/pkg/minikube/bootstrapper/kubeadm/testdata/v1.15/dns.yaml @@ -0,0 +1,43 @@ +apiVersion: kubeadm.k8s.io/v1beta1 +kind: InitConfiguration +localAPIEndpoint: + advertiseAddress: 1.1.1.1 + bindPort: 8443 +bootstrapTokens: + - groups: + - system:bootstrappers:kubeadm:default-node-token + ttl: 24h0m0s + usages: + - signing + - authentication +nodeRegistration: + criSocket: /var/run/dockershim.sock + name: mk + taints: [] +--- +apiVersion: kubeadm.k8s.io/v1beta1 +kind: ClusterConfiguration +apiServer: + extraArgs: + enable-admission-plugins: "NamespaceLifecycle,LimitRanger,ServiceAccount,DefaultStorageClass,DefaultTolerationSeconds,NodeRestriction,MutatingAdmissionWebhook,ValidatingAdmissionWebhook,ResourceQuota" +certificatesDir: /var/lib/minikube/certs +clusterName: kubernetes +controlPlaneEndpoint: localhost:8443 +dns: + type: CoreDNS +etcd: + local: + dataDir: /var/lib/minikube/etcd +kubernetesVersion: v1.15.0 +networking: + dnsDomain: 1.1.1.1 + podSubnet: "" + serviceSubnet: 10.96.0.0/12 +--- +apiVersion: kubelet.config.k8s.io/v1beta1 +kind: KubeletConfiguration +imageGCHighThresholdPercent: 100 +evictionHard: + nodefs.available: "0%" + nodefs.inodesFree: "0%" + imagefs.available: "0%" diff --git a/pkg/minikube/bootstrapper/kubeadm/testdata/v1.16/dns.yaml b/pkg/minikube/bootstrapper/kubeadm/testdata/v1.16/dns.yaml new file mode 100644 index 000000000000..1fd0562a5590 --- /dev/null +++ b/pkg/minikube/bootstrapper/kubeadm/testdata/v1.16/dns.yaml @@ -0,0 +1,43 @@ +apiVersion: kubeadm.k8s.io/v1beta1 +kind: InitConfiguration +localAPIEndpoint: + advertiseAddress: 1.1.1.1 + bindPort: 8443 +bootstrapTokens: + - groups: + - system:bootstrappers:kubeadm:default-node-token + ttl: 24h0m0s + usages: + - signing + - authentication +nodeRegistration: + criSocket: /var/run/dockershim.sock + name: mk + taints: [] +--- +apiVersion: kubeadm.k8s.io/v1beta1 +kind: ClusterConfiguration +apiServer: + extraArgs: + enable-admission-plugins: "NamespaceLifecycle,LimitRanger,ServiceAccount,DefaultStorageClass,DefaultTolerationSeconds,NodeRestriction,MutatingAdmissionWebhook,ValidatingAdmissionWebhook,ResourceQuota" +certificatesDir: /var/lib/minikube/certs +clusterName: kubernetes +controlPlaneEndpoint: localhost:8443 +dns: + type: CoreDNS +etcd: + local: + dataDir: /var/lib/minikube/etcd +kubernetesVersion: v1.16.0 +networking: + dnsDomain: 1.1.1.1 + podSubnet: "" + serviceSubnet: 10.96.0.0/12 +--- +apiVersion: kubelet.config.k8s.io/v1beta1 +kind: KubeletConfiguration +imageGCHighThresholdPercent: 100 +evictionHard: + nodefs.available: "0%" + nodefs.inodesFree: "0%" + imagefs.available: "0%" diff --git a/site/content/en/docs/Reference/Networking/dns.md b/site/content/en/docs/Reference/Networking/dns.md new file mode 100644 index 000000000000..6c44114b7b01 --- /dev/null +++ b/site/content/en/docs/Reference/Networking/dns.md @@ -0,0 +1,58 @@ +--- +title: "DNS Domain" +linkTitle: "DNS Domain" +weight: 6 +date: 2019-10-09 +description: > + Use configured DNS domain in bootstrapper kubeadm +--- + +minikube by default uses **cluster.local** if none is specified via the start flag --dns-domain. The configuration file used by kubeadm are found inside **/var/tmp/minikube/kubeadm.yaml** directory inside minikube. + +Default DNS configuration will look like below + +``` +apiVersion: kubeadm.k8s.io/v1beta1 +kind: InitConfiguration +localAPIEndpoint: +...... +...... +--- +apiVersion: kubeadm.k8s.io/v1beta1 +kind: ClusterConfiguration +..... +..... +kubernetesVersion: v1.16.0 +networking: + dnsDomain: cluster.local + podSubnet: "" + serviceSubnet: 10.96.0.0/12 +--- +``` + +To change the dns pass the value when starting minikube + +``` +minikube start --dns-domain bla.blah.blah +``` + +the dns now changed to bla.blah.blah + +``` +apiVersion: kubeadm.k8s.io/v1beta1 +kind: InitConfiguration +localAPIEndpoint: +...... +...... +--- +apiVersion: kubeadm.k8s.io/v1beta1 +kind: ClusterConfiguration +..... +..... +kubernetesVersion: v1.16.0 +networking: + dnsDomain: bla.blah.blah + podSubnet: "" + serviceSubnet: 10.96.0.0/12 +--- +``` \ No newline at end of file