Skip to content

Commit 8b82ebb

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 4803425 commit 8b82ebb

File tree

8 files changed

+23
-4
lines changed

8 files changed

+23
-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
@@ -221,7 +221,7 @@ func initKubernetesFlags() {
221221
Valid components are: kubelet, kubeadm, apiserver, controller-manager, etcd, proxy, scheduler
222222
Valid kubeadm parameters: `+fmt.Sprintf("%s, %s", strings.Join(bsutil.KubeadmExtraArgsAllowed[bsutil.KubeadmCmdParam], ", "), strings.Join(bsutil.KubeadmExtraArgsAllowed[bsutil.KubeadmConfigParam], ",")))
223223
startCmd.Flags().String(featureGates, "", "A set of key=value pairs that describe feature gates for alpha/experimental features.")
224-
startCmd.Flags().String(dnsDomain, constants.ClusterDNSDomain, "The cluster dns domain name used in the Kubernetes cluster")
224+
startCmd.Flags().String(dnsDomain, constants.DefaultDNSDomain, "The cluster dns domain name used in the Kubernetes cluster")
225225
startCmd.Flags().Int(apiServerPort, constants.APIServerPort, "The apiserver listening port")
226226
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")
227227
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")
@@ -560,6 +560,9 @@ func generateNewConfigFromFlags(cmd *cobra.Command, k8sVersion string, rtime str
560560
out.WarningT("--network flag is only valid with the docker/podman, qemu, kvm, and vfkit drivers, it will be ignored")
561561
}
562562

563+
clusterDNSDomain := viper.GetString(config.DefaultDNSDomain)
564+
updateStringFromFlag(cmd, &clusterDNSDomain, dnsDomain)
565+
563566
validateHANodeCount(cmd)
564567

565568
checkNumaCount(k8sVersion)
@@ -636,7 +639,7 @@ func generateNewConfigFromFlags(cmd *cobra.Command, k8sVersion string, rtime str
636639
APIServerName: viper.GetString(apiServerName),
637640
APIServerNames: apiServerNames,
638641
APIServerIPs: apiServerIPs,
639-
DNSDomain: viper.GetString(dnsDomain),
642+
DNSDomain: clusterDNSDomain,
640643
FeatureGates: viper.GetString(featureGates),
641644
ContainerRuntime: rtime,
642645
CRISocket: viper.GetString(criSocket),

go.mod

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ require (
4646
github.com/moby/hyperkit v0.0.0-20210108224842-2f061e447e14
4747
github.com/moby/patternmatcher v0.6.0
4848
github.com/olekukonko/tablewriter v1.0.8
49+
github.com/onsi/ginkgo v1.14.0
50+
github.com/onsi/gomega v1.35.1
4951
github.com/opencontainers/cgroups v0.0.1
5052
github.com/opencontainers/go-digest v1.0.0
5153
github.com/otiai10/copy v1.14.1
@@ -59,6 +61,7 @@ require (
5961
github.com/spf13/cobra v1.9.1
6062
github.com/spf13/pflag v1.0.6
6163
github.com/spf13/viper v1.20.1
64+
github.com/xeipuuv/gojsonschema v1.2.0
6265
github.com/zchee/go-vmnet v0.0.0-20161021174912-97ebf9174097
6366
go.opentelemetry.io/otel v1.37.0
6467
go.opentelemetry.io/otel/sdk v1.37.0
@@ -181,6 +184,7 @@ require (
181184
github.com/muesli/reflow v0.3.0 // indirect
182185
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
183186
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
187+
github.com/nxadm/tail v1.4.4 // indirect
184188
github.com/olekukonko/errors v0.0.0-20250405072817-4e6d85265da6 // indirect
185189
github.com/olekukonko/ll v0.0.8 // indirect
186190
github.com/opencontainers/image-spec v1.1.0 // indirect
@@ -208,6 +212,8 @@ require (
208212
github.com/ulikunitz/xz v0.5.10 // indirect
209213
github.com/vbatts/tar-split v0.11.6 // indirect
210214
github.com/x448/float16 v0.8.4 // indirect
215+
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect
216+
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
211217
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
212218
github.com/yusufpapurcu/wmi v1.2.4 // indirect
213219
github.com/zeebo/errs v1.4.0 // indirect
@@ -229,6 +235,7 @@ require (
229235
google.golang.org/protobuf v1.36.6 // indirect
230236
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
231237
gopkg.in/inf.v0 v0.9.1 // indirect
238+
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
232239
gopkg.in/yaml.v3 v3.0.1 // indirect
233240
k8s.io/cli-runtime v0.33.1 // indirect
234241
k8s.io/kube-openapi v0.0.0-20250318190949-c8a335a9a2ff // indirect

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)