Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flag "--listen-address" for docker and podman driver #10653

Merged
merged 11 commits into from
Mar 5, 2021
12 changes: 12 additions & 0 deletions cmd/minikube/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,10 @@ func validateFlags(cmd *cobra.Command, drvName string) {
validateChangedMemoryFlags(drvName)
}

if cmd.Flags().Changed(listenAddress) {
validateListenAddress(viper.GetString(listenAddress))
}

if cmd.Flags().Changed(containerRuntime) {
runtime := strings.ToLower(viper.GetString(containerRuntime))

Expand Down Expand Up @@ -1199,6 +1203,14 @@ func validateRegistryMirror() {
}
}

// This function validates if the --listen-address
// match the format 0.0.0.0
func validateListenAddress(listenAddr string) {
if len(listenAddr) > 0 && net.ParseIP(listenAddr) == nil {
exit.Message(reason.Usage, "Sorry, the IP provided with the --listen-address flag is invalid: {{.listenAddr}}.", out.V{"listenAddr": listenAddr})
}
}

// This function validates that the --insecure-registry follows one of the following formats:
// "<ip>[:<port>]" "<hostname>[:<port>]" "<network>/<netmask>"
func validateInsecureRegistry() {
Expand Down
3 changes: 3 additions & 0 deletions cmd/minikube/cmd/start_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ const (
sshSSHPort = "ssh-port"
defaultSSHUser = "root"
defaultSSHPort = 22
listenAddress = "listen-address"
)

var (
Expand Down Expand Up @@ -215,6 +216,7 @@ func initDriverFlags() {
startCmd.Flags().String(hypervExternalAdapter, "", "External Adapter on which external switch will be created if no external switch is found. (hyperv driver only)")

// docker & podman
startCmd.Flags().String(listenAddress, "", "IP Address to use to expose ports (docker and podman driver only)")
startCmd.Flags().StringSlice(ports, []string{}, "List of ports that should be exposed (docker and podman driver only)")
}

Expand Down Expand Up @@ -322,6 +324,7 @@ func generateClusterConfig(cmd *cobra.Command, existing *config.ClusterConfig, k
CPUs: viper.GetInt(cpus),
DiskSize: diskSize,
Driver: drvName,
ListenAddress: viper.GetString(listenAddress),
HyperkitVpnKitSock: viper.GetString(vpnkitSock),
HyperkitVSockPorts: viper.GetStringSlice(vsockPorts),
NFSShare: viper.GetStringSlice(nfsShare),
Expand Down
9 changes: 8 additions & 1 deletion pkg/drivers/kic/kic.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (
"k8s.io/minikube/pkg/minikube/download"
"k8s.io/minikube/pkg/minikube/driver"
"k8s.io/minikube/pkg/minikube/out"
"k8s.io/minikube/pkg/minikube/style"
"k8s.io/minikube/pkg/minikube/sysinit"
"k8s.io/minikube/pkg/util/retry"
)
Expand Down Expand Up @@ -102,8 +103,14 @@ func (d *Driver) Create() error {
params.IP = ip.String()
}
drv := d.DriverName()

listAddr := oci.DefaultBindIPV4
if oci.IsExternalDaemonHost(drv) {
if d.NodeConfig.ListenAddress != "" && d.NodeConfig.ListenAddress != listAddr {
out.Step(style.Tip, "minikube is not meant for production use. You are opening non-local traffic")
out.WarningT("Listening to {{.listenAddr}}. This is not recommended and can cause a security vulnerability. Use at your own risk",
Loyen marked this conversation as resolved.
Show resolved Hide resolved
out.V{"listenAddr": d.NodeConfig.ListenAddress})
listAddr = d.NodeConfig.ListenAddress
} else if oci.IsExternalDaemonHost(drv) {
out.WarningT("Listening to 0.0.0.0 on external docker host {{.host}}. Please be advised",
out.V{"host": oci.DaemonHost(drv)})
listAddr = "0.0.0.0"
Expand Down
1 change: 1 addition & 0 deletions pkg/drivers/kic/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,5 @@ type Config struct {
ContainerRuntime string // container runtime kic is running
Network string // network to run with kic
ExtraArgs []string // a list of any extra option to pass to oci binary during creation time, for example --expose 8080...
ListenAddress string // IP Address to listen to
}
1 change: 1 addition & 0 deletions pkg/minikube/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ type ClusterConfig struct {
StartHostTimeout time.Duration
ScheduledStop *ScheduledStopConfig
ExposedPorts []string // Only used by the docker and podman driver
ListenAddress string // Only used by the docker and podman driver
Network string // only used by docker driver
MultiNodeRequested bool
}
Expand Down
1 change: 1 addition & 0 deletions pkg/minikube/registry/drvs/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ func configure(cc config.ClusterConfig, n config.Node) (interface{}, error) {
ContainerRuntime: cc.KubernetesConfig.ContainerRuntime,
ExtraArgs: extraArgs,
Network: cc.Network,
ListenAddress: cc.ListenAddress,
}), nil
}

Expand Down
1 change: 1 addition & 0 deletions pkg/minikube/registry/drvs/podman/podman.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ func configure(cc config.ClusterConfig, n config.Node) (interface{}, error) {
KubernetesVersion: cc.KubernetesConfig.KubernetesVersion,
ContainerRuntime: cc.KubernetesConfig.ContainerRuntime,
ExtraArgs: extraArgs,
ListenAddress: cc.ListenAddress,
}), nil
}

Expand Down
1 change: 1 addition & 0 deletions site/content/en/docs/commands/start.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ minikube start [flags]
--kvm-hidden Hide the hypervisor signature from the guest in minikube (kvm2 driver only)
--kvm-network string The KVM network name. (kvm2 driver only) (default "default")
--kvm-qemu-uri string The KVM QEMU connection URI. (kvm2 driver only) (default "qemu:///system")
--listen-address string IP Address to use to expose ports (docker and podman driver only)
--memory string Amount of RAM to allocate to Kubernetes (format: <number>[<unit>], where unit = b, k, m or g).
--mount This will start the mount daemon and automatically mount files into minikube.
--mount-string string The argument to pass the minikube mount command on start.
Expand Down