diff --git a/cmd/minikube/cmd/start_flags.go b/cmd/minikube/cmd/start_flags.go index 4323b69d141f..b9aa10e17284 100644 --- a/cmd/minikube/cmd/start_flags.go +++ b/cmd/minikube/cmd/start_flags.go @@ -107,6 +107,7 @@ const ( forceSystemd = "force-systemd" kicBaseImage = "base-image" startOutput = "output" + ports = "ports" ) // initMinikubeFlags includes commandline flags for minikube. @@ -197,6 +198,9 @@ func initDriverFlags() { startCmd.Flags().String(hypervVirtualSwitch, "", "The hyperv virtual switch name. Defaults to first found. (hyperv driver only)") startCmd.Flags().Bool(hypervUseExternalSwitch, false, "Whether to use external switch over Default Switch if virtual switch not explicitly specified. (hyperv driver only)") 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().StringSlice(ports, []string{}, "List of ports that should be exposed (docker and podman driver only)") } // initNetworkingFlags inits the commandline flags for connectivity related flags for start @@ -311,6 +315,7 @@ func generateClusterConfig(cmd *cobra.Command, existing *config.ClusterConfig, k HostOnlyNicType: viper.GetString(hostOnlyNicType), NatNicType: viper.GetString(natNicType), StartHostTimeout: viper.GetDuration(waitTimeout), + ExposedPorts: viper.GetStringSlice(ports), KubernetesConfig: config.KubernetesConfig{ KubernetesVersion: k8sVersion, ClusterName: ClusterFlagValue(), @@ -547,6 +552,10 @@ func updateExistingConfigFromFlags(cmd *cobra.Command, existing *config.ClusterC cc.KubernetesConfig.NodePort = viper.GetInt(apiServerPort) } + if cmd.Flags().Changed(vsockPorts) { + cc.ExposedPorts = viper.GetStringSlice(ports) + } + // pre minikube 1.9.2 cc.KubernetesConfig.NodePort was not populated. // in minikube config there were two fields for api server port. // one in cc.KubernetesConfig.NodePort and one in cc.Nodes.Port diff --git a/pkg/drivers/kic/kic.go b/pkg/drivers/kic/kic.go index 120d64a9b646..04bf3d46a506 100644 --- a/pkg/drivers/kic/kic.go +++ b/pkg/drivers/kic/kic.go @@ -78,7 +78,7 @@ func (d *Driver) Create() error { CPUs: strconv.Itoa(d.NodeConfig.CPU), Memory: strconv.Itoa(d.NodeConfig.Memory) + "mb", Envs: d.NodeConfig.Envs, - ExtraArgs: []string{"--expose", fmt.Sprintf("%d", d.NodeConfig.APIServerPort)}, + ExtraArgs: append([]string{"--expose", fmt.Sprintf("%d", d.NodeConfig.APIServerPort)}, d.NodeConfig.ExtraArgs...), OCIBinary: d.NodeConfig.OCIBinary, APIServerPort: d.NodeConfig.APIServerPort, } diff --git a/pkg/drivers/kic/types.go b/pkg/drivers/kic/types.go index 42ec88749a44..78518a330bc9 100644 --- a/pkg/drivers/kic/types.go +++ b/pkg/drivers/kic/types.go @@ -61,4 +61,5 @@ type Config struct { Envs map[string]string // key,value of environment variables passed to the node KubernetesVersion string // Kubernetes version to install ContainerRuntime string // container runtime kic is running + ExtraArgs []string // a list of any extra option to pass to oci binary during creation time, for example --expose 8080... } diff --git a/pkg/minikube/config/types.go b/pkg/minikube/config/types.go index e2f5a66438f4..e56086b96007 100644 --- a/pkg/minikube/config/types.go +++ b/pkg/minikube/config/types.go @@ -71,6 +71,7 @@ type ClusterConfig struct { Addons map[string]bool VerifyComponents map[string]bool // map of components to verify and wait for after start. StartHostTimeout time.Duration + ExposedPorts []string // Only used by the docker and podman driver } // KubernetesConfig contains the parameters used to configure the VM Kubernetes. diff --git a/pkg/minikube/registry/drvs/docker/docker.go b/pkg/minikube/registry/drvs/docker/docker.go index 98d961e1d23d..d51b9347b4ab 100644 --- a/pkg/minikube/registry/drvs/docker/docker.go +++ b/pkg/minikube/registry/drvs/docker/docker.go @@ -60,6 +60,12 @@ func configure(cc config.ClusterConfig, n config.Node) (interface{}, error) { } } + extraArgs := []string{} + + for _, port := range cc.ExposedPorts { + extraArgs = append(extraArgs, "-p", port) + } + return kic.NewDriver(kic.Config{ ClusterName: cc.Name, MachineName: driver.MachineName(cc, n), @@ -72,6 +78,7 @@ func configure(cc config.ClusterConfig, n config.Node) (interface{}, error) { APIServerPort: cc.Nodes[0].Port, KubernetesVersion: cc.KubernetesConfig.KubernetesVersion, ContainerRuntime: cc.KubernetesConfig.ContainerRuntime, + ExtraArgs: extraArgs, }), nil } diff --git a/pkg/minikube/registry/drvs/podman/podman.go b/pkg/minikube/registry/drvs/podman/podman.go index fdf912f5e237..88f09930692e 100644 --- a/pkg/minikube/registry/drvs/podman/podman.go +++ b/pkg/minikube/registry/drvs/podman/podman.go @@ -72,6 +72,12 @@ func configure(cc config.ClusterConfig, n config.Node) (interface{}, error) { } } + extraArgs := []string{} + + for _, port := range cc.ExposedPorts { + extraArgs = append(extraArgs, "-p", port) + } + return kic.NewDriver(kic.Config{ ClusterName: cc.Name, MachineName: driver.MachineName(cc, n), @@ -84,6 +90,7 @@ func configure(cc config.ClusterConfig, n config.Node) (interface{}, error) { APIServerPort: cc.Nodes[0].Port, KubernetesVersion: cc.KubernetesConfig.KubernetesVersion, ContainerRuntime: cc.KubernetesConfig.ContainerRuntime, + ExtraArgs: extraArgs, }), nil } diff --git a/site/content/en/docs/commands/start.md b/site/content/en/docs/commands/start.md index 87538fb59cc8..5d23ddd5e72f 100644 --- a/site/content/en/docs/commands/start.md +++ b/site/content/en/docs/commands/start.md @@ -83,6 +83,7 @@ minikube start [flags] --no-vtx-check Disable checking for the availability of hardware virtualization before the vm is started (virtualbox driver only) -n, --nodes int The number of nodes to spin up. Defaults to 1. (default 1) -o, --output string Format to print stdout in. Options include: [text,json] (default "text") + --ports strings List of ports that should be exposed (docker and podman driver only) --preload If set, download tarball of preloaded images if available to improve start time. Defaults to true. (default true) --registry-mirror strings Registry mirrors to pass to the Docker daemon --service-cluster-ip-range string The CIDR to be used for service cluster IPs. (default "10.96.0.0/12")