2019-01-12 04:58:27 +00:00
/ *
Copyright 2014 The Kubernetes Authors .
Licensed under the Apache License , Version 2.0 ( the "License" ) ;
you may not use this file except in compliance with the License .
You may obtain a copy of the License at
http : //www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing , software
distributed under the License is distributed on an "AS IS" BASIS ,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied .
See the License for the specific language governing permissions and
limitations under the License .
* /
// Package options contains flags and options for initializing an apiserver
package options
import (
"net"
"strings"
"time"
2020-12-01 01:06:26 +00:00
"github.com/spf13/pflag"
2019-01-12 04:58:27 +00:00
utilnet "k8s.io/apimachinery/pkg/util/net"
genericoptions "k8s.io/apiserver/pkg/server/options"
"k8s.io/apiserver/pkg/storage/storagebackend"
2019-04-07 17:07:55 +00:00
cliflag "k8s.io/component-base/cli/flag"
2020-08-10 17:43:49 +00:00
"k8s.io/component-base/logs"
"k8s.io/component-base/metrics"
2020-12-01 01:06:26 +00:00
2019-01-12 04:58:27 +00:00
api "k8s.io/kubernetes/pkg/apis/core"
2020-12-01 01:06:26 +00:00
"k8s.io/kubernetes/pkg/cluster/ports"
"k8s.io/kubernetes/pkg/controlplane/reconcilers"
2019-01-12 04:58:27 +00:00
_ "k8s.io/kubernetes/pkg/features" // add the kubernetes feature gates
kubeoptions "k8s.io/kubernetes/pkg/kubeapiserver/options"
kubeletclient "k8s.io/kubernetes/pkg/kubelet/client"
"k8s.io/kubernetes/pkg/serviceaccount"
)
2020-12-01 01:06:26 +00:00
// InsecurePortFlags are dummy flags, they are kept only for compatibility and will be removed in v1.24.
// TODO: remove these flags in v1.24.
var InsecurePortFlags = [ ] string { "insecure-port" , "port" }
2019-01-12 04:58:27 +00:00
// ServerRunOptions runs a kubernetes api server.
type ServerRunOptions struct {
GenericServerRunOptions * genericoptions . ServerRunOptions
Etcd * genericoptions . EtcdOptions
SecureServing * genericoptions . SecureServingOptionsWithLoopback
Audit * genericoptions . AuditOptions
Features * genericoptions . FeatureOptions
Admission * kubeoptions . AdmissionOptions
Authentication * kubeoptions . BuiltInAuthenticationOptions
Authorization * kubeoptions . BuiltInAuthorizationOptions
CloudProvider * kubeoptions . CloudProviderOptions
APIEnablement * genericoptions . APIEnablementOptions
2019-09-27 21:51:53 +00:00
EgressSelector * genericoptions . EgressSelectorOptions
2020-08-10 17:43:49 +00:00
Metrics * metrics . Options
Logs * logs . Options
2019-01-12 04:58:27 +00:00
AllowPrivileged bool
EnableLogsHandler bool
EventTTL time . Duration
KubeletConfig kubeletclient . KubeletClientConfig
KubernetesServiceNodePort int
MaxConnectionBytesPerSec int64
2019-09-27 21:51:53 +00:00
// ServiceClusterIPRange is mapped to input provided by user
ServiceClusterIPRanges string
2020-12-01 01:06:26 +00:00
// PrimaryServiceClusterIPRange and SecondaryServiceClusterIPRange are the results
2019-09-27 21:51:53 +00:00
// of parsing ServiceClusterIPRange into actual values
PrimaryServiceClusterIPRange net . IPNet
SecondaryServiceClusterIPRange net . IPNet
ServiceNodePortRange utilnet . PortRange
SSHKeyfile string
SSHUser string
2019-01-12 04:58:27 +00:00
ProxyClientCertFile string
ProxyClientKeyFile string
EnableAggregatorRouting bool
MasterCount int
EndpointReconcilerType string
2020-12-01 01:06:26 +00:00
IdentityLeaseDurationSeconds int
IdentityLeaseRenewIntervalSeconds int
2019-01-12 04:58:27 +00:00
ServiceAccountSigningKeyFile string
ServiceAccountIssuer serviceaccount . TokenGenerator
ServiceAccountTokenMaxExpiration time . Duration
2019-12-12 01:27:03 +00:00
ShowHiddenMetricsForVersion string
2019-01-12 04:58:27 +00:00
}
// NewServerRunOptions creates a new ServerRunOptions object with default parameters
func NewServerRunOptions ( ) * ServerRunOptions {
s := ServerRunOptions {
GenericServerRunOptions : genericoptions . NewServerRunOptions ( ) ,
Etcd : genericoptions . NewEtcdOptions ( storagebackend . NewDefaultConfig ( kubeoptions . DefaultEtcdPathPrefix , nil ) ) ,
SecureServing : kubeoptions . NewSecureServingOptions ( ) ,
Audit : genericoptions . NewAuditOptions ( ) ,
Features : genericoptions . NewFeatureOptions ( ) ,
Admission : kubeoptions . NewAdmissionOptions ( ) ,
Authentication : kubeoptions . NewBuiltInAuthenticationOptions ( ) . WithAll ( ) ,
Authorization : kubeoptions . NewBuiltInAuthorizationOptions ( ) ,
CloudProvider : kubeoptions . NewCloudProviderOptions ( ) ,
APIEnablement : genericoptions . NewAPIEnablementOptions ( ) ,
2019-09-27 21:51:53 +00:00
EgressSelector : genericoptions . NewEgressSelectorOptions ( ) ,
2020-08-10 17:43:49 +00:00
Metrics : metrics . NewOptions ( ) ,
Logs : logs . NewOptions ( ) ,
2019-01-12 04:58:27 +00:00
2020-12-01 01:06:26 +00:00
EnableLogsHandler : true ,
EventTTL : 1 * time . Hour ,
MasterCount : 1 ,
EndpointReconcilerType : string ( reconcilers . LeaseEndpointReconcilerType ) ,
IdentityLeaseDurationSeconds : 3600 ,
IdentityLeaseRenewIntervalSeconds : 10 ,
2019-01-12 04:58:27 +00:00
KubeletConfig : kubeletclient . KubeletClientConfig {
Port : ports . KubeletPort ,
ReadOnlyPort : ports . KubeletReadOnlyPort ,
PreferredAddressTypes : [ ] string {
// --override-hostname
string ( api . NodeHostName ) ,
// internal, preferring DNS if reported
string ( api . NodeInternalDNS ) ,
string ( api . NodeInternalIP ) ,
// external, preferring DNS if reported
string ( api . NodeExternalDNS ) ,
string ( api . NodeExternalIP ) ,
} ,
HTTPTimeout : time . Duration ( 5 ) * time . Second ,
} ,
ServiceNodePortRange : kubeoptions . DefaultServiceNodePortRange ,
}
// Overwrite the default for storage data format.
2019-08-30 18:33:25 +00:00
s . Etcd . DefaultStorageMediaType = "application/vnd.kubernetes.protobuf"
2019-01-12 04:58:27 +00:00
return & s
}
2020-12-01 01:06:26 +00:00
// TODO: remove these insecure flags in v1.24
func addDummyInsecureFlags ( fs * pflag . FlagSet ) {
var (
bindAddr = net . IPv4 ( 127 , 0 , 0 , 1 )
bindPort int
)
for _ , name := range [ ] string { "insecure-bind-address" , "address" } {
fs . IPVar ( & bindAddr , name , bindAddr , "" +
2021-03-18 22:40:29 +00:00
"The IP address on which to serve the insecure port (set to 0.0.0.0 or :: for listening in all interfaces and IP families)." )
2020-12-01 01:06:26 +00:00
fs . MarkDeprecated ( name , "This flag has no effect now and will be removed in v1.24." )
}
for _ , name := range InsecurePortFlags {
fs . IntVar ( & bindPort , name , bindPort , "" +
"The port on which to serve unsecured, unauthenticated access." )
fs . MarkDeprecated ( name , "This flag has no effect now and will be removed in v1.24." )
}
}
2019-01-12 04:58:27 +00:00
// Flags returns flags for a specific APIServer by section name
2019-04-07 17:07:55 +00:00
func ( s * ServerRunOptions ) Flags ( ) ( fss cliflag . NamedFlagSets ) {
2019-01-12 04:58:27 +00:00
// Add the generic flags.
s . GenericServerRunOptions . AddUniversalFlags ( fss . FlagSet ( "generic" ) )
s . Etcd . AddFlags ( fss . FlagSet ( "etcd" ) )
s . SecureServing . AddFlags ( fss . FlagSet ( "secure serving" ) )
2020-12-01 01:06:26 +00:00
addDummyInsecureFlags ( fss . FlagSet ( "insecure serving" ) )
2019-01-12 04:58:27 +00:00
s . Audit . AddFlags ( fss . FlagSet ( "auditing" ) )
s . Features . AddFlags ( fss . FlagSet ( "features" ) )
s . Authentication . AddFlags ( fss . FlagSet ( "authentication" ) )
s . Authorization . AddFlags ( fss . FlagSet ( "authorization" ) )
s . CloudProvider . AddFlags ( fss . FlagSet ( "cloud provider" ) )
2019-12-12 01:27:03 +00:00
s . APIEnablement . AddFlags ( fss . FlagSet ( "API enablement" ) )
2019-09-27 21:51:53 +00:00
s . EgressSelector . AddFlags ( fss . FlagSet ( "egress selector" ) )
2019-01-12 04:58:27 +00:00
s . Admission . AddFlags ( fss . FlagSet ( "admission" ) )
2020-08-10 17:43:49 +00:00
s . Metrics . AddFlags ( fss . FlagSet ( "metrics" ) )
s . Logs . AddFlags ( fss . FlagSet ( "logs" ) )
2019-12-12 01:27:03 +00:00
2019-01-12 04:58:27 +00:00
// Note: the weird ""+ in below lines seems to be the only way to get gofmt to
// arrange these text blocks sensibly. Grrr.
fs := fss . FlagSet ( "misc" )
fs . DurationVar ( & s . EventTTL , "event-ttl" , s . EventTTL ,
"Amount of time to retain events." )
fs . BoolVar ( & s . AllowPrivileged , "allow-privileged" , s . AllowPrivileged ,
"If true, allow privileged containers. [default=false]" )
fs . BoolVar ( & s . EnableLogsHandler , "enable-logs-handler" , s . EnableLogsHandler ,
"If true, install a /logs handler for the apiserver logs." )
2019-08-30 18:33:25 +00:00
fs . MarkDeprecated ( "enable-logs-handler" , "This flag will be removed in v1.19" )
2019-01-12 04:58:27 +00:00
// Deprecated in release 1.9
fs . StringVar ( & s . SSHUser , "ssh-user" , s . SSHUser ,
"If non-empty, use secure SSH proxy to the nodes, using this user name" )
fs . MarkDeprecated ( "ssh-user" , "This flag will be removed in a future version." )
// Deprecated in release 1.9
fs . StringVar ( & s . SSHKeyfile , "ssh-keyfile" , s . SSHKeyfile ,
"If non-empty, use secure SSH proxy to the nodes, using this user keyfile" )
fs . MarkDeprecated ( "ssh-keyfile" , "This flag will be removed in a future version." )
fs . Int64Var ( & s . MaxConnectionBytesPerSec , "max-connection-bytes-per-sec" , s . MaxConnectionBytesPerSec , "" +
"If non-zero, throttle each user connection to this number of bytes/sec. " +
"Currently only applies to long-running requests." )
fs . IntVar ( & s . MasterCount , "apiserver-count" , s . MasterCount ,
"The number of apiservers running in the cluster, must be a positive number. (In use when --endpoint-reconciler-type=master-count is enabled.)" )
fs . StringVar ( & s . EndpointReconcilerType , "endpoint-reconciler-type" , string ( s . EndpointReconcilerType ) ,
"Use an endpoint reconciler (" + strings . Join ( reconcilers . AllTypes . Names ( ) , ", " ) + ")" )
2020-12-01 01:06:26 +00:00
fs . IntVar ( & s . IdentityLeaseDurationSeconds , "identity-lease-duration-seconds" , s . IdentityLeaseDurationSeconds ,
"The duration of kube-apiserver lease in seconds, must be a positive number. (In use when the APIServerIdentity feature gate is enabled.)" )
fs . IntVar ( & s . IdentityLeaseRenewIntervalSeconds , "identity-lease-renew-interval-seconds" , s . IdentityLeaseRenewIntervalSeconds ,
"The interval of kube-apiserver renewing its lease in seconds, must be a positive number. (In use when the APIServerIdentity feature gate is enabled.)" )
2019-01-12 04:58:27 +00:00
// See #14282 for details on how to test/try this option out.
// TODO: remove this comment once this option is tested in CI.
fs . IntVar ( & s . KubernetesServiceNodePort , "kubernetes-service-node-port" , s . KubernetesServiceNodePort , "" +
"If non-zero, the Kubernetes master service (which apiserver creates/maintains) will be " +
"of type NodePort, using this as the value of the port. If zero, the Kubernetes master " +
"service will be of type ClusterIP." )
2019-09-27 21:51:53 +00:00
fs . StringVar ( & s . ServiceClusterIPRanges , "service-cluster-ip-range" , s . ServiceClusterIPRanges , "" +
2019-01-12 04:58:27 +00:00
"A CIDR notation IP range from which to assign service cluster IPs. This must not " +
2021-03-18 22:40:29 +00:00
"overlap with any IP ranges assigned to nodes or pods. Max of two dual-stack CIDRs is allowed." )
2019-01-12 04:58:27 +00:00
fs . Var ( & s . ServiceNodePortRange , "service-node-port-range" , "" +
"A port range to reserve for services with NodePort visibility. " +
"Example: '30000-32767'. Inclusive at both ends of the range." )
// Kubelet related flags:
2020-08-10 17:43:49 +00:00
kubeletHTTPS := true
fs . BoolVar ( & kubeletHTTPS , "kubelet-https" , kubeletHTTPS , "Use https for kubelet connections." )
fs . MarkDeprecated ( "kubelet-https" , "API Server connections to kubelets always use https. This flag will be removed in 1.22." )
2019-01-12 04:58:27 +00:00
fs . StringSliceVar ( & s . KubeletConfig . PreferredAddressTypes , "kubelet-preferred-address-types" , s . KubeletConfig . PreferredAddressTypes ,
"List of the preferred NodeAddressTypes to use for kubelet connections." )
fs . UintVar ( & s . KubeletConfig . Port , "kubelet-port" , s . KubeletConfig . Port ,
"DEPRECATED: kubelet port." )
fs . MarkDeprecated ( "kubelet-port" , "kubelet-port is deprecated and will be removed." )
fs . UintVar ( & s . KubeletConfig . ReadOnlyPort , "kubelet-read-only-port" , s . KubeletConfig . ReadOnlyPort ,
2019-09-27 21:51:53 +00:00
"DEPRECATED: kubelet read only port." )
fs . MarkDeprecated ( "kubelet-read-only-port" , "kubelet-read-only-port is deprecated and will be removed." )
2019-01-12 04:58:27 +00:00
fs . DurationVar ( & s . KubeletConfig . HTTPTimeout , "kubelet-timeout" , s . KubeletConfig . HTTPTimeout ,
"Timeout for kubelet operations." )
fs . StringVar ( & s . KubeletConfig . CertFile , "kubelet-client-certificate" , s . KubeletConfig . CertFile ,
"Path to a client cert file for TLS." )
fs . StringVar ( & s . KubeletConfig . KeyFile , "kubelet-client-key" , s . KubeletConfig . KeyFile ,
"Path to a client key file for TLS." )
fs . StringVar ( & s . KubeletConfig . CAFile , "kubelet-certificate-authority" , s . KubeletConfig . CAFile ,
"Path to a cert file for the certificate authority." )
fs . StringVar ( & s . ProxyClientCertFile , "proxy-client-cert-file" , s . ProxyClientCertFile , "" +
"Client certificate used to prove the identity of the aggregator or kube-apiserver " +
"when it must call out during a request. This includes proxying requests to a user " +
"api-server and calling out to webhook admission plugins. It is expected that this " +
"cert includes a signature from the CA in the --requestheader-client-ca-file flag. " +
"That CA is published in the 'extension-apiserver-authentication' configmap in " +
"the kube-system namespace. Components receiving calls from kube-aggregator should " +
"use that CA to perform their half of the mutual TLS verification." )
fs . StringVar ( & s . ProxyClientKeyFile , "proxy-client-key-file" , s . ProxyClientKeyFile , "" +
"Private key for the client certificate used to prove the identity of the aggregator or kube-apiserver " +
"when it must call out during a request. This includes proxying requests to a user " +
"api-server and calling out to webhook admission plugins." )
fs . BoolVar ( & s . EnableAggregatorRouting , "enable-aggregator-routing" , s . EnableAggregatorRouting ,
"Turns on aggregator routing requests to endpoints IP rather than cluster IP." )
fs . StringVar ( & s . ServiceAccountSigningKeyFile , "service-account-signing-key-file" , s . ServiceAccountSigningKeyFile , "" +
2020-12-01 01:06:26 +00:00
"Path to the file that contains the current private key of the service account token issuer. The issuer will sign issued ID tokens with this private key." )
2019-01-12 04:58:27 +00:00
return fss
}