Skip to content

Commit e077e4b

Browse files
committed
Add a default cluster DNS name config
It is very handy to be able to store the default cluster DNS name so that I can fire up and teardown clusters easily without losing that setting. You can think of this as a default value for the `start --dns-domain <val>` flag, but only when starting a new cluster. In my particular case, I would like to set my default cluster dna domain to a subdomain under a domain that I control. E.g. `cluster.wt.user.dev.example.com`. I want to do this to make it easier to manage TLS certs for my dev cluster. For context, the `start --dns-domain <val>` flag works like this: If you fire up a new cluster with that flag, you will get a new cluster with the domain name base. If you start an existing cluster, the config will be updated to the new domain name base and then started. This config will work a little differently. The change implements a config that will only affect newly started cluster. Here are some examples to show that difference: Newly started cluster example: ``` $ minikube config set default-dns-domain cluster2.local $ minikube start ... ``` Stop and starting the cluster with `--dns-domain` flag: ``` $ minikube stop ... $ minikub start --dns-domain cluster3.local ... ``` Stopping and starting a new cluster with a non-default domain name and without the `--dns-domain` flag: ``` $ minikube stop ... $ minikub start ... ``` The reason for this behavior is that I am not configuring the name of a cluster. That is a cluster configuration option. I am setting the default for that. If I manually overrode the name of a cluster when started previously, I don't want a default option to override my cluster configuration. Before: User cannot cannot change the default DNS domain name for a cluster to something other than cluster.local. On cluster creation/start: If a user runs `minikube start` without a `--dnsDomain` flag, the cluster will have the dns domain "cluster.local". A cluster setting is persisted. If a user runs 'minikube start --dnsDomain cluster.example.com`, the cluster will hae the dns domain "cluster.example.com". A cluster setting is persisted. On cluster restart: If a user run `minikube start`, the cluster's existing dns domain (pulled from the persisted cluster config) dns domain will be used. If a user runs `minikube start --dnsDomain cluster.example.com`, the cluster's persisted dns name will be updated to the new name and the cluster will be started with the new domain ("cluster.example.com"). Example command sequence: ``` $ minikube start --dnsDomain=cluster.example.com # cluster now has dns domain "cluster.example.com" $ minikube delete $ minikube start # cluster now has dns domain "cluster.local" ``` After: The behavior of the minikube start flag `--dns-domain` does not change at all. When the new configuration value is not set, all of the behaviors from the "Before" section above will not change. User can set the default cluster domain name to whatever they want via the config option `default-dns-domain`. E.g.: `minikube config set default-dns-domain cluster.wt.users.dev.example.com` Since the case with no configuration is the same as before, here is a description of what happens only with the new configuration set like above. On cluster creation/start: If a user runs `minikube start` without a `--dnsDomain` flag, the cluster will have the dns domain "cluster.wt.users.dev.example.com". A cluster setting is persisted. This is the only thing that changes with the configuration option set. If a user runs 'minikube start --dnsDomain cluster.example.com`, the cluster will hae the dns domain "cluster.example.com". A cluster setting is persisted. On cluster restart: If a user run `minikube start`, the cluster's existing dns domain (pulled from the persisted cluster config not from the new config) dns domain will be used. If a user runs `minikube start --dnsDomain cluster.example.com`, the cluster's persisted dns name will be updated to the new name and the cluster will be started with the new domain ("cluster.example.com"). Notice that the only case that changes with the new setting defined is the case of starting a new cluster. Setting the config will change the behavior of the "Before -> Example command sequence" section as described: Example command sequence: ``` $ minikube config set default-dns-domain cluster.wt.users.dev.example.com $ minikube start --dnsDomain=cluster.example.com # cluster now has dns domain "cluster.example.com" $ minikube delete $ minikube start # cluster now has dns domain "cluster.wt.users.dev.example.com" ``` The important piece here is that I can now change the default dnsDomain so that I don't have to specify it explicitly. This is useful when I am starting and deleting a single cluster where I want the top-level domain default to be a subdomain of a domain I control.
1 parent 358a142 commit e077e4b

File tree

7 files changed

+16
-4
lines changed

7 files changed

+16
-4
lines changed

cmd/minikube/cmd/config/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ var settings = []Setting{
172172
name: config.MaxAuditEntries,
173173
set: SetInt,
174174
},
175+
{
176+
name: config.DefaultDNSDomain,
177+
set: SetString,
178+
},
175179
}
176180

177181
// ConfigCmd represents the config command

