Skip to content

Commit da0cdb9

Browse files
committed
Add listen-apiserver-port for docker driver
1 parent 6e803a1 commit da0cdb9

File tree

11 files changed

+77
-47
lines changed

11 files changed

+77
-47
lines changed

cmd/minikube/cmd/start.go

+12
Original file line numberDiff line numberDiff line change
@@ -1088,6 +1088,10 @@ func validateFlags(cmd *cobra.Command, drvName string) {
10881088
validateListenAddress(viper.GetString(listenAddress))
10891089
}
10901090

1091+
if cmd.Flags().Changed(listenAPIServerPort) {
1092+
validateListenAPIServerPort(viper.GetInt(listenAPIServerPort))
1093+
}
1094+
10911095
if cmd.Flags().Changed(imageRepository) {
10921096
viper.Set(imageRepository, validateImageRepository(viper.GetString(imageRepository)))
10931097
}
@@ -1244,6 +1248,14 @@ func validateListenAddress(listenAddr string) {
12441248
}
12451249
}
12461250

1251+
// This function validates if the --listen-apiserver-port
1252+
// is valid
1253+
func validateListenAPIServerPort(listenAPIServerPort int) {
1254+
if listenAPIServerPort < 0 || listenAPIServerPort > 65535 {
1255+
exit.Message(reason.Usage, "Sorry, the port provided with the --listen-apiserver-port flag is invalid: {{.listenAPIServerPort}}.", out.V{"listenAPIServerPort": listenAPIServerPort})
1256+
}
1257+
}
1258+
12471259
// This function validates that the --insecure-registry follows one of the following formats:
12481260
// "<ip>[:<port>]" "<hostname>[:<port>]" "<network>/<netmask>"
12491261
func validateInsecureRegistry() {

cmd/minikube/cmd/start_flags.go

+3
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ const (
118118
defaultSSHUser = "root"
119119
defaultSSHPort = 22
120120
listenAddress = "listen-address"
121+
listenAPIServerPort = "listen-apiserver-port"
121122
)
122123

123124
var (
@@ -219,6 +220,7 @@ func initDriverFlags() {
219220

220221
// docker & podman
221222
startCmd.Flags().String(listenAddress, "", "IP Address to use to expose ports (docker and podman driver only)")
223+
startCmd.Flags().Int(listenAPIServerPort, 0, "Port that apiserver exposed (docker and podman driver only). Use it with --listen-address=0.0.0.0(for remote access) --apiserver-ips=HostIP(for certificate).")
222224
startCmd.Flags().StringSlice(ports, []string{}, "List of ports that should be exposed (docker and podman driver only)")
223225
}
224226

@@ -369,6 +371,7 @@ func generateNewConfigFromFlags(cmd *cobra.Command, k8sVersion string, drvName s
369371
DiskSize: diskSize,
370372
Driver: drvName,
371373
ListenAddress: viper.GetString(listenAddress),
374+
ListenAPIServerPort: viper.GetInt(listenAPIServerPort),
372375
HyperkitVpnKitSock: viper.GetString(vpnkitSock),
373376
HyperkitVSockPorts: viper.GetStringSlice(vsockPorts),
374377
NFSShare: viper.GetStringSlice(nfsShare),

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ require (
3838
github.com/hectane/go-acl v0.0.0-20190604041725-da78bae5fc95 // indirect
3939
github.com/hooklift/assert v0.0.0-20170704181755-9d1defd6d214 // indirect
4040
github.com/hooklift/iso9660 v0.0.0-20170318115843-1cf07e5970d8
41-
github.com/intel-go/cpuid v0.0.0-20181003105527-1a4a6f06a1c6
41+
github.com/intel-go/cpuid v0.0.0-20181003105527-1a4a6f06a1c6 // indirect
4242
github.com/johanneswuerbach/nfsexports v0.0.0-20200318065542-c48c3734757f
4343
github.com/juju/clock v0.0.0-20190205081909-9c5c9712527c
4444
github.com/juju/errors v0.0.0-20190806202954-0232dcc7464d // indirect

go.sum

-1
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,6 @@ github.com/opencontainers/selinux v1.8.0/go.mod h1:RScLhm78qiWa2gbVCcGkC7tCGdgk3
809809
github.com/otiai10/copy v1.5.0 h1:SoXDGnlTUZoqB/wSuj/Y5L6T5i6iN4YRAcMCd+JnLNU=
810810
github.com/otiai10/copy v1.5.0/go.mod h1:XWfuS3CrI0R6IE0FbgHsEazaXO8G0LpMp9o8tos0x4E=
811811
github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95/go.mod h1:9qAhocn7zKJG+0mI8eUu6xqkFDYS2kb2saOteoSB3cE=
812-
github.com/otiai10/curr v1.0.0 h1:TJIWdbX0B+kpNagQrjgq8bCMrbhiuX73M2XwgtDMoOI=
813812
github.com/otiai10/curr v1.0.0/go.mod h1:LskTG5wDwr8Rs+nNQ+1LlxRjAtTZZjtJW4rMXl6j4vs=
814813
github.com/otiai10/mint v1.3.0/go.mod h1:F5AjcsTsWUqX+Na9fpHb52P8pcRX2CI6A3ctIT91xUo=
815814
github.com/otiai10/mint v1.3.2 h1:VYWnrP5fXmz1MXvjuUvcBrXSjGE6xjON+axB/UrpO3E=

pkg/drivers/kic/kic.go

+6
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,16 @@ func (d *Driver) Create() error {
116116
listAddr = "0.0.0.0"
117117
}
118118

119+
listenAPIServerPort := 0
120+
if d.NodeConfig.ListenAPIServerPort != 0 {
121+
listenAPIServerPort = d.NodeConfig.ListenAPIServerPort
122+
}
123+
119124
// control plane specific options
120125
params.PortMappings = append(params.PortMappings,
121126
oci.PortMapping{
122127
ListenAddress: listAddr,
128+
HostPort: int32(listenAPIServerPort),
123129
ContainerPort: int32(params.APIServerPort),
124130
},
125131
oci.PortMapping{

pkg/drivers/kic/oci/oci.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -502,8 +502,13 @@ func generatePortMappings(portMappings ...PortMapping) []string {
502502
result := make([]string, 0, len(portMappings))
503503
for _, pm := range portMappings {
504504
// let docker pick a host port by leaving it as ::
505-
// example --publish=127.0.0.17::8443 will get a random host port for 8443
506-
publish := fmt.Sprintf("--publish=%s::%d", pm.ListenAddress, pm.ContainerPort)
505+
// example --publish=127.0.0.17:8443:8443 will get a fixed host port for 8443
506+
publish := ""
507+
if pm.HostPort != 0 {
508+
publish = fmt.Sprintf("--publish=%s:%d:%d", pm.ListenAddress, pm.HostPort, pm.ContainerPort)
509+
} else {
510+
publish = fmt.Sprintf("--publish=%s::%d", pm.ListenAddress, pm.ContainerPort)
511+
}
507512
result = append(result, publish)
508513
}
509514
return result

pkg/drivers/kic/types.go

+17-16
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,21 @@ var (
4747

4848
// Config is configuration for the kic driver used by registry
4949
type Config struct {
50-
ClusterName string // The cluster the container belongs to
51-
MachineName string // maps to the container name being created
52-
CPU int // Number of CPU cores assigned to the container
53-
Memory int // max memory in MB
54-
StorePath string // libmachine store path
55-
OCIBinary string // oci tool to use (docker, podman,...)
56-
ImageDigest string // image name with sha to use for the node
57-
Mounts []oci.Mount // mounts
58-
APIServerPort int // Kubernetes api server port inside the container
59-
PortMappings []oci.PortMapping // container port mappings
60-
Envs map[string]string // key,value of environment variables passed to the node
61-
KubernetesVersion string // Kubernetes version to install
62-
ContainerRuntime string // container runtime kic is running
63-
Network string // network to run with kic
64-
ExtraArgs []string // a list of any extra option to pass to oci binary during creation time, for example --expose 8080...
65-
ListenAddress string // IP Address to listen to
50+
ClusterName string // The cluster the container belongs to
51+
MachineName string // maps to the container name being created
52+
CPU int // Number of CPU cores assigned to the container
53+
Memory int // max memory in MB
54+
StorePath string // libmachine store path
55+
OCIBinary string // oci tool to use (docker, podman,...)
56+
ImageDigest string // image name with sha to use for the node
57+
Mounts []oci.Mount // mounts
58+
APIServerPort int // Kubernetes api server port inside the container
59+
PortMappings []oci.PortMapping // container port mappings
60+
Envs map[string]string // key,value of environment variables passed to the node
61+
KubernetesVersion string // Kubernetes version to install
62+
ContainerRuntime string // container runtime kic is running
63+
Network string // network to run with kic
64+
ExtraArgs []string // a list of any extra option to pass to oci binary during creation time, for example --expose 8080...
65+
ListenAddress string // IP Address to listen to
66+
ListenAPIServerPort int // apiserver Port to listen to
6667
}

pkg/minikube/config/types.go

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ type ClusterConfig struct {
7979
ScheduledStop *ScheduledStopConfig
8080
ExposedPorts []string // Only used by the docker and podman driver
8181
ListenAddress string // Only used by the docker and podman driver
82+
ListenAPIServerPort int // Only used by the docker and podman driver
8283
Network string // only used by docker driver
8384
MultiNodeRequested bool
8485
}

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

+15-14
Original file line numberDiff line numberDiff line change
@@ -70,20 +70,21 @@ func configure(cc config.ClusterConfig, n config.Node) (interface{}, error) {
7070
}
7171

7272
return kic.NewDriver(kic.Config{
73-
ClusterName: cc.Name,
74-
MachineName: config.MachineName(cc, n),
75-
StorePath: localpath.MiniPath(),
76-
ImageDigest: cc.KicBaseImage,
77-
Mounts: mounts,
78-
CPU: cc.CPUs,
79-
Memory: cc.Memory,
80-
OCIBinary: oci.Docker,
81-
APIServerPort: cc.Nodes[0].Port,
82-
KubernetesVersion: cc.KubernetesConfig.KubernetesVersion,
83-
ContainerRuntime: cc.KubernetesConfig.ContainerRuntime,
84-
ExtraArgs: extraArgs,
85-
Network: cc.Network,
86-
ListenAddress: cc.ListenAddress,
73+
ClusterName: cc.Name,
74+
MachineName: config.MachineName(cc, n),
75+
StorePath: localpath.MiniPath(),
76+
ImageDigest: cc.KicBaseImage,
77+
Mounts: mounts,
78+
CPU: cc.CPUs,
79+
Memory: cc.Memory,
80+
OCIBinary: oci.Docker,
81+
APIServerPort: cc.Nodes[0].Port,
82+
KubernetesVersion: cc.KubernetesConfig.KubernetesVersion,
83+
ContainerRuntime: cc.KubernetesConfig.ContainerRuntime,
84+
ExtraArgs: extraArgs,
85+
Network: cc.Network,
86+
ListenAddress: cc.ListenAddress,
87+
ListenAPIServerPort: cc.ListenAPIServerPort,
8788
}), nil
8889
}
8990

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

+14-13
Original file line numberDiff line numberDiff line change
@@ -83,19 +83,20 @@ func configure(cc config.ClusterConfig, n config.Node) (interface{}, error) {
8383
}
8484

8585
return kic.NewDriver(kic.Config{
86-
ClusterName: cc.Name,
87-
MachineName: config.MachineName(cc, n),
88-
StorePath: localpath.MiniPath(),
89-
ImageDigest: strings.Split(cc.KicBaseImage, "@")[0], // for podman does not support docker images references with both a tag and digest.
90-
Mounts: mounts,
91-
CPU: cc.CPUs,
92-
Memory: cc.Memory,
93-
OCIBinary: oci.Podman,
94-
APIServerPort: cc.Nodes[0].Port,
95-
KubernetesVersion: cc.KubernetesConfig.KubernetesVersion,
96-
ContainerRuntime: cc.KubernetesConfig.ContainerRuntime,
97-
ExtraArgs: extraArgs,
98-
ListenAddress: cc.ListenAddress,
86+
ClusterName: cc.Name,
87+
MachineName: config.MachineName(cc, n),
88+
StorePath: localpath.MiniPath(),
89+
ImageDigest: strings.Split(cc.KicBaseImage, "@")[0], // for podman does not support docker images references with both a tag and digest.
90+
Mounts: mounts,
91+
CPU: cc.CPUs,
92+
Memory: cc.Memory,
93+
OCIBinary: oci.Podman,
94+
APIServerPort: cc.Nodes[0].Port,
95+
KubernetesVersion: cc.KubernetesConfig.KubernetesVersion,
96+
ContainerRuntime: cc.KubernetesConfig.ContainerRuntime,
97+
ExtraArgs: extraArgs,
98+
ListenAddress: cc.ListenAddress,
99+
ListenAPIServerPort: cc.ListenAPIServerPort,
99100
}), nil
100101
}
101102

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

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ minikube start [flags]
7373
--kvm-numa-count int Simulate numa node count in minikube, supported numa node count range is 1-8 (kvm2 driver only) (default 1)
7474
--kvm-qemu-uri string The KVM QEMU connection URI. (kvm2 driver only) (default "qemu:///system")
7575
--listen-address string IP Address to use to expose ports (docker and podman driver only)
76+
--listen-apiserver-port int Port that apiserver exposed (docker and podman driver only). Use it with --listen-address=0.0.0.0(for remote access) --apiserver-ips=HostIP(for certificate).
7677
--memory string Amount of RAM to allocate to Kubernetes (format: <number>[<unit>], where unit = b, k, m or g).
7778
--mount This will start the mount daemon and automatically mount files into minikube.
7879
--mount-string string The argument to pass the minikube mount command on start.

0 commit comments

Comments
 (0)