Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
327dec43
Unverified
Commit
327dec43
authored
Oct 13, 2016
by
Ilya Dmitrichenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add flags for alternative API and discovery ports (close #34311 #34307 #33638)
parent
40e1aa6b
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
67 additions
and
18 deletions
+67
-18
defaults.go
cmd/kubeadm/app/apis/kubeadm/defaults.go
+2
-0
types.go
cmd/kubeadm/app/apis/kubeadm/types.go
+8
-0
types.go
cmd/kubeadm/app/apis/kubeadm/v1alpha1/types.go
+8
-0
init.go
cmd/kubeadm/app/cmd/init.go
+24
-8
join.go
cmd/kubeadm/app/cmd/join.go
+10
-0
discovery.go
cmd/kubeadm/app/master/discovery.go
+4
-4
kubeconfig.go
cmd/kubeadm/app/master/kubeconfig.go
+3
-2
manifests.go
cmd/kubeadm/app/master/manifests.go
+1
-1
discovery.go
cmd/kubeadm/app/node/discovery.go
+1
-1
checks.go
cmd/kubeadm/app/preflight/checks.go
+4
-2
known-flags.txt
hack/verify-flags/known-flags.txt
+2
-0
No files found.
cmd/kubeadm/app/apis/kubeadm/defaults.go
View file @
327dec43
...
@@ -20,4 +20,6 @@ const (
...
@@ -20,4 +20,6 @@ const (
DefaultServiceDNSDomain
=
"cluster.local"
DefaultServiceDNSDomain
=
"cluster.local"
DefaultServicesSubnet
=
"10.12.0.0/12"
DefaultServicesSubnet
=
"10.12.0.0/12"
DefaultKubernetesVersion
=
"v1.4.1"
DefaultKubernetesVersion
=
"v1.4.1"
DefaultAPIBindPort
=
6443
DefaultDiscoveryBindPort
=
9898
)
)
cmd/kubeadm/app/apis/kubeadm/types.go
View file @
327dec43
...
@@ -23,6 +23,7 @@ type MasterConfiguration struct {
...
@@ -23,6 +23,7 @@ type MasterConfiguration struct {
Secrets
Secrets
Secrets
Secrets
API
API
API
API
Discovery
Discovery
Etcd
Etcd
Etcd
Etcd
Networking
Networking
Networking
Networking
KubernetesVersion
string
KubernetesVersion
string
...
@@ -32,6 +33,11 @@ type MasterConfiguration struct {
...
@@ -32,6 +33,11 @@ type MasterConfiguration struct {
type
API
struct
{
type
API
struct
{
AdvertiseAddresses
[]
string
AdvertiseAddresses
[]
string
ExternalDNSNames
[]
string
ExternalDNSNames
[]
string
BindPort
int32
}
type
Discovery
struct
{
BindPort
int32
}
}
type
Networking
struct
{
type
Networking
struct
{
...
@@ -59,6 +65,8 @@ type NodeConfiguration struct {
...
@@ -59,6 +65,8 @@ type NodeConfiguration struct {
MasterAddresses
[]
string
MasterAddresses
[]
string
Secrets
Secrets
Secrets
Secrets
APIPort
int32
DiscoveryPort
int32
}
}
// ClusterInfo TODO add description
// ClusterInfo TODO add description
...
...
cmd/kubeadm/app/apis/kubeadm/v1alpha1/types.go
View file @
327dec43
...
@@ -24,6 +24,7 @@ type MasterConfiguration struct {
...
@@ -24,6 +24,7 @@ type MasterConfiguration struct {
Secrets
Secrets
`json:"secrets"`
Secrets
Secrets
`json:"secrets"`
API
API
`json:"api"`
API
API
`json:"api"`
Etcd
Etcd
`json:"etcd"`
Etcd
Etcd
`json:"etcd"`
Discovery
Discovery
`json:"discovery"`
Networking
Networking
`json:"networking"`
Networking
Networking
`json:"networking"`
KubernetesVersion
string
`json:"kubernetesVersion"`
KubernetesVersion
string
`json:"kubernetesVersion"`
CloudProvider
string
`json:"cloudProvider"`
CloudProvider
string
`json:"cloudProvider"`
...
@@ -32,6 +33,11 @@ type MasterConfiguration struct {
...
@@ -32,6 +33,11 @@ type MasterConfiguration struct {
type
API
struct
{
type
API
struct
{
AdvertiseAddresses
[]
string
`json:"advertiseAddresses"`
AdvertiseAddresses
[]
string
`json:"advertiseAddresses"`
ExternalDNSNames
[]
string
`json:"externalDNSNames"`
ExternalDNSNames
[]
string
`json:"externalDNSNames"`
BindPort
int32
`json:"bindPort"`
}
type
Discovery
struct
{
BindPort
int32
`json:"bindPort"`
}
}
type
Networking
struct
{
type
Networking
struct
{
...
@@ -59,6 +65,8 @@ type NodeConfiguration struct {
...
@@ -59,6 +65,8 @@ type NodeConfiguration struct {
MasterAddresses
[]
string
`json:"masterAddresses"`
MasterAddresses
[]
string
`json:"masterAddresses"`
Secrets
Secrets
`json:"secrets"`
Secrets
Secrets
`json:"secrets"`
APIPort
int32
`json:"apiPort"`
DiscoveryPort
int32
`json:"discoveryPort"`
}
}
// ClusterInfo TODO add description
// ClusterInfo TODO add description
...
...
cmd/kubeadm/app/cmd/init.go
View file @
327dec43
...
@@ -20,6 +20,7 @@ import (
...
@@ -20,6 +20,7 @@ import (
"fmt"
"fmt"
"io"
"io"
"io/ioutil"
"io/ioutil"
"strings"
"github.com/renstrom/dedent"
"github.com/renstrom/dedent"
"github.com/spf13/cobra"
"github.com/spf13/cobra"
...
@@ -41,7 +42,7 @@ var (
...
@@ -41,7 +42,7 @@ var (
You can now join any number of machines by running the following on each node:
You can now join any number of machines by running the following on each node:
kubeadm join
--token %s
%s
kubeadm join %s
`
)
`
)
)
)
...
@@ -126,6 +127,16 @@ func NewCmdInit(out io.Writer) *cobra.Command {
...
@@ -126,6 +127,16 @@ func NewCmdInit(out io.Writer) *cobra.Command {
"skip preflight checks normally run before modifying the system"
,
"skip preflight checks normally run before modifying the system"
,
)
)
cmd
.
PersistentFlags
()
.
Int32Var
(
&
cfg
.
API
.
BindPort
,
"api-port"
,
kubeadmapi
.
DefaultAPIBindPort
,
"Port for API to bind to"
,
)
cmd
.
PersistentFlags
()
.
Int32Var
(
&
cfg
.
Discovery
.
BindPort
,
"discovery-port"
,
kubeadmapi
.
DefaultDiscoveryBindPort
,
"Port for JWS discovery service to bind to"
,
)
return
cmd
return
cmd
}
}
...
@@ -146,7 +157,7 @@ func NewInit(cfgPath string, cfg *kubeadmapi.MasterConfiguration, skipPreFlight
...
@@ -146,7 +157,7 @@ func NewInit(cfgPath string, cfg *kubeadmapi.MasterConfiguration, skipPreFlight
if
!
skipPreFlight
{
if
!
skipPreFlight
{
fmt
.
Println
(
"Running pre-flight checks"
)
fmt
.
Println
(
"Running pre-flight checks"
)
err
:=
preflight
.
RunInitMasterChecks
()
err
:=
preflight
.
RunInitMasterChecks
(
cfg
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
&
preflight
.
PreFlightError
{
Msg
:
err
.
Error
()}
return
nil
,
&
preflight
.
PreFlightError
{
Msg
:
err
.
Error
()}
}
}
...
@@ -190,7 +201,7 @@ func (i *Init) Run(out io.Writer) error {
...
@@ -190,7 +201,7 @@ func (i *Init) Run(out io.Writer) error {
return
err
return
err
}
}
kubeconfigs
,
err
:=
kubemaster
.
CreateCertsAndConfigForClients
(
i
.
cfg
.
API
.
AdvertiseAddresses
,
[]
string
{
"kubelet"
,
"admin"
},
caKey
,
caCert
)
kubeconfigs
,
err
:=
kubemaster
.
CreateCertsAndConfigForClients
(
i
.
cfg
.
API
,
[]
string
{
"kubelet"
,
"admin"
},
caKey
,
caCert
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -228,11 +239,16 @@ func (i *Init) Run(out io.Writer) error {
...
@@ -228,11 +239,16 @@ func (i *Init) Run(out io.Writer) error {
return
err
return
err
}
}
// TODO(phase1+) use templates to reference struct fields directly as order of args is fragile
// TODO(phase1+) we could probably use templates for this logic, and reference struct fields directly etc
fmt
.
Fprintf
(
out
,
initDoneMsgf
,
joinArgs
:=
[]
string
{
fmt
.
Sprintf
(
"--token=%s"
,
i
.
cfg
.
Secrets
.
GivenToken
)}
i
.
cfg
.
Secrets
.
GivenToken
,
if
i
.
cfg
.
API
.
BindPort
!=
kubeadmapi
.
DefaultAPIBindPort
{
i
.
cfg
.
API
.
AdvertiseAddresses
[
0
],
joinArgs
=
append
(
joinArgs
,
fmt
.
Sprintf
(
"--api-port=%d"
,
i
.
cfg
.
API
.
BindPort
))
)
}
if
i
.
cfg
.
Discovery
.
BindPort
!=
kubeadmapi
.
DefaultDiscoveryBindPort
{
joinArgs
=
append
(
joinArgs
,
fmt
.
Sprintf
(
"--discovery-port=%d"
,
i
.
cfg
.
Discovery
.
BindPort
))
}
joinArgs
=
append
(
joinArgs
,
i
.
cfg
.
API
.
AdvertiseAddresses
[
0
])
fmt
.
Fprintf
(
out
,
initDoneMsgf
,
strings
.
Join
(
joinArgs
,
" "
))
return
nil
return
nil
}
}
cmd/kubeadm/app/cmd/join.go
View file @
327dec43
...
@@ -70,6 +70,16 @@ func NewCmdJoin(out io.Writer) *cobra.Command {
...
@@ -70,6 +70,16 @@ func NewCmdJoin(out io.Writer) *cobra.Command {
"skip preflight checks normally run before modifying the system"
,
"skip preflight checks normally run before modifying the system"
,
)
)
cmd
.
PersistentFlags
()
.
Int32Var
(
&
cfg
.
APIPort
,
"api-port"
,
kubeadmapi
.
DefaultAPIBindPort
,
"(optional) API server port on the master"
,
)
cmd
.
PersistentFlags
()
.
Int32Var
(
&
cfg
.
DiscoveryPort
,
"discovery-port"
,
kubeadmapi
.
DefaultDiscoveryBindPort
,
"(optional) Discovery port on the master"
,
)
return
cmd
return
cmd
}
}
...
...
cmd/kubeadm/app/master/discovery.go
View file @
327dec43
...
@@ -48,7 +48,7 @@ func encodeKubeDiscoverySecretData(s *kubeadmapi.MasterConfiguration, caCert *x5
...
@@ -48,7 +48,7 @@ func encodeKubeDiscoverySecretData(s *kubeadmapi.MasterConfiguration, caCert *x5
)
)
for
_
,
addr
:=
range
s
.
API
.
AdvertiseAddresses
{
for
_
,
addr
:=
range
s
.
API
.
AdvertiseAddresses
{
endpointList
=
append
(
endpointList
,
fmt
.
Sprintf
(
"https://%s:
443"
,
addr
))
endpointList
=
append
(
endpointList
,
fmt
.
Sprintf
(
"https://%s:
%d"
,
addr
,
s
.
API
.
BindPort
))
}
}
tokenMap
[
s
.
Secrets
.
TokenID
]
=
s
.
Secrets
.
BearerToken
tokenMap
[
s
.
Secrets
.
TokenID
]
=
s
.
Secrets
.
BearerToken
...
@@ -60,7 +60,7 @@ func encodeKubeDiscoverySecretData(s *kubeadmapi.MasterConfiguration, caCert *x5
...
@@ -60,7 +60,7 @@ func encodeKubeDiscoverySecretData(s *kubeadmapi.MasterConfiguration, caCert *x5
return
data
return
data
}
}
func
newKubeDiscoveryPodSpec
()
api
.
PodSpec
{
func
newKubeDiscoveryPodSpec
(
s
*
kubeadmapi
.
MasterConfiguration
)
api
.
PodSpec
{
envParams
:=
kubeadmapi
.
GetEnvParams
()
envParams
:=
kubeadmapi
.
GetEnvParams
()
return
api
.
PodSpec
{
return
api
.
PodSpec
{
// We have to use host network namespace, as `HostPort`/`HostIP` are Docker's
// We have to use host network namespace, as `HostPort`/`HostIP` are Docker's
...
@@ -80,7 +80,7 @@ func newKubeDiscoveryPodSpec() api.PodSpec {
...
@@ -80,7 +80,7 @@ func newKubeDiscoveryPodSpec() api.PodSpec {
Ports
:
[]
api
.
ContainerPort
{
Ports
:
[]
api
.
ContainerPort
{
// TODO when CNI issue (#31307) is resolved, we should consider adding
// TODO when CNI issue (#31307) is resolved, we should consider adding
// `HostIP: s.API.AdvertiseAddrs[0]`, if there is only one address`
// `HostIP: s.API.AdvertiseAddrs[0]`, if there is only one address`
{
Name
:
"http"
,
ContainerPort
:
9898
,
HostPort
:
9898
},
{
Name
:
"http"
,
ContainerPort
:
kubeadmapi
.
DefaultDiscoveryBindPort
,
HostPort
:
s
.
Discovery
.
BindPort
},
},
},
SecurityContext
:
&
api
.
SecurityContext
{
SecurityContext
:
&
api
.
SecurityContext
{
SELinuxOptions
:
&
api
.
SELinuxOptions
{
SELinuxOptions
:
&
api
.
SELinuxOptions
{
...
@@ -103,7 +103,7 @@ func newKubeDiscoveryPodSpec() api.PodSpec {
...
@@ -103,7 +103,7 @@ func newKubeDiscoveryPodSpec() api.PodSpec {
func
newKubeDiscovery
(
s
*
kubeadmapi
.
MasterConfiguration
,
caCert
*
x509
.
Certificate
)
kubeDiscovery
{
func
newKubeDiscovery
(
s
*
kubeadmapi
.
MasterConfiguration
,
caCert
*
x509
.
Certificate
)
kubeDiscovery
{
kd
:=
kubeDiscovery
{
kd
:=
kubeDiscovery
{
Deployment
:
NewDeployment
(
kubeDiscoveryName
,
1
,
newKubeDiscoveryPodSpec
()),
Deployment
:
NewDeployment
(
kubeDiscoveryName
,
1
,
newKubeDiscoveryPodSpec
(
s
)),
Secret
:
&
api
.
Secret
{
Secret
:
&
api
.
Secret
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
kubeDiscoverySecretName
},
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
kubeDiscoverySecretName
},
Type
:
api
.
SecretTypeOpaque
,
Type
:
api
.
SecretTypeOpaque
,
...
...
cmd/kubeadm/app/master/kubeconfig.go
View file @
327dec43
...
@@ -22,19 +22,20 @@ import (
...
@@ -22,19 +22,20 @@ import (
"fmt"
"fmt"
// TODO: "k8s.io/client-go/client/tools/clientcmd/api"
// TODO: "k8s.io/client-go/client/tools/clientcmd/api"
kubeadmapi
"k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
kubeadmutil
"k8s.io/kubernetes/cmd/kubeadm/app/util"
kubeadmutil
"k8s.io/kubernetes/cmd/kubeadm/app/util"
clientcmdapi
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd/api"
clientcmdapi
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd/api"
certutil
"k8s.io/kubernetes/pkg/util/cert"
certutil
"k8s.io/kubernetes/pkg/util/cert"
)
)
func
CreateCertsAndConfigForClients
(
advertiseAddresses
,
clientNames
[]
string
,
caKey
*
rsa
.
PrivateKey
,
caCert
*
x509
.
Certificate
)
(
map
[
string
]
*
clientcmdapi
.
Config
,
error
)
{
func
CreateCertsAndConfigForClients
(
cfg
kubeadmapi
.
API
,
clientNames
[]
string
,
caKey
*
rsa
.
PrivateKey
,
caCert
*
x509
.
Certificate
)
(
map
[
string
]
*
clientcmdapi
.
Config
,
error
)
{
basicClientConfig
:=
kubeadmutil
.
CreateBasicClientConfig
(
basicClientConfig
:=
kubeadmutil
.
CreateBasicClientConfig
(
"kubernetes"
,
"kubernetes"
,
// TODO this is not great, but there is only one address we can use here
// TODO this is not great, but there is only one address we can use here
// so we'll pick the first one, there is much of chance to have an empty
// so we'll pick the first one, there is much of chance to have an empty
// slice by the time this gets called
// slice by the time this gets called
fmt
.
Sprintf
(
"https://%s:
443"
,
advertiseAddresses
[
0
]
),
fmt
.
Sprintf
(
"https://%s:
%d"
,
cfg
.
AdvertiseAddresses
[
0
],
cfg
.
BindPort
),
certutil
.
EncodeCertPEM
(
caCert
),
certutil
.
EncodeCertPEM
(
caCert
),
)
)
...
...
cmd/kubeadm/app/master/manifests.go
View file @
327dec43
...
@@ -232,7 +232,7 @@ func getComponentCommand(component string, s *kubeadmapi.MasterConfiguration) (c
...
@@ -232,7 +232,7 @@ func getComponentCommand(component string, s *kubeadmapi.MasterConfiguration) (c
"--tls-cert-file="
+
pkiDir
+
"/apiserver.pem"
,
"--tls-cert-file="
+
pkiDir
+
"/apiserver.pem"
,
"--tls-private-key-file="
+
pkiDir
+
"/apiserver-key.pem"
,
"--tls-private-key-file="
+
pkiDir
+
"/apiserver-key.pem"
,
"--token-auth-file="
+
pkiDir
+
"/tokens.csv"
,
"--token-auth-file="
+
pkiDir
+
"/tokens.csv"
,
"--secure-port=443"
,
fmt
.
Sprintf
(
"--secure-port=%d"
,
s
.
API
.
BindPort
)
,
"--allow-privileged"
,
"--allow-privileged"
,
},
},
controllerManager
:
{
controllerManager
:
{
...
...
cmd/kubeadm/app/node/discovery.go
View file @
327dec43
...
@@ -33,7 +33,7 @@ import (
...
@@ -33,7 +33,7 @@ import (
const
discoveryRetryTimeout
=
5
*
time
.
Second
const
discoveryRetryTimeout
=
5
*
time
.
Second
func
RetrieveTrustedClusterInfo
(
s
*
kubeadmapi
.
NodeConfiguration
)
(
*
kubeadmapi
.
ClusterInfo
,
error
)
{
func
RetrieveTrustedClusterInfo
(
s
*
kubeadmapi
.
NodeConfiguration
)
(
*
kubeadmapi
.
ClusterInfo
,
error
)
{
host
,
port
:=
s
.
MasterAddresses
[
0
],
9898
host
,
port
:=
s
.
MasterAddresses
[
0
],
s
.
DiscoveryPort
requestURL
:=
fmt
.
Sprintf
(
"http://%s:%d/cluster-info/v1/?token-id=%s"
,
host
,
port
,
s
.
Secrets
.
TokenID
)
requestURL
:=
fmt
.
Sprintf
(
"http://%s:%d/cluster-info/v1/?token-id=%s"
,
host
,
port
,
s
.
Secrets
.
TokenID
)
req
,
err
:=
http
.
NewRequest
(
"GET"
,
requestURL
,
nil
)
req
,
err
:=
http
.
NewRequest
(
"GET"
,
requestURL
,
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
cmd/kubeadm/app/preflight/checks.go
View file @
327dec43
...
@@ -24,6 +24,7 @@ import (
...
@@ -24,6 +24,7 @@ import (
"os"
"os"
"os/exec"
"os/exec"
kubeadmapi
"k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
"k8s.io/kubernetes/pkg/util/initsystem"
"k8s.io/kubernetes/pkg/util/initsystem"
)
)
...
@@ -156,15 +157,16 @@ func (ipc InPathCheck) Check() (warnings, errors []error) {
...
@@ -156,15 +157,16 @@ func (ipc InPathCheck) Check() (warnings, errors []error) {
return
nil
,
nil
return
nil
,
nil
}
}
func
RunInitMasterChecks
()
error
{
func
RunInitMasterChecks
(
cfg
*
kubeadmapi
.
MasterConfiguration
)
error
{
// TODO: Some of these ports should come from kubeadm config eventually:
// TODO: Some of these ports should come from kubeadm config eventually:
checks
:=
[]
PreFlightCheck
{
checks
:=
[]
PreFlightCheck
{
IsRootCheck
{
root
:
true
},
IsRootCheck
{
root
:
true
},
ServiceCheck
{
Service
:
"kubelet"
},
ServiceCheck
{
Service
:
"kubelet"
},
ServiceCheck
{
Service
:
"docker"
},
ServiceCheck
{
Service
:
"docker"
},
PortOpenCheck
{
port
:
443
},
PortOpenCheck
{
port
:
int
(
cfg
.
API
.
BindPort
)
},
PortOpenCheck
{
port
:
2379
},
PortOpenCheck
{
port
:
2379
},
PortOpenCheck
{
port
:
8080
},
PortOpenCheck
{
port
:
8080
},
PortOpenCheck
{
port
:
int
(
cfg
.
Discovery
.
BindPort
)},
PortOpenCheck
{
port
:
10250
},
PortOpenCheck
{
port
:
10250
},
PortOpenCheck
{
port
:
10251
},
PortOpenCheck
{
port
:
10251
},
PortOpenCheck
{
port
:
10252
},
PortOpenCheck
{
port
:
10252
},
...
...
hack/verify-flags/known-flags.txt
View file @
327dec43
...
@@ -12,6 +12,7 @@ allowed-not-ready-nodes
...
@@ -12,6 +12,7 @@ allowed-not-ready-nodes
anonymous-auth
anonymous-auth
api-advertise-addresses
api-advertise-addresses
api-external-dns-names
api-external-dns-names
api-port
api-burst
api-burst
api-prefix
api-prefix
api-rate
api-rate
...
@@ -129,6 +130,7 @@ dest-file
...
@@ -129,6 +130,7 @@ dest-file
disable-filter
disable-filter
disable-kubenet
disable-kubenet
dns-bind-address
dns-bind-address
discovery-port
dns-port
dns-port
dns-provider
dns-provider
dns-provider-config
dns-provider-config
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment