options.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. /*
  2. Copyright 2014 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. // Package options contains flags and options for initializing an apiserver
  14. package options
  15. import (
  16. "net"
  17. "strings"
  18. "time"
  19. utilnet "k8s.io/apimachinery/pkg/util/net"
  20. genericoptions "k8s.io/apiserver/pkg/server/options"
  21. "k8s.io/apiserver/pkg/storage/storagebackend"
  22. cliflag "k8s.io/component-base/cli/flag"
  23. api "k8s.io/kubernetes/pkg/apis/core"
  24. _ "k8s.io/kubernetes/pkg/features" // add the kubernetes feature gates
  25. kubeoptions "k8s.io/kubernetes/pkg/kubeapiserver/options"
  26. kubeletclient "k8s.io/kubernetes/pkg/kubelet/client"
  27. "k8s.io/kubernetes/pkg/master/ports"
  28. "k8s.io/kubernetes/pkg/master/reconcilers"
  29. "k8s.io/kubernetes/pkg/serviceaccount"
  30. )
  31. // ServerRunOptions runs a kubernetes api server.
  32. type ServerRunOptions struct {
  33. GenericServerRunOptions *genericoptions.ServerRunOptions
  34. Etcd *genericoptions.EtcdOptions
  35. SecureServing *genericoptions.SecureServingOptionsWithLoopback
  36. InsecureServing *genericoptions.DeprecatedInsecureServingOptionsWithLoopback
  37. Audit *genericoptions.AuditOptions
  38. Features *genericoptions.FeatureOptions
  39. Admission *kubeoptions.AdmissionOptions
  40. Authentication *kubeoptions.BuiltInAuthenticationOptions
  41. Authorization *kubeoptions.BuiltInAuthorizationOptions
  42. CloudProvider *kubeoptions.CloudProviderOptions
  43. APIEnablement *genericoptions.APIEnablementOptions
  44. AllowPrivileged bool
  45. EnableLogsHandler bool
  46. EventTTL time.Duration
  47. KubeletConfig kubeletclient.KubeletClientConfig
  48. KubernetesServiceNodePort int
  49. MaxConnectionBytesPerSec int64
  50. ServiceClusterIPRange net.IPNet // TODO: make this a list
  51. ServiceNodePortRange utilnet.PortRange
  52. SSHKeyfile string
  53. SSHUser string
  54. ProxyClientCertFile string
  55. ProxyClientKeyFile string
  56. EnableAggregatorRouting bool
  57. MasterCount int
  58. EndpointReconcilerType string
  59. ServiceAccountSigningKeyFile string
  60. ServiceAccountIssuer serviceaccount.TokenGenerator
  61. ServiceAccountTokenMaxExpiration time.Duration
  62. }
  63. // NewServerRunOptions creates a new ServerRunOptions object with default parameters
  64. func NewServerRunOptions() *ServerRunOptions {
  65. s := ServerRunOptions{
  66. GenericServerRunOptions: genericoptions.NewServerRunOptions(),
  67. Etcd: genericoptions.NewEtcdOptions(storagebackend.NewDefaultConfig(kubeoptions.DefaultEtcdPathPrefix, nil)),
  68. SecureServing: kubeoptions.NewSecureServingOptions(),
  69. InsecureServing: kubeoptions.NewInsecureServingOptions(),
  70. Audit: genericoptions.NewAuditOptions(),
  71. Features: genericoptions.NewFeatureOptions(),
  72. Admission: kubeoptions.NewAdmissionOptions(),
  73. Authentication: kubeoptions.NewBuiltInAuthenticationOptions().WithAll(),
  74. Authorization: kubeoptions.NewBuiltInAuthorizationOptions(),
  75. CloudProvider: kubeoptions.NewCloudProviderOptions(),
  76. APIEnablement: genericoptions.NewAPIEnablementOptions(),
  77. EnableLogsHandler: true,
  78. EventTTL: 1 * time.Hour,
  79. MasterCount: 1,
  80. EndpointReconcilerType: string(reconcilers.LeaseEndpointReconcilerType),
  81. KubeletConfig: kubeletclient.KubeletClientConfig{
  82. Port: ports.KubeletPort,
  83. ReadOnlyPort: ports.KubeletReadOnlyPort,
  84. PreferredAddressTypes: []string{
  85. // --override-hostname
  86. string(api.NodeHostName),
  87. // internal, preferring DNS if reported
  88. string(api.NodeInternalDNS),
  89. string(api.NodeInternalIP),
  90. // external, preferring DNS if reported
  91. string(api.NodeExternalDNS),
  92. string(api.NodeExternalIP),
  93. },
  94. EnableHttps: true,
  95. HTTPTimeout: time.Duration(5) * time.Second,
  96. },
  97. ServiceNodePortRange: kubeoptions.DefaultServiceNodePortRange,
  98. }
  99. s.ServiceClusterIPRange = kubeoptions.DefaultServiceIPCIDR
  100. // Overwrite the default for storage data format.
  101. s.Etcd.DefaultStorageMediaType = "application/vnd.kubernetes.protobuf"
  102. return &s
  103. }
  104. // Flags returns flags for a specific APIServer by section name
  105. func (s *ServerRunOptions) Flags() (fss cliflag.NamedFlagSets) {
  106. // Add the generic flags.
  107. s.GenericServerRunOptions.AddUniversalFlags(fss.FlagSet("generic"))
  108. s.Etcd.AddFlags(fss.FlagSet("etcd"))
  109. s.SecureServing.AddFlags(fss.FlagSet("secure serving"))
  110. s.InsecureServing.AddFlags(fss.FlagSet("insecure serving"))
  111. s.InsecureServing.AddUnqualifiedFlags(fss.FlagSet("insecure serving")) // TODO: remove it until kops stops using `--address`
  112. s.Audit.AddFlags(fss.FlagSet("auditing"))
  113. s.Features.AddFlags(fss.FlagSet("features"))
  114. s.Authentication.AddFlags(fss.FlagSet("authentication"))
  115. s.Authorization.AddFlags(fss.FlagSet("authorization"))
  116. s.CloudProvider.AddFlags(fss.FlagSet("cloud provider"))
  117. s.APIEnablement.AddFlags(fss.FlagSet("api enablement"))
  118. s.Admission.AddFlags(fss.FlagSet("admission"))
  119. // Note: the weird ""+ in below lines seems to be the only way to get gofmt to
  120. // arrange these text blocks sensibly. Grrr.
  121. fs := fss.FlagSet("misc")
  122. fs.DurationVar(&s.EventTTL, "event-ttl", s.EventTTL,
  123. "Amount of time to retain events.")
  124. fs.BoolVar(&s.AllowPrivileged, "allow-privileged", s.AllowPrivileged,
  125. "If true, allow privileged containers. [default=false]")
  126. fs.BoolVar(&s.EnableLogsHandler, "enable-logs-handler", s.EnableLogsHandler,
  127. "If true, install a /logs handler for the apiserver logs.")
  128. fs.MarkDeprecated("enable-logs-handler", "This flag will be removed in v1.19")
  129. // Deprecated in release 1.9
  130. fs.StringVar(&s.SSHUser, "ssh-user", s.SSHUser,
  131. "If non-empty, use secure SSH proxy to the nodes, using this user name")
  132. fs.MarkDeprecated("ssh-user", "This flag will be removed in a future version.")
  133. // Deprecated in release 1.9
  134. fs.StringVar(&s.SSHKeyfile, "ssh-keyfile", s.SSHKeyfile,
  135. "If non-empty, use secure SSH proxy to the nodes, using this user keyfile")
  136. fs.MarkDeprecated("ssh-keyfile", "This flag will be removed in a future version.")
  137. fs.Int64Var(&s.MaxConnectionBytesPerSec, "max-connection-bytes-per-sec", s.MaxConnectionBytesPerSec, ""+
  138. "If non-zero, throttle each user connection to this number of bytes/sec. "+
  139. "Currently only applies to long-running requests.")
  140. fs.IntVar(&s.MasterCount, "apiserver-count", s.MasterCount,
  141. "The number of apiservers running in the cluster, must be a positive number. (In use when --endpoint-reconciler-type=master-count is enabled.)")
  142. fs.StringVar(&s.EndpointReconcilerType, "endpoint-reconciler-type", string(s.EndpointReconcilerType),
  143. "Use an endpoint reconciler ("+strings.Join(reconcilers.AllTypes.Names(), ", ")+")")
  144. // See #14282 for details on how to test/try this option out.
  145. // TODO: remove this comment once this option is tested in CI.
  146. fs.IntVar(&s.KubernetesServiceNodePort, "kubernetes-service-node-port", s.KubernetesServiceNodePort, ""+
  147. "If non-zero, the Kubernetes master service (which apiserver creates/maintains) will be "+
  148. "of type NodePort, using this as the value of the port. If zero, the Kubernetes master "+
  149. "service will be of type ClusterIP.")
  150. fs.IPNetVar(&s.ServiceClusterIPRange, "service-cluster-ip-range", s.ServiceClusterIPRange, ""+
  151. "A CIDR notation IP range from which to assign service cluster IPs. This must not "+
  152. "overlap with any IP ranges assigned to nodes for pods.")
  153. fs.Var(&s.ServiceNodePortRange, "service-node-port-range", ""+
  154. "A port range to reserve for services with NodePort visibility. "+
  155. "Example: '30000-32767'. Inclusive at both ends of the range.")
  156. // Kubelet related flags:
  157. fs.BoolVar(&s.KubeletConfig.EnableHttps, "kubelet-https", s.KubeletConfig.EnableHttps,
  158. "Use https for kubelet connections.")
  159. fs.StringSliceVar(&s.KubeletConfig.PreferredAddressTypes, "kubelet-preferred-address-types", s.KubeletConfig.PreferredAddressTypes,
  160. "List of the preferred NodeAddressTypes to use for kubelet connections.")
  161. fs.UintVar(&s.KubeletConfig.Port, "kubelet-port", s.KubeletConfig.Port,
  162. "DEPRECATED: kubelet port.")
  163. fs.MarkDeprecated("kubelet-port", "kubelet-port is deprecated and will be removed.")
  164. fs.UintVar(&s.KubeletConfig.ReadOnlyPort, "kubelet-read-only-port", s.KubeletConfig.ReadOnlyPort,
  165. "DEPRECATED: kubelet port.")
  166. fs.DurationVar(&s.KubeletConfig.HTTPTimeout, "kubelet-timeout", s.KubeletConfig.HTTPTimeout,
  167. "Timeout for kubelet operations.")
  168. fs.StringVar(&s.KubeletConfig.CertFile, "kubelet-client-certificate", s.KubeletConfig.CertFile,
  169. "Path to a client cert file for TLS.")
  170. fs.StringVar(&s.KubeletConfig.KeyFile, "kubelet-client-key", s.KubeletConfig.KeyFile,
  171. "Path to a client key file for TLS.")
  172. fs.StringVar(&s.KubeletConfig.CAFile, "kubelet-certificate-authority", s.KubeletConfig.CAFile,
  173. "Path to a cert file for the certificate authority.")
  174. fs.StringVar(&s.ProxyClientCertFile, "proxy-client-cert-file", s.ProxyClientCertFile, ""+
  175. "Client certificate used to prove the identity of the aggregator or kube-apiserver "+
  176. "when it must call out during a request. This includes proxying requests to a user "+
  177. "api-server and calling out to webhook admission plugins. It is expected that this "+
  178. "cert includes a signature from the CA in the --requestheader-client-ca-file flag. "+
  179. "That CA is published in the 'extension-apiserver-authentication' configmap in "+
  180. "the kube-system namespace. Components receiving calls from kube-aggregator should "+
  181. "use that CA to perform their half of the mutual TLS verification.")
  182. fs.StringVar(&s.ProxyClientKeyFile, "proxy-client-key-file", s.ProxyClientKeyFile, ""+
  183. "Private key for the client certificate used to prove the identity of the aggregator or kube-apiserver "+
  184. "when it must call out during a request. This includes proxying requests to a user "+
  185. "api-server and calling out to webhook admission plugins.")
  186. fs.BoolVar(&s.EnableAggregatorRouting, "enable-aggregator-routing", s.EnableAggregatorRouting,
  187. "Turns on aggregator routing requests to endpoints IP rather than cluster IP.")
  188. fs.StringVar(&s.ServiceAccountSigningKeyFile, "service-account-signing-key-file", s.ServiceAccountSigningKeyFile, ""+
  189. "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. (Requires the 'TokenRequest' feature gate.)")
  190. return fss
  191. }