Skip to content

Commit e573b92

Browse files
authored
Merge pull request #9404 from ToonvanStrijp/master
Add new flag "--ports" to expose ports for docker & podman drivers
2 parents 0068dfb + 61048ee commit e573b92

File tree

7 files changed

+27
-1
lines changed

7 files changed

+27
-1
lines changed

cmd/minikube/cmd/start_flags.go

+9
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ const (
107107
forceSystemd = "force-systemd"
108108
kicBaseImage = "base-image"
109109
startOutput = "output"
110+
ports = "ports"
110111
)
111112

112113
// initMinikubeFlags includes commandline flags for minikube.
@@ -197,6 +198,9 @@ func initDriverFlags() {
197198
startCmd.Flags().String(hypervVirtualSwitch, "", "The hyperv virtual switch name. Defaults to first found. (hyperv driver only)")
198199
startCmd.Flags().Bool(hypervUseExternalSwitch, false, "Whether to use external switch over Default Switch if virtual switch not explicitly specified. (hyperv driver only)")
199200
startCmd.Flags().String(hypervExternalAdapter, "", "External Adapter on which external switch will be created if no external switch is found. (hyperv driver only)")
201+
202+
// docker & podman
203+
startCmd.Flags().StringSlice(ports, []string{}, "List of ports that should be exposed (docker and podman driver only)")
200204
}
201205

202206
// initNetworkingFlags inits the commandline flags for connectivity related flags for start
@@ -311,6 +315,7 @@ func generateClusterConfig(cmd *cobra.Command, existing *config.ClusterConfig, k
311315
HostOnlyNicType: viper.GetString(hostOnlyNicType),
312316
NatNicType: viper.GetString(natNicType),
313317
StartHostTimeout: viper.GetDuration(waitTimeout),
318+
ExposedPorts: viper.GetStringSlice(ports),
314319
KubernetesConfig: config.KubernetesConfig{
315320
KubernetesVersion: k8sVersion,
316321
ClusterName: ClusterFlagValue(),
@@ -547,6 +552,10 @@ func updateExistingConfigFromFlags(cmd *cobra.Command, existing *config.ClusterC
547552
cc.KubernetesConfig.NodePort = viper.GetInt(apiServerPort)
548553
}
549554

555+
if cmd.Flags().Changed(vsockPorts) {
556+
cc.ExposedPorts = viper.GetStringSlice(ports)
557+
}
558+
550559
// pre minikube 1.9.2 cc.KubernetesConfig.NodePort was not populated.
551560
// in minikube config there were two fields for api server port.
552561
// one in cc.KubernetesConfig.NodePort and one in cc.Nodes.Port

pkg/drivers/kic/kic.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func (d *Driver) Create() error {
7878
CPUs: strconv.Itoa(d.NodeConfig.CPU),
7979
Memory: strconv.Itoa(d.NodeConfig.Memory) + "mb",
8080
Envs: d.NodeConfig.Envs,
81-
ExtraArgs: []string{"--expose", fmt.Sprintf("%d", d.NodeConfig.APIServerPort)},
81+
ExtraArgs: append([]string{"--expose", fmt.Sprintf("%d", d.NodeConfig.APIServerPort)}, d.NodeConfig.ExtraArgs...),
8282
OCIBinary: d.NodeConfig.OCIBinary,
8383
APIServerPort: d.NodeConfig.APIServerPort,
8484
}

pkg/drivers/kic/types.go

+1
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,5 @@ type Config struct {
6161
Envs map[string]string // key,value of environment variables passed to the node
6262
KubernetesVersion string // Kubernetes version to install
6363
ContainerRuntime string // container runtime kic is running
64+
ExtraArgs []string // a list of any extra option to pass to oci binary during creation time, for example --expose 8080...
6465
}

pkg/minikube/config/types.go

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ type ClusterConfig struct {
7171
Addons map[string]bool
7272
VerifyComponents map[string]bool // map of components to verify and wait for after start.
7373
StartHostTimeout time.Duration
74+
ExposedPorts []string // Only used by the docker and podman driver
7475
}
7576

7677
// KubernetesConfig contains the parameters used to configure the VM Kubernetes.

pkg/minikube/registry/drvs/docker/docker.go

+7
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ func configure(cc config.ClusterConfig, n config.Node) (interface{}, error) {
6060
}
6161
}
6262

63+
extraArgs := []string{}
64+
65+
for _, port := range cc.ExposedPorts {
66+
extraArgs = append(extraArgs, "-p", port)
67+
}
68+
6369
return kic.NewDriver(kic.Config{
6470
ClusterName: cc.Name,
6571
MachineName: driver.MachineName(cc, n),
@@ -72,6 +78,7 @@ func configure(cc config.ClusterConfig, n config.Node) (interface{}, error) {
7278
APIServerPort: cc.Nodes[0].Port,
7379
KubernetesVersion: cc.KubernetesConfig.KubernetesVersion,
7480
ContainerRuntime: cc.KubernetesConfig.ContainerRuntime,
81+
ExtraArgs: extraArgs,
7582
}), nil
7683
}
7784

pkg/minikube/registry/drvs/podman/podman.go

+7
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ func configure(cc config.ClusterConfig, n config.Node) (interface{}, error) {
7272
}
7373
}
7474

75+
extraArgs := []string{}
76+
77+
for _, port := range cc.ExposedPorts {
78+
extraArgs = append(extraArgs, "-p", port)
79+
}
80+
7581
return kic.NewDriver(kic.Config{
7682
ClusterName: cc.Name,
7783
MachineName: driver.MachineName(cc, n),
@@ -84,6 +90,7 @@ func configure(cc config.ClusterConfig, n config.Node) (interface{}, error) {
8490
APIServerPort: cc.Nodes[0].Port,
8591
KubernetesVersion: cc.KubernetesConfig.KubernetesVersion,
8692
ContainerRuntime: cc.KubernetesConfig.ContainerRuntime,
93+
ExtraArgs: extraArgs,
8794
}), nil
8895
}
8996

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

+1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ minikube start [flags]
8383
--no-vtx-check Disable checking for the availability of hardware virtualization before the vm is started (virtualbox driver only)
8484
-n, --nodes int The number of nodes to spin up. Defaults to 1. (default 1)
8585
-o, --output string Format to print stdout in. Options include: [text,json] (default "text")
86+
--ports strings List of ports that should be exposed (docker and podman driver only)
8687
--preload If set, download tarball of preloaded images if available to improve start time. Defaults to true. (default true)
8788
--registry-mirror strings Registry mirrors to pass to the Docker daemon
8889
--service-cluster-ip-range string The CIDR to be used for service cluster IPs. (default "10.96.0.0/12")

0 commit comments

Comments
 (0)