cmd/minikube/cmd/root.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ func setupViper() {
331331
viper.SetDefault(config.WantVirtualBoxDriverWarning, true)
332332
viper.SetDefault(config.MaxAuditEntries, 1000)
333333
viper.SetDefault(config.SkipAuditFlag, false)
334+
viper.SetDefault(config.DefaultDNSDomain, constants.DefaultDNSDomain)
334335
}
335336

336337
func addToPath(dir string) {

cmd/minikube/cmd/start_flags.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ func initKubernetesFlags() {
223223
Valid components are: kubelet, kubeadm, apiserver, controller-manager, etcd, proxy, scheduler
224224
Valid kubeadm parameters: `+fmt.Sprintf("%s, %s", strings.Join(bsutil.KubeadmExtraArgsAllowed[bsutil.KubeadmCmdParam], ", "), strings.Join(bsutil.KubeadmExtraArgsAllowed[bsutil.KubeadmConfigParam], ",")))
225225
startCmd.Flags().String(featureGates, "", "A set of key=value pairs that describe feature gates for alpha/experimental features.")
226-
startCmd.Flags().String(dnsDomain, constants.ClusterDNSDomain, "The cluster dns domain name used in the Kubernetes cluster")
226+
startCmd.Flags().String(dnsDomain, constants.DefaultDNSDomain, "The cluster dns domain name used in the Kubernetes cluster")
227227
startCmd.Flags().Int(apiServerPort, constants.APIServerPort, "The apiserver listening port")
228228
startCmd.Flags().String(apiServerName, constants.APIServerName, "The authoritative apiserver hostname for apiserver certificates and connectivity. This can be used if you want to make the apiserver available from outside the machine")
229229
startCmd.Flags().StringSliceVar(&apiServerNames, "apiserver-names", nil, "A set of apiserver names which are used in the generated certificate for kubernetes. This can be used if you want to make the apiserver available from outside the machine")
@@ -562,6 +562,9 @@ func generateNewConfigFromFlags(cmd *cobra.Command, k8sVersion string, rtime str
562562
out.WarningT("--network flag is only valid with the docker/podman, qemu, kvm, and vfkit drivers, it will be ignored")
563563
}
564564

565+
clusterDNSDomain := viper.GetString(config.DefaultDNSDomain)
566+
updateStringFromFlag(cmd, &clusterDNSDomain, dnsDomain)
567+
565568
validateHANodeCount(cmd)
566569

567570
checkNumaCount(k8sVersion)
@@ -638,7 +641,7 @@ func generateNewConfigFromFlags(cmd *cobra.Command, k8sVersion string, rtime str
638641
APIServerName: viper.GetString(apiServerName),
639642
APIServerNames: apiServerNames,
640643
APIServerIPs: apiServerIPs,
641-
DNSDomain: viper.GetString(dnsDomain),
644+
DNSDomain: clusterDNSDomain,
642645
FeatureGates: viper.GetString(featureGates),
643646
ContainerRuntime: rtime,
644647
CRISocket: viper.GetString(criSocket),

pkg/minikube/bootstrapper/certs_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func TestSetupCerts(t *testing.T) {
3636
CertExpiration: constants.DefaultCertExpiration,
3737
KubernetesConfig: config.KubernetesConfig{
3838
APIServerName: constants.APIServerName,
39-
DNSDomain: constants.ClusterDNSDomain,
39+
DNSDomain: constants.DefaultDNSDomain,
4040
ServiceCIDR: constants.DefaultServiceCIDR,
4141
},
4242
}

pkg/minikube/config/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ const (
5858
EmbedCerts = "EmbedCerts"
5959
// MaxAuditEntries is the maximum number of audit entries to retain
6060
MaxAuditEntries = "MaxAuditEntries"
61+
// DefaultDnsDomain is the key for the default dns domain name when creating
62+
// a cluster
63+
DefaultDNSDomain = "default-dns-domain"
6164
)
6265

6366
var (

pkg/minikube/constants/constants.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ const (
7575
// APIServerName is the default API server name
7676
APIServerName = "minikubeCA"
7777
// ClusterDNSDomain is the default DNS domain
78-
ClusterDNSDomain = "cluster.local"
78+
DefaultDNSDomain = "cluster.local"
7979
// DefaultServiceCIDR is The CIDR to be used for service cluster IPs
8080
DefaultServiceCIDR = "10.96.0.0/12"
8181
// HostAlias is a DNS alias to the container/VM host IP

site/content/en/docs/commands/config.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Configurable fields:
4141
* native-ssh
4242
* rootless
4343
* MaxAuditEntries
44+
* default-dns-domain
4445

4546
```shell
4647
minikube config SUBCOMMAND [flags]

0 commit comments

Comments
 (0)