...

Source file src/k8s.io/kubernetes/cmd/kube-apiserver/app/options/options.go

Documentation: k8s.io/kubernetes/cmd/kube-apiserver/app/options

     1  /*
     2  Copyright 2014 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  // Package options contains flags and options for initializing an apiserver
    18  package options
    19  
    20  import (
    21  	"net"
    22  	"strings"
    23  	"time"
    24  
    25  	utilnet "k8s.io/apimachinery/pkg/util/net"
    26  	cliflag "k8s.io/component-base/cli/flag"
    27  
    28  	api "k8s.io/kubernetes/pkg/apis/core"
    29  	"k8s.io/kubernetes/pkg/cluster/ports"
    30  	controlplaneapiserver "k8s.io/kubernetes/pkg/controlplane/apiserver/options"
    31  	"k8s.io/kubernetes/pkg/controlplane/reconcilers"
    32  	_ "k8s.io/kubernetes/pkg/features" // add the kubernetes feature gates
    33  	kubeoptions "k8s.io/kubernetes/pkg/kubeapiserver/options"
    34  	kubeletclient "k8s.io/kubernetes/pkg/kubelet/client"
    35  )
    36  
    37  // ServerRunOptions runs a kubernetes api server.
    38  type ServerRunOptions struct {
    39  	*controlplaneapiserver.Options // embedded to avoid noise in existing consumers
    40  	CloudProvider                  *kubeoptions.CloudProviderOptions
    41  
    42  	Extra
    43  }
    44  
    45  type Extra struct {
    46  	AllowPrivileged           bool
    47  	KubeletConfig             kubeletclient.KubeletClientConfig
    48  	KubernetesServiceNodePort int
    49  	// ServiceClusterIPRange is mapped to input provided by user
    50  	ServiceClusterIPRanges string
    51  	// PrimaryServiceClusterIPRange and SecondaryServiceClusterIPRange are the results
    52  	// of parsing ServiceClusterIPRange into actual values
    53  	PrimaryServiceClusterIPRange   net.IPNet
    54  	SecondaryServiceClusterIPRange net.IPNet
    55  	// APIServerServiceIP is the first valid IP from PrimaryServiceClusterIPRange
    56  	APIServerServiceIP net.IP
    57  
    58  	ServiceNodePortRange utilnet.PortRange
    59  
    60  	EndpointReconcilerType string
    61  
    62  	MasterCount int
    63  }
    64  
    65  // NewServerRunOptions creates a new ServerRunOptions object with default parameters
    66  func NewServerRunOptions() *ServerRunOptions {
    67  	s := ServerRunOptions{
    68  		Options:       controlplaneapiserver.NewOptions(),
    69  		CloudProvider: kubeoptions.NewCloudProviderOptions(),
    70  
    71  		Extra: Extra{
    72  			EndpointReconcilerType: string(reconcilers.LeaseEndpointReconcilerType),
    73  			KubeletConfig: kubeletclient.KubeletClientConfig{
    74  				Port:         ports.KubeletPort,
    75  				ReadOnlyPort: ports.KubeletReadOnlyPort,
    76  				PreferredAddressTypes: []string{
    77  					// --override-hostname
    78  					string(api.NodeHostName),
    79  
    80  					// internal, preferring DNS if reported
    81  					string(api.NodeInternalDNS),
    82  					string(api.NodeInternalIP),
    83  
    84  					// external, preferring DNS if reported
    85  					string(api.NodeExternalDNS),
    86  					string(api.NodeExternalIP),
    87  				},
    88  				HTTPTimeout: time.Duration(5) * time.Second,
    89  			},
    90  			ServiceNodePortRange: kubeoptions.DefaultServiceNodePortRange,
    91  			MasterCount:          1,
    92  		},
    93  	}
    94  
    95  	return &s
    96  }
    97  
    98  // Flags returns flags for a specific APIServer by section name
    99  func (s *ServerRunOptions) Flags() (fss cliflag.NamedFlagSets) {
   100  	s.Options.AddFlags(&fss)
   101  	s.CloudProvider.AddFlags(fss.FlagSet("cloud provider"))
   102  
   103  	// Note: the weird ""+ in below lines seems to be the only way to get gofmt to
   104  	// arrange these text blocks sensibly. Grrr.
   105  	fs := fss.FlagSet("misc")
   106  
   107  	fs.BoolVar(&s.AllowPrivileged, "allow-privileged", s.AllowPrivileged,
   108  		"If true, allow privileged containers. [default=false]")
   109  
   110  	fs.StringVar(&s.EndpointReconcilerType, "endpoint-reconciler-type", s.EndpointReconcilerType,
   111  		"Use an endpoint reconciler ("+strings.Join(reconcilers.AllTypes.Names(), ", ")+") master-count is deprecated, and will be removed in a future version.")
   112  
   113  	// See #14282 for details on how to test/try this option out.
   114  	// TODO: remove this comment once this option is tested in CI.
   115  	fs.IntVar(&s.KubernetesServiceNodePort, "kubernetes-service-node-port", s.KubernetesServiceNodePort, ""+
   116  		"If non-zero, the Kubernetes master service (which apiserver creates/maintains) will be "+
   117  		"of type NodePort, using this as the value of the port. If zero, the Kubernetes master "+
   118  		"service will be of type ClusterIP.")
   119  
   120  	fs.StringVar(&s.ServiceClusterIPRanges, "service-cluster-ip-range", s.ServiceClusterIPRanges, ""+
   121  		"A CIDR notation IP range from which to assign service cluster IPs. This must not "+
   122  		"overlap with any IP ranges assigned to nodes or pods. Max of two dual-stack CIDRs is allowed.")
   123  
   124  	fs.Var(&s.ServiceNodePortRange, "service-node-port-range", ""+
   125  		"A port range to reserve for services with NodePort visibility.  This must not overlap with the ephemeral port range on nodes.  "+
   126  		"Example: '30000-32767'. Inclusive at both ends of the range.")
   127  
   128  	// Kubelet related flags:
   129  	fs.StringSliceVar(&s.KubeletConfig.PreferredAddressTypes, "kubelet-preferred-address-types", s.KubeletConfig.PreferredAddressTypes,
   130  		"List of the preferred NodeAddressTypes to use for kubelet connections.")
   131  
   132  	fs.UintVar(&s.KubeletConfig.Port, "kubelet-port", s.KubeletConfig.Port,
   133  		"DEPRECATED: kubelet port.")
   134  	fs.MarkDeprecated("kubelet-port", "kubelet-port is deprecated and will be removed.")
   135  
   136  	fs.UintVar(&s.KubeletConfig.ReadOnlyPort, "kubelet-read-only-port", s.KubeletConfig.ReadOnlyPort,
   137  		"DEPRECATED: kubelet read only port.")
   138  	fs.MarkDeprecated("kubelet-read-only-port", "kubelet-read-only-port is deprecated and will be removed.")
   139  
   140  	fs.DurationVar(&s.KubeletConfig.HTTPTimeout, "kubelet-timeout", s.KubeletConfig.HTTPTimeout,
   141  		"Timeout for kubelet operations.")
   142  
   143  	fs.StringVar(&s.KubeletConfig.TLSClientConfig.CertFile, "kubelet-client-certificate", s.KubeletConfig.TLSClientConfig.CertFile,
   144  		"Path to a client cert file for TLS.")
   145  
   146  	fs.StringVar(&s.KubeletConfig.TLSClientConfig.KeyFile, "kubelet-client-key", s.KubeletConfig.TLSClientConfig.KeyFile,
   147  		"Path to a client key file for TLS.")
   148  
   149  	fs.StringVar(&s.KubeletConfig.TLSClientConfig.CAFile, "kubelet-certificate-authority", s.KubeletConfig.TLSClientConfig.CAFile,
   150  		"Path to a cert file for the certificate authority.")
   151  
   152  	fs.IntVar(&s.MasterCount, "apiserver-count", s.MasterCount,
   153  		"The number of apiservers running in the cluster, must be a positive number. (In use when --endpoint-reconciler-type=master-count is enabled.)")
   154  	fs.MarkDeprecated("apiserver-count", "apiserver-count is deprecated and will be removed in a future version.")
   155  
   156  	return fss
   157  }
   158  

View as plain text