kubelet Startup - Command Line Initialization

Overview

The kubelet command-line has 177 parameters, making it the Kubernetes component with the most configuration options.

Kubelet’s options can be categorized into three types: kubeletFlags (those that cannot be changed after startup and can only be configured via the command line, such as IP addresses and paths), kubeletConfiguration (those that can be modified after startup and can be set via the command line, configuration files, or dynamic Kubelet config - configmap; configuring via the command line is deprecated, and some options can only be set through configuration files, e.g., NodeStatusReportFrequency), and globalFlags (those that can only be configured via the command line, such as log levels, log paths, and versions).

How does kubelet start, initialize, and recognize so many options? This article focuses on the command-line initialization of kubelet. The runtime process of various components will be analyzed in subsequent articles.

This article is based on Kubernetes version 1.18.6. Please visit the source code reading repository for more details.

The entry file for kubelet is cmd\kubelet\kubelet.go. The main process includes:

  1. Initializing the random factor.
  2. Creating a Cobra Command.
  3. Initializing logging.
  4. Executing the Cobra Command.

During this stage, command-line options are defined, default values are set, various fields of the command are defined, command help functions are created, and command usage functions are defined.

The main process includes:

  • Creating a flagset named “kubelet” to have a clean flagset (to avoid contamination by the CommandLine flagset) and setting the NormalizeFunc of the flagset to convert flag names containing underscores “_” to hyphens “-”. For example, –iptables-drop-bit and –iptables_drop_bit are considered the same.

  • Creating a “kubeletFlags” structure that contains default values for some initial options. Specific field-to-command line option mappings can be found in the “kubeletFlags options” section below. The “NewKubeletFlags()” function is defined in cmd\kubelet\app\options\options.go.

    go

    // NewKubeletFlags will create a new KubeletFlags with default values
    func NewKubeletFlags() *KubeletFlags {
        remoteRuntimeEndpoint := ""
        if runtime.GOOS == "linux" {
            remoteRuntimeEndpoint = "unix:///var/run/dockershim.sock"
        } else if runtime.GOOS == "windows" {
            remoteRuntimeEndpoint = "npipe:////./pipe/dockershim"
        }
    
        return &KubeletFlags{
            EnableServer:                        true,
            ContainerRuntimeOptions:             *NewContainerRuntimeOptions(),
            CertDirectory:                       "/var/lib/kubelet/pki",
            RootDirectory:                       defaultRootDir, // defaultRootDir为/var/lib/kubelet
            MasterServiceNamespace:              metav1.NamespaceDefault, // NamespaceDefault为default
            MaxContainerCount:                   -1,
            MaxPerPodContainerCount:             1,
            MinimumGCAge:                        metav1.Duration{Duration: 0},
            NonMasqueradeCIDR:                   "10.0.0.0/8",
            RegisterSchedulable:                 true,
            ExperimentalKernelMemcgNotification: false,
            RemoteRuntimeEndpoint:               remoteRuntimeEndpoint,
            NodeLabels:                          make(map[string]string),
            VolumePluginDir:                     "/usr/libexec/kubernetes/kubelet-plugins/volume/exec/",
            RegisterNode:                        true,
            SeccompProfileRoot:                  filepath.Join(defaultRootDir, "seccomp"),
            // prior to the introduction of this flag, there was a hardcoded cap of 50 images
            NodeStatusMaxImages:         50,
            EnableCAdvisorJSONEndpoints: false,
        }
    }

    NewContainerRuntimeOptions() is defined in cmd\kubelet\app\options\container_runtime.go

    go

    const (
        // When these values are updated, also update test/utils/image/manifest.go
        defaultPodSandboxImageName    = "k8s.gcr.io/pause"
        defaultPodSandboxImageVersion = "3.2"
    )
    
    var (
        defaultPodSandboxImage = defaultPodSandboxImageName +
            ":" + defaultPodSandboxImageVersion
    )
    
    // NewContainerRuntimeOptions will create a new ContainerRuntimeOptions with
    // default values.
    func NewContainerRuntimeOptions() *config.ContainerRuntimeOptions {
        dockerEndpoint := ""
        if runtime.GOOS != "windows" {
            dockerEndpoint = "unix:///var/run/docker.sock"
        }
    
        return &config.ContainerRuntimeOptions{
            ContainerRuntime:           kubetypes.DockerContainerRuntime, //DockerContainerRuntime为docker
            RedirectContainerStreaming: false,
            DockerEndpoint:             dockerEndpoint,
            DockershimRootDirectory:    "/var/lib/dockershim",
            PodSandboxImage:            defaultPodSandboxImage,
            ImagePullProgressDeadline:  metav1.Duration{Duration: 1 * time.Minute},
            ExperimentalDockershim:     false,
    
            //Alpha feature
            CNIBinDir:   "/opt/cni/bin",
            CNIConfDir:  "/etc/cni/net.d",
            CNICacheDir: "/var/lib/cni/cache",
        }
    }
  • Create a kubeletConfiguration to set default values for flag options related to kubeletConfiguration. This is done by creating a v1beta1 KubeletConfiguration and generating the default configuration through scheme.Default(), which is then converted into the internal KubeletConfiguration.

    Specific command-line options corresponding to fields can be found in the “kubeletConfigurationFlag options” section below.

    go

     KubeletConfiguration{
    		SyncFrequency: metav1.Duration{Duration: 1 * time.Minute},
    		FileCheckFrequency: metav1.Duration{Duration: 20 * time.Second},
    		HTTPCheckFrequency: metav1.Duration{Duration: 20 * time.Second},
    		Address: "0.0.0.0",
    		Port: 10250,
    		Authentication.Anonymous.Enabled: true, // by applyLegacyDefaults, by default false,
    		Authentication.Webhook.Enabled: false, // by applyLegacyDefaults, by default true,
    		Authentication.Webhook.CacheTTL: metav1.Duration{Duration: 2 * time.Minute},
    		Authorization.Mode: "AlwaysAllow", // by applyLegacyDefaults, by default "webhook",
    		Authorization.Webhook.CacheAuthorizedTTL: metav1.Duration{Duration: 5 * time.Minute},
    		Authorization.Webhook.CacheUnauthorizedTTL: metav1.Duration{Duration: 30 * time.Second},
    		ReadOnlyPort: 10255, // by applyLegacyDefaults,
    		RegistryPullQPS: 5,
    		RegistryBurst: 10,
    		EventRecordQPS: 5,
    		EventBurst: 10,
    		EnableDebuggingHandlers: true,
    		HealthzPort: 10248,
    		HealthzBindAddress: "127.0.0.1",
    		OOMScoreAdj: -999,
    		StreamingConnectionIdleTimeout: metav1.Duration{Duration: 4 * time.Hour},
    		NodeStatusReportFrequency: metav1.Duration{Duration: 5 * time.Minute},
    		NodeStatusUpdateFrequency: metav1.Duration{Duration: 10 * time.Second},
    		NodeLeaseDurationSeconds: 40,
    		ImageMinimumGCAge: metav1.Duration{Duration: 2 * time.Minute},
    		ImageGCHighThresholdPercent: 85,
    		ImageGCLowThresholdPercent: 80,
    		VolumeStatsAggPeriod: metav1.Duration{Duration: time.Minute},
    		CgroupsPerQOS: true,
    		CgroupDriver: "cgroupfs",
    		CPUManagerPolicy: "none",
    		CPUManagerReconcilePeriod: metav1.Duration{Duration: 10 * time.Second},
    		TopologyManagerPolicy: "none",
    		RuntimeRequestTimeout: metav1.Duration{Duration: 2 * time.Minute},
    		HairpinMode: "promiscuous-bridge",
    		MaxPods: 110,
    		PodPidsLimit: -1,
    		ResolverConfig: "/etc/resolv.conf",
    		CPUCFSQuota: true,
    		CPUCFSQuotaPeriod: metav1.Duration{Duration: 100 * time.Millisecond},
    		MaxOpenFiles: 1000000,
    		ContentType: "application/vnd.kubernetes.protobuf",
    		KubeAPIQPS: 5,
    		KubeAPIBurst: 10,
    		SerializeImagePulls: true,
    		EvictionHard: map[string]string{
    			"memory.available":  "100Mi",
    			"nodefs.available":  "10%",
    			"nodefs.inodesFree": "5%",
    			"imagefs.available": "15%",
    		},
    		EvictionPressureTransitionPeriod: metav1.Duration{Duration: 5 * time.Minute},
    		EnableControllerAttachDetach: true,
    		MakeIPTablesUtilChains: true,
    		IPTablesMasqueradeBit: 14,
    		IPTablesDropBit: 15,
    		FailSwapOn: true,
    		ContainerLogMaxSize: "10Mi",
    		ContainerLogMaxFiles: 5,
    		ConfigMapAndSecretChangeDetectionStrategy: "Watch",
    		EnforceNodeAllocatable: []string{"pods"},
    	}
  • Create a Cobra Command, defining fields such as Use, Long, DisableFlagParsing, and Run.

  • Add kubeletFlags options to the flagset.

  • Add kubeletConfigurationFlag options to the flagset.

  • Add globalFlags to the flagset, which includes options related to klog, verflag, CAdvisor, and logflush.

  • Set the help option.

  • Customize the command’s helpfunc and usageFunc.

You may notice that kubelet does not use Cobra’s command parsing, definition of helpfunc and usageFunc. Why is that?

This is because the globalFlags, which define flag options, are registered under pflag.Command - automatically registered through imported modules. By default, Cobra’s helpfunc and usageFunc, as well as execute, execute mergePersistentFlags(), which imports flags from pflag.Command. Due to historical reasons, some unnecessary options are also registered under pflag.Command and would be included. Therefore, a new flagset is created to parse the command manually and keep it clean.

The code comments also mention this, although not in detail.

go

	// keep cleanFlagSet separate, so Cobra doesn't pollute it with the global flags
	kubeletFlags.AddFlags(cleanFlagSet)
	options.AddKubeletConfigFlags(cleanFlagSet, kubeletConfig)
	options.AddGlobalFlags(cleanFlagSet)
	cleanFlagSet.BoolP("help", "h", false, fmt.Sprintf("help for %s", cmd.Name()))

	// ugly, but necessary, because Cobra's default UsageFunc and HelpFunc pollute the flagset with global flags
	const usageFmt = "Usage:\n  %s\n\nFlags:\n%s"
	cmd.SetUsageFunc(func(cmd *cobra.Command) error {
		fmt.Fprintf(cmd.OutOrStderr(), usageFmt, cmd.UseLine(), cleanFlagSet.FlagUsagesWrapped(2))
		return nil
	})
	cmd.SetHelpFunc(func(cmd *cobra.Command, args []string) {
		fmt.Fprintf(cmd.OutOrStdout(), "%s\n\n"+usageFmt, cmd.Long, cmd.UseLine(), cleanFlagSet.FlagUsagesWrapped(2))
	})


// AddGlobalFlags explicitly registers flags that libraries (glog, verflag, etc.) register
// against the global flagsets from "flag" and "github.com/spf13/pflag".
// We do this in order to prevent unwanted flags from leaking into the Kubelet's flagset.
func AddGlobalFlags(fs *pflag.FlagSet) {

The kubeletFlags options include options that cannot be changed while the kubelet is running, options that cannot be safely changed, and options that cannot be shared between different instances.

KubeletConfiguration defines options that can be shared between different instances.

// KubeletFlags contains configuration flags for the Kubelet.

// A configuration field should go in KubeletFlags instead of KubeletConfiguration if any of these are true:

// - its value will never, or cannot safely be changed during the lifetime of a node, or

// - its value cannot be safely shared between nodes at the same time (e.g. a hostname);

// KubeletConfiguration is intended to be shared between nodes.

categories分类var变量flagdefault默认值description
ContainerRuntimeOptionsContainerRuntime–container-runtimedockerThe container runtime to use. Possible values: ‘docker’, ‘remote’.
ContainerRuntimeOptionsRuntimeCgroups–runtime-cgroups""Optional absolute name of cgroups to create and run the runtime in.
ContainerRuntimeOptionsRedirectContainerStreaming–redirect-container-streamingfalseEnables container streaming redirect. If false, kubelet will proxy container streaming data between apiserver and container runtime; if true, kubelet will return an http redirect to apiserver, and apiserver will access container runtime directly. The proxy approach is more secure, but introduces some overhead. The redirect approach is more performant, but less secure because the connection between apiserver and container runtime may not be authenticated.
ContainerRuntimeOptions dockerExperimentalDockershim–experimental-dockershimfalseEnable dockershim only mode. In this mode, kubelet will only start dockershim without any other functionalities. This flag only serves test purpose, please do not use it unless you are conscious of what you are doing. [default=false]
ContainerRuntimeOptions dockerDockershimRootDirectory–experimental-dockershim-root-directory/var/lib/dockershimPath to the dockershim root directory.
ContainerRuntimeOptions dockerPodSandboxImage–pod-infra-container-imagek8s.gcr.io/pause:3.2The image whose network/ipc namespaces containers in each pod will use.
ContainerRuntimeOptions dockerDockerEndpoint–docker-endpointunix:///var/run/docker.sockUse this for the docker endpoint to communicate with.
ContainerRuntimeOptions dockerImagePullProgressDeadline.Duration–image-pull-progress-deadline1 * time.MinuteIf no pulling progress is made before this deadline, the image pulling will be cancelled.
ContainerRuntimeOptions dockerNetworkPluginName–network-plugin""<Warning: Alpha feature> The name of the network plugin to be invoked for various events in kubelet/pod lifecycle.
ContainerRuntimeOptions dockerCNIConfDir–cni-conf-dir/opt/cni/conf.d“<Warning: Alpha feature> The full path of the directory in which to search for CNI config files.
ContainerRuntimeOptions dockerCNIBinDir–cni-bin-dir/opt/cni/bin<Warning: Alpha feature> A comma-separated list of full paths of directories in which to search for CNI plugin binaries.
ContainerRuntimeOptions dockerCNICacheDir–cni-cache-dir/var/lib/cni/cache<Warning: Alpha feature> The full path of the directory in which CNI should store cache files.
ContainerRuntimeOptions dockerNetworkPluginMTU–network-plugin-mtu0<Warning: Alpha feature> The MTU to be passed to the network plugin, to override the default. Set to 0 to use the default 1460 MTU.
mainKubeletConfigFile–config"”The Kubelet will load its initial configuration from this file. The path may be absolute or relative; relative paths start at the Kubelet’s current working directory. Omit this flag to use the built-in default configuration values. Command-line flags override configuration from this file.
mainKubeConfig–kubeconfig""Path to a kubeconfig file, specifying how to connect to the API server. Providing –kubeconfig enables API server mode, omitting –kubeconfig enables standalone mode.
mainBootstrapKubeconfig–bootstrap-kubeconfig""Path to a kubeconfig file that will be used to get client certificate for kubelet. If the file specified by –kubeconfig does not exist, the bootstrap kubeconfig is used to request a client certificate from the API server. On success, a kubeconfig file referencing the generated client certificate and key is written to the path specified by –kubeconfig. The client certificate and key file will be stored in the directory pointed by –cert-dir.
mainReallyCrashForTesting–really-crash-for-testingfalseIf true, when panics occur crash. Intended for testing.
mainChaosChance–chaos-chance0If > 0.0, introduce random client errors and latency. Intended for testing.
mainRunOnce–runoncefalseIf true, exit after spawning pods from static pod files or remote urls. Exclusive with –enable-server
mainEnableServer–enable-servertrueEnable the Kubelet’s server
mainHostnameOverride–hostname-override""If non-empty, will use this string as identification instead of the actual hostname. If –cloud-provider is set, the cloud provider determines the name of the node (consult cloud provider documentation to determine if and how the hostname is used).
mainNodeIP–node-ip""IP address of the node. If set, kubelet will use this IP address for the node. If unset, kubelet will use the node’s default IPv4 address, if any, or its default IPv6 address if it has no IPv4 addresses. You can pass :: to make it prefer the default IPv6 address rather than the default IPv4 address.
mainProviderID–provider-id""Unique identifier for identifying the node in a machine database, i.e cloudprovider
mainCertDirectory–cert-dir/var/lib/kubelet/pkiThe directory where the TLS certs are located. If –tls-cert-file and –tls-private-key-file are provided, this flag will be ignored.
mainCloudProvider–cloud-provider""The path to the cloud provider configuration file. Empty string for no configuration file.
mainCloudConfigFile–cloud-config""The path to the cloud provider configuration file. Empty string for no configuration file.
mainRootDirectory–root-dir/var/lib/kubeletDirectory path for managing kubelet files (volume mounts,etc).
mainDynamicConfigDir–dynamic-config-dir""The Kubelet will use this directory for checkpointing downloaded configurations and tracking configuration health. The Kubelet will create this directory if it does not already exist. The path may be absolute or relative; relative paths start at the Kubelet’s current working directory. Providing this flag enables dynamic Kubelet configuration. The DynamicKubeletConfig feature gate must be enabled to pass this flag; this gate currently defaults to true because the feature is beta.
mainRegisterNode–register-nodetrueRegister the node with the apiserver. If –kubeconfig is not provided, this flag is irrelevant, as the Kubelet won’t have an apiserver to register with.
experimentalExperimentalMounterPath–experimental-mounter-path""[Experimental] Path of mounter binary. Leave empty to use the default mount.
experimentalExperimentalKernelMemcgNotification–experimental-kernel-memcg-notificationfalseIf enabled, the kubelet will integrate with the kernel memcg notification to determine if memory eviction thresholds are crossed rather than polling.
experimentalRemoteRuntimeEndpoint–container-runtime-endpointunix:///var/run/dockershim.sock“[Experimental] The endpoint of remote runtime service. Currently unix socket endpoint is supported on Linux, while npipe and tcp endpoints are supported on windows. Examples:‘unix:///var/run/dockershim.sock’, ’npipe:////./pipe/dockershim’
experimentalRemoteImageEndpoint–image-service-endpoint"”[Experimental] The endpoint of remote image service. If not specified, it will be the same with container-runtime-endpoint by default. Currently unix socket endpoint is supported on Linux, while npipe and tcp endpoints are supported on windows. Examples:‘unix:///var/run/dockershim.sock’, ’npipe:////./pipe/dockershim’
experimentalExperimentalCheckNodeCapabilitiesBeforeMount–experimental-check-node-capabilities-before-mountfalse[Experimental] if set true, the kubelet will check the underlying node for required components (binaries, etc.) before performing the mount
experimentalExperimentalNodeAllocatableIgnoreEvictionThreshold–experimental-allocatable-ignore-evictionfalseWhen set to ’true’, Hard Eviction Thresholds will be ignored while calculating Node Allocatable. See https://kubernetes.io/docs/tasks/administer-cluster/reserve-compute-resources/ for more details. [default=false]
experimentalNodeLabels–node-labels""<Warning: Alpha feature> Labels to add when registering the node in the cluster. Labels must be key=value pairs separated by ‘,’. Labels in the ‘kubernetes.io’ namespace must begin with an allowed prefix (kubelet.kubernetes.io, node.kubernetes.io) or be in the specifically allowed set (beta.kubernetes.io/arch, beta.kubernetes.io/instance-type, beta.kubernetes.io/os, failure-domain.beta.kubernetes.io/region, failure-domain.beta.kubernetes.io/zone, kubernetes.io/arch, kubernetes.io/hostname, kubernetes.io/os, node.kubernetes.io/instance-type, topology.kubernetes.io/region, topology.kubernetes.io/zone)
experimentalVolumePluginDir–volume-plugin-dir/usr/libexec/kubernetes/kubelet-plugins/volume/exec/The full path of the directory in which to search for additional third party volume plugins
experimentalLockFilePath–lock-file""<Warning: Alpha feature> The path to file for kubelet to use as a lock file.
experimentalExitOnLockContention–exit-on-lock-contentionfalseWhether kubelet should exit upon lock-file contention.
experimentalSeccompProfileRoot–seccomp-profile-root/var/lib/kubelet/seccomp<Warning: Alpha feature> Directory path for seccomp profiles.
experimentalBootstrapCheckpointPath–bootstrap-checkpoint-path""<Warning: Alpha feature> Path to the directory where the checkpoints are stored
experimentalNodeStatusMaxImages–node-status-max-images50<Warning: Alpha feature> The maximum number of images to report in Node.Status.Images. If -1 is specified, no cap will be applied.
deprecatedBootstrapKubeconfig–experimental-bootstrap-kubeconfig""Use –bootstrap-kubeconfig
deprecatedMinimumGCAge.Duration–minimum-container-ttl-duration0Minimum age for a finished container before it is garbage collected. Examples: ‘300ms’, ’10s’ or ‘2h45m’. Use –eviction-hard or –eviction-soft instead. Will be removed in a future version.
deprecatedMaxPerPodContainerCount–maximum-dead-containers-per-container1Maximum number of old instances to retain per container. Each container takes up some disk space. Use –eviction-hard or –eviction-soft instead. Will be removed in a future version.
deprecatedMaxContainerCount–maximum-dead-containers-1Maximum number of old instances of containers to retain globally. Each container takes up some disk space. To disable, set to a negative number. Use –eviction-hard or –eviction-soft instead. Will be removed in a future version.
deprecatedMasterServiceNamespace–master-service-namespacedefaultThe namespace from which the kubernetes master services should be injected into pods. This flag will be removed in a future version.
deprecatedRegisterSchedulable–register-schedulabletrueRegister the node as schedulable. Won’t have any effect if register-node is false. This flag will be removed in a future version.
deprecatedNonMasqueradeCIDR–non-masquerade-cidr10.0.0.0/8Traffic to IPs outside this range will use IP masquerade. Set to ‘0.0.0.0/0’ to never masquerade. This flag will be removed in a future version.
deprecatedKeepTerminatedPodVolumes–keep-terminated-pod-volumesfalseKeep terminated pod volumes mounted to the node after the pod terminates. Can be useful for debugging volume related issues. This flag will be removed in a future version.
deprecatedEnableCAdvisorJSONEndpoints–enable-cadvisor-json-endpointsfalseEnable cAdvisor json /spec and /stats/* endpoints. This flag will be removed in a future version.

kubeletConfigurationFlag options are divided into two categories. The first category, “deprecated command line,” can be configured in the command line (but is deprecated), in configuration files, and in dynamic kubelet configuration. The second category, “configuration,” cannot be configured in the command line and can only be set in configuration files and dynamic kubelet configuration.

categories分类var变量flagdefault默认值description
deprecated command lineFailSwapOn–fail-swap-ontrueMakes the Kubelet fail to start if swap is enabled on the node.
deprecated command lineStaticPodPath–pod-manifest-path""Path to the directory containing static pod files to run, or the path to a single static pod file. Files starting with dots will be ignored.
deprecated command lineSyncFrequency.Duration–sync-frequency1 * time.MinuteMax period between synchronizing running containers and config
deprecated command lineFileCheckFrequency.Duration–file-check-frequency20 * time.SecondDuration between checking config files for new data
deprecated command lineHTTPCheckFrequency.Duration–http-check-frequency20 * time.SecondDuration between checking http for new data
deprecated command lineStaticPodURL–manifest-url""URL for accessing additional Pod specifications to run
deprecated command lineStaticPodURLHeader–manifest-url-header""Comma-separated list of HTTP headers to use when accessing the url provided to –manifest-url. Multiple headers with the same name will be added in the same order provided. This flag can be repeatedly invoked. For example: --manifest-url-header 'a:hello,b:again,c:world' --manifest-url-header 'b:beautiful'
deprecated command lineAddress–address0.0.0.0The IP address for the Kubelet to serve on (set to 0.0.0.0 for all IPv4 interfaces and :: for all IPv6 interfaces)
deprecated command linePort–port10250The port for the Kubelet to serve on.
deprecated command lineReadOnlyPort–read-only-port0The read-only port for the Kubelet to serve on with no authentication/authorization (set to 0 to disable)
deprecated command lineAuthentication.Anonymous.Enabled–anonymous-authtrueEnables anonymous requests to the Kubelet server. Requests that are not rejected by another authentication method are treated as anonymous requests. Anonymous requests have a username of system:anonymous, and a group name of system:unauthenticated.
deprecated command lineAuthentication.Webhook.Enabled–authentication-token-webhookfalseUse the TokenReview API to determine authentication for bearer tokens.
deprecated command lineAuthentication.Webhook.CacheTTL.Duration–authentication-token-webhook-cache-ttl2 * time.MinuteThe duration to cache responses from the webhook token authenticator.
deprecated command lineAuthentication.X509.ClientCAFile–client-ca-file""If set, any request presenting a client certificate signed by one of the authorities in the client-ca-file is authenticated with an identity corresponding to the CommonName of the client certificate.
deprecated command lineAuthorization.Mode–authorization-modeAlwaysAllowAuthorization mode for Kubelet server. Valid options are AlwaysAllow or Webhook. Webhook mode uses the SubjectAccessReview API to determine authorization.
deprecated command lineAuthorization.Webhook.CacheAuthorizedTTL.Duration–authorization-webhook-cache-authorized-ttl5 * time.MinuteThe duration to cache ‘authorized’ responses from the webhook authorizer.
deprecated command lineAuthorization.Webhook.CacheUnauthorizedTTL.Duration–authorization-webhook-cache-unauthorized-ttl30 * time.SecondThe duration to cache ‘unauthorized’ responses from the webhook authorizer.
deprecated command lineTLSCertFile–tls-cert-file""File containing x509 Certificate used for serving HTTPS (with intermediate certs, if any, concatenated after server cert). If –tls-cert-file and –tls-private-key-file are not provided, a self-signed certificate and key are generated for the public address and saved to the directory passed to –cert-dir.
deprecated command lineTLSPrivateKeyFile–tls-private-key-file""File containing x509 private key matching –tls-cert-file.
deprecated command lineServerTLSBootstrap–rotate-server-certificatesfalseAuto-request and rotate the kubelet serving certificates by requesting new certificates from the kube-apiserver when the certificate expiration approaches. Requires the RotateKubeletServerCertificate feature gate to be enabled, and approval of the submitted CertificateSigningRequest objects.
deprecated command lineTLSCipherSuites–tls-cipher-suites""Comma-separated list of cipher suites for the server. If omitted, the default Go cipher suites will be used.
Preferred values: TLS_AES_128_GCM_SHA256, TLS_AES_256_GCM_SHA384, TLS_CHACHA20_POLY1305_SHA256, TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305, TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256, TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305, TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256, TLS_RSA_WITH_3DES_EDE_CBC_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_128_GCM_SHA256, TLS_RSA_WITH_AES_256_CBC_SHA, TLS_RSA_WITH_AES_256_GCM_SHA384.
Insecure values: TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256, TLS_ECDHE_ECDSA_WITH_RC4_128_SHA, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256, TLS_ECDHE_RSA_WITH_RC4_128_SHA, TLS_RSA_WITH_AES_128_CBC_SHA256, TLS_RSA_WITH_RC4_128_SHA.
deprecated command lineTLSMinVersion–tls-min-version""Minimum TLS version supported. Possible values: VersionTLS10, VersionTLS11, VersionTLS12, VersionTLS13
deprecated command lineRotateCertificates–rotate-certificatesfalse<Warning: Beta feature> Auto rotate the kubelet client certificates by requesting new certificates from the kube-apiserver when the certificate expiration approaches.
deprecated command lineRegistryPullQPS–registry-qps5If > 0, limit registry pull QPS to this value. If 0, unlimited.
deprecated command lineRegistryBurst–registry-burst10Maximum size of a bursty pulls, temporarily allows pulls to burst to this number, while still not exceeding registry-qps. Only used if –registry-qps > 0
deprecated command lineEventRecordQPS–event-qps5If > 0, limit event creations per second to this value. If 0, unlimited.
deprecated command lineEventBurst–event-burst10Maximum size of a bursty event records, temporarily allows event records to burst to this number, while still not exceeding event-qps. Only used if –event-qps > 0
deprecated command lineEnableDebuggingHandlers–enable-debugging-handlerstrueEnables server endpoints for log collection and local running of containers and commands
deprecated command lineEnableContentionProfiling–contention-profilingfalseEnable lock contention profiling, if profiling is enabled
deprecated command lineHealthzPort–healthz-port10248The port of the localhost healthz endpoint (set to 0 to disable)
deprecated command lineHealthzBindAddress–healthz-bind-address127.0.0.1The IP address for the healthz server to serve on (set to 0.0.0.0 for all IPv4 interfaces and :: for all IPv6 interfaces)
deprecated command lineOOMScoreAdj–oom-score-adj-999The oom-score-adj value for kubelet process. Values must be within the range [-1000, 1000]
deprecated command lineClusterDomain–cluster-domain""Domain for this cluster. If set, kubelet will configure all containers to search this domain in addition to the host’s search domains
deprecated command lineClusterDNS–cluster-dns""Comma-separated list of DNS server IP address. This value is used for containers DNS server in case of Pods with "dnsPolicy=ClusterFirst". Note: all DNS servers appearing in the list MUST serve the same set of records otherwise name resolution within the cluster may not work correctly. There is no guarantee as to which DNS server may be contacted for name resolution.
deprecated command lineStreamingConnectionIdleTimeout.Duration–streaming-connection-idle-timeout4 * time.HourMaximum time a streaming connection can be idle before the connection is automatically closed. 0 indicates no timeout. Example: ‘5m’
deprecated command lineNodeStatusUpdateFrequency.Duration–node-status-update-frequency10 * time.SecondSpecifies how often kubelet posts node status to master. Note: be cautious when changing the constant, it must work with nodeMonitorGracePeriod in nodecontroller.
deprecated command lineImageMinimumGCAge.Duration–minimum-image-ttl-duration2 * time.MinuteMinimum age for an unused image before it is garbage collected. Examples: ‘300ms’, ’10s’ or ‘2h45m’.
deprecated command lineImageGCHighThresholdPercent–image-gc-high-threshold85The percent of disk usage after which image garbage collection is always run. Values must be within the range [0, 100], To disable image garbage collection, set to 100.
deprecated command lineImageGCLowThresholdPercent–image-gc-low-threshold80The percent of disk usage before which image garbage collection is never run. Lowest disk usage to garbage collect to. Values must be within the range [0, 100] and should not be larger than that of –image-gc-high-threshold.
deprecated command lineVolumeStatsAggPeriod.Duration–volume-stats-agg-period1 * time.Minutepecifies interval for kubelet to calculate and cache the volume disk usage for all pods and volumes. To disable volume calculations, set to 0.
deprecated command lineFeatureGates–feature-gates""A set of key=value pairs that describe feature gates for alpha/experimental features.
deprecated command lineKubeletCgroups–kubelet-cgroups""Optional absolute name of cgroups to create and run the Kubelet in.
deprecated command lineSystemCgroups–system-cgroups""Optional absolute name of cgroups in which to place all non-kernel processes that are not already inside a cgroup under /. Empty for no container. Rolling back the flag requires a reboot.
deprecated command lineCgroupsPerQOS–cgroups-per-qostrueEnable creation of QoS cgroup hierarchy, if true top level QoS and pod cgroups are created.
deprecated command lineCgroupDriver–cgroup-drivercgroupfsDriver that the kubelet uses to manipulate cgroups on the host. Possible values: ‘cgroupfs’, ‘systemd’
deprecated command lineCgroupRoot–cgroup-root""Optional root cgroup to use for pods. This is handled by the container runtime on a best effort basis. Default: ‘’, which means use the container runtime default.
deprecated command lineCPUManagerPolicy–cpu-manager-policynoneCPU Manager policy to use. Possible values: ’none’, ‘static’. Default: ’none’
deprecated command lineCPUManagerReconcilePeriod.Duration–cpu-manager-reconcile-period10 * time.Second<Warning: Alpha feature> CPU Manager reconciliation period. Examples: ’10s’, or ‘1m’. If not supplied, defaults to NodeStatusUpdateFrequency
deprecated command lineQOSReserved–qos-reserved""<Warning: Alpha feature> A set of ResourceName=Percentage (e.g. memory=50%) pairs that describe how pod resource requests are reserved at the QoS level. Currently only memory is supported. Requires the QOSReserved feature gate to be enabled.
deprecated command lineTopologyManagerPolicy–topology-manager-policy“none”Topology Manager policy to use. Possible values: ’none’, ‘best-effort’, ‘restricted’, ‘single-numa-node’.
deprecated command lineRuntimeRequestTimeout.Duration–runtime-request-timeout2 * time.MinuteTimeout of all runtime requests except long running request - pull, logs, exec and attach. When timeout exceeded, kubelet will cancel the request, throw out an error and retry later.
deprecated command lineHairpinMode–hairpin-modepromiscuous-bridgeHow should the kubelet setup hairpin NAT. This allows endpoints of a Service to loadbalance back to themselves if they should try to access their own Service. Valid values are "promiscuous-bridge", "hairpin-veth" and "none".
deprecated command lineMaxPods–max-pods110Number of Pods that can run on this Kubelet.
deprecated command linePodCIDR–pod-cidr""The CIDR to use for pod IP addresses, only used in standalone mode. In cluster mode, this is obtained from the master. For IPv6, the maximum number of IP’s allocated is 65536
deprecated command linePodPidsLimit–pod-max-pids-1Set the maximum number of processes per pod. If -1, the kubelet defaults to the node allocatable pid capacity.
deprecated command lineResolverConfig–resolv-conf/etc/resolv.confResolver configuration file used as the basis for the container DNS resolution configuration.
deprecated command lineCPUCFSQuota–cpu-cfs-quotatrueEnable CPU CFS quota enforcement for containers that specify CPU limits
deprecated command lineCPUCFSQuotaPeriod–cpu-cfs-quota-period100 * time.MillisecondSets CPU CFS quota period value, cpu.cfs_period_us, defaults to Linux Kernel default
deprecated command lineEnableControllerAttachDetach–enable-controller-attach-detachtrueEnables the Attach/Detach controller to manage attachment/detachment of volumes scheduled to this node, and disables kubelet from executing any attach/detach operations
deprecated command lineMakeIPTablesUtilChains–make-iptables-util-chainstrueIf true, kubelet will ensure iptables utility rules are present on host.
deprecated command lineIPTablesMasqueradeBit–iptables-masquerade-bit14The bit of the fwmark space to mark packets for SNAT. Must be within the range [0, 31]. Please match this parameter with corresponding parameter in kube-proxy.
deprecated command lineIPTablesDropBit–iptables-drop-bit15The bit of the fwmark space to mark packets for dropping. Must be within the range [0, 31].
deprecated command lineContainerLogMaxSize–container-log-max-size10Mi<Warning: Beta feature> Set the maximum size (e.g. 10Mi) of container log file before it is rotated. This flag can only be used with –container-runtime=remote.
deprecated command lineContainerLogMaxFiles–container-log-max-files5<Warning: Beta feature> Set the maximum number of container log files that can be present for a container. The number must be >= 2. This flag can only be used with –container-runtime=remote.
deprecated command lineAllowedUnsafeSysctls–allowed-unsafe-sysctls""Comma-separated whitelist of unsafe sysctls or unsafe sysctl patterns (ending in *). Use these at your own risk.
deprecated command lineMaxOpenFiles–max-open-files1000000Number of files that can be opened by Kubelet process.
deprecated command lineContentType–kube-api-content-typeapplication/vnd.kubernetes.protobufContent type of requests sent to apiserver.
deprecated command lineKubeAPIQPS–kube-api-qps5QPS to use while talking with kubernetes apiserver
deprecated command lineKubeAPIBurst–kube-api-burst10Burst to use while talking with kubernetes apiserver
deprecated command lineSerializeImagePulls–serialize-image-pullstruePull images one at a time. We recommend not changing the default value on nodes that run docker daemon with version < 1.9 or an Aufs storage backend. Issue #10959 has more details.
deprecated command lineEvictionHard–eviction-hardmemory.available<100Mi,nodefs.available<10%,nodefs.inodesFree<5%,imagefs.available<15%A set of eviction thresholds (e.g. memory.available<1Gi) that if met would trigger a pod eviction.
deprecated command lineEvictionSoft–eviction-soft""A set of eviction thresholds (e.g. memory.available<1.5Gi) that if met over a corresponding grace period would trigger a pod eviction.
deprecated command lineEvictionSoftGracePeriod–eviction-soft-grace-period""A set of eviction grace periods (e.g. memory.available=1m30s) that correspond to how long a soft eviction threshold must hold before triggering a pod eviction.
deprecated command lineEvictionPressureTransitionPeriod.Duration–eviction-pressure-transition-period5 * time.MinuteDuration for which the kubelet has to wait before transitioning out of an eviction pressure condition.
deprecated command lineEvictionMaxPodGracePeriod–eviction-max-pod-grace-period0Maximum allowed grace period (in seconds) to use when terminating pods in response to a soft eviction threshold being met. If negative, defer to pod specified value.
deprecated command lineEvictionMinimumReclaim–eviction-minimum-reclaim0A set of minimum reclaims (e.g. imagefs.available=2Gi) that describes the minimum amount of resource the kubelet will reclaim when performing a pod eviction if that resource is under pressure.
deprecated command linePodsPerCore–pods-per-core0Number of Pods per core that can run on this Kubelet. The total number of Pods on this Kubelet cannot exceed max-pods, so max-pods will be used if this calculation results in a larger number of Pods allowed on the Kubelet. A value of 0 disables this limit.
deprecated command lineProtectKernelDefaults–protect-kernel-defaultsfalseDefault kubelet behaviour for kernel tuning. If set, kubelet errors if any of kernel tunables is different than kubelet defaults.
deprecated command lineReservedSystemCPUs–reserved-cpus""A comma-separated list of CPUs or CPU ranges that are reserved for system and kubernetes usage. This specific list will supersede cpu counts in –system-reserved and –kube-reserved.
deprecated command lineSystemReserved–system-reserved""A set of ResourceName=ResourceQuantity (e.g. cpu=200m,memory=500Mi,ephemeral-storage=1Gi) pairs that describe resources reserved for non-kubernetes components. Currently only cpu and memory are supported. See http://kubernetes.io/docs/user-guide/compute-resources for more detail. [default=none]
deprecated command lineKubeReserved–kube-reserved""A set of ResourceName=ResourceQuantity (e.g. cpu=200m,memory=500Mi,ephemeral-storage=1Gi) pairs that describe resources reserved for kubernetes system components. Currently cpu, memory and local ephemeral storage for root file system are supported. See http://kubernetes.io/docs/user-guide/compute-resources for more detail. [default=none]
deprecated command lineEnforceNodeAllocatable–enforce-node-allocatablepodsA comma separated list of levels of node allocatable enforcement to be enforced by kubelet. Acceptable options are ’none’, ‘pods’, ‘system-reserved’, and ‘kube-reserved’. If the latter two options are specified, ‘–system-reserved-cgroup’ and ‘–kube-reserved-cgroup’ must also be set, respectively. If ’none’ is specified, no additional options should be set. See https://kubernetes.io/docs/tasks/administer-cluster/reserve-compute-resources/ for more details.
deprecated command lineSystemReservedCgroup–system-reserved-cgroup""Absolute name of the top level cgroup that is used to manage non-kubernetes components for which compute resources were reserved via ‘–system-reserved’ flag. Ex. ‘/system-reserved’. [default=’’]
deprecated command lineKubeReservedCgroup–kube-reserved-cgroup""Absolute name of the top level cgroup that is used to manage kubernetes components for which compute resources were reserved via ‘–kube-reserved’ flag. Ex. ‘/kube-reserved’. [default=’’]
configurationNodeStatusReportFrequency5 * time.MinuteThe frequency that kubelet posts node status to master if node status does not change. Kubelet will ignore this frequency and post node status immediately if any change is detected. It is only used when node lease feature is enabled. nodeStatusReportFrequency’s default value is 1m. But if nodeStatusUpdateFrequency is set explicitly, nodeStatusReportFrequency’s default value will be set to nodeStatusUpdateFrequency for backward compatibility.
configurationNodeLeaseDurationSeconds40 * time.SecondThe duration the Kubelet will set on its corresponding Lease, when the NodeLease feature is enabled. This feature provides an indicator of node health by having the Kubelet create and periodically renew a lease, named after the node, in the kube-node-lease namespace. If the lease expires, the node can be considered unhealthy. The lease is currently renewed every 10s, per KEP-0009. In the future, the lease renewal interval may be set based on the lease duration. Requires the NodeLease feature gate to be enabled.
configurationConfigMapAndSecretChangeDetectionStrategyWatchA mode in which config map and secret managers are running.
configurationShowHiddenMetricsForVersion""The previous version for which you want to show hidden metrics. Only the previous minor version is meaningful, other values will not be allowed. The format is ., e.g.: ‘1.16’. The purpose of this format is make sure you have the opportunity to notice if the next release hides additional metrics, rather than being surprised when they are permanently removed in the release after that.

globalFlags includes options related to klog, CAdvisor, CredentialProvider, and logflush.

The klog options are defined using klog.InitFlags.

go

// InitFlags is for explicitly initializing the flags.
func InitFlags(flagset *flag.FlagSet) {
	if flagset == nil {
		flagset = flag.CommandLine
	}

	flagset.StringVar(&logging.logDir, "log_dir", logging.logDir, "If non-empty, write log files in this directory")
	flagset.StringVar(&logging.logFile, "log_file", logging.logFile, "If non-empty, use this log file")
	flagset.Uint64Var(&logging.logFileMaxSizeMB, "log_file_max_size", logging.logFileMaxSizeMB,
		"Defines the maximum size a log file can grow to. Unit is megabytes. "+
			"If the value is 0, the maximum file size is unlimited.")
	flagset.BoolVar(&logging.toStderr, "logtostderr", logging.toStderr, "log to standard error instead of files")
	flagset.BoolVar(&logging.alsoToStderr, "alsologtostderr", logging.alsoToStderr, "log to standard error as well as files")
	flagset.Var(&logging.verbosity, "v", "number for the log level verbosity")
	flagset.BoolVar(&logging.skipHeaders, "add_dir_header", logging.addDirHeader, "If true, adds the file directory to the header") //这里应该是&logging.addDirHeader,在下一个klog版本v2.0.0修复了,所有的1.18版本都会有这个问题
	flagset.BoolVar(&logging.skipHeaders, "skip_headers", logging.skipHeaders, "If true, avoid header prefixes in the log messages")
	flagset.BoolVar(&logging.skipLogHeaders, "skip_log_headers", logging.skipLogHeaders, "If true, avoid headers when opening log files")
	flagset.Var(&logging.stderrThreshold, "stderrthreshold", "logs at or above this threshold go to stderr")
	flagset.Var(&logging.vmodule, "vmodule", "comma-separated list of pattern=N settings for file-filtered logging")
	flagset.Var(&logging.traceLocation, "log_backtrace_at", "when logging hits line file:N, emit a stack trace")
}

cadvisor define

The cadvisor flags are imported through anonymous imports and can be found in the code saved under vendor/github.com/google/cadvisor.

go

// ensure libs have a chance to globally register their flags
	_ "github.com/google/cadvisor/container/common"
	_ "github.com/google/cadvisor/container/containerd"
	_ "github.com/google/cadvisor/container/docker"
	_ "github.com/google/cadvisor/container/raw"
	_ "github.com/google/cadvisor/machine"
	_ "github.com/google/cadvisor/manager"
	_ "github.com/google/cadvisor/storage"

For example, taking github.com/google/cadvisor/container/docker as an example, it defines the following options.

go

var ArgDockerEndpoint = flag.String("docker", "unix:///var/run/docker.sock", "docker endpoint")
var ArgDockerTLS = flag.Bool("docker-tls", false, "use TLS to connect to docker")
var ArgDockerCert = flag.String("docker-tls-cert", "cert.pem", "path to client certificate")
var ArgDockerKey = flag.String("docker-tls-key", "key.pem", "path to private key")
var ArgDockerCA = flag.String("docker-tls-ca", "ca.pem", "path to trusted CA")

// The namespace under which Docker aliases are unique.
const DockerNamespace = "docker"

// Regexp that identifies docker cgroups, containers started with
// --cgroup-parent have another prefix than 'docker'
var dockerCgroupRegexp = regexp.MustCompile(`([a-z0-9]{64})`)

var dockerEnvWhitelist = flag.String("docker_env_metadata_whitelist", "", "a comma-separated list of environment variable keys that needs to be collected for docker containers")

var (
	// Basepath to all container specific information that libcontainer stores.
	dockerRootDir string

	dockerRootDirFlag = flag.String("docker_root", "/var/lib/docker", "DEPRECATED: docker root is read from docker info (this is a fallback, default: /var/lib/docker)")

	dockerRootDirOnce sync.Once

	// flag that controls globally disabling thin_ls pending future enhancements.
	// in production, it has been found that thin_ls makes excessive use of iops.
	// in an iops restricted environment, usage of thin_ls must be controlled via blkio.
	// pending that enhancement, disable its usage.
	disableThinLs = true
)

Except for --docker-root and housekeeping-interval, all other options in the cadvisor section are deprecated. Notably, the update_machine_info_interval flag is not registered with kubelet. Based on commit records, update_machine_info_interval was added when upgrading the cadvisor version to 0.33.0. It’s possible that these options are not registered with kubelet due to their deprecated status.

go

// These flags were also implicit from cadvisor, but are actually used by something in the core repo:
	// TODO(mtaufen): This one is stil used by our salt, but for heaven's sake it's even deprecated in cadvisor
	register(global, local, "docker_root")
	// e2e node tests rely on this
	register(global, local, "housekeeping_interval")

	// These flags were implicit from cadvisor, and are mistakes that should be registered deprecated:
	const deprecated = "This is a cadvisor flag that was mistakenly registered with the Kubelet. Due to legacy concerns, it will follow the standard CLI deprecation timeline before being removed."

	registerDeprecated(global, local, "application_metrics_count_limit", deprecated)
	registerDeprecated(global, local, "boot_id_file", deprecated)
	registerDeprecated(global, local, "container_hints", deprecated)
	registerDeprecated(global, local, "containerd", deprecated)
	registerDeprecated(global, local, "docker", deprecated)
	registerDeprecated(global, local, "docker_env_metadata_whitelist", deprecated)
	registerDeprecated(global, local, "docker_only", deprecated)
	registerDeprecated(global, local, "docker-tls", deprecated)
	registerDeprecated(global, local, "docker-tls-ca", deprecated)
	registerDeprecated(global, local, "docker-tls-cert", deprecated)
	registerDeprecated(global, local, "docker-tls-key", deprecated)
	registerDeprecated(global, local, "enable_load_reader", deprecated)
	registerDeprecated(global, local, "event_storage_age_limit", deprecated)
	registerDeprecated(global, local, "event_storage_event_limit", deprecated)
	registerDeprecated(global, local, "global_housekeeping_interval", deprecated)
	registerDeprecated(global, local, "log_cadvisor_usage", deprecated)
	registerDeprecated(global, local, "machine_id_file", deprecated)
	registerDeprecated(global, local, "storage_driver_user", deprecated)
	registerDeprecated(global, local, "storage_driver_password", deprecated)
	registerDeprecated(global, local, "storage_driver_host", deprecated)
	registerDeprecated(global, local, "storage_driver_db", deprecated)
	registerDeprecated(global, local, "storage_driver_table", deprecated)
	registerDeprecated(global, local, "storage_driver_secure", deprecated)
	registerDeprecated(global, local, "storage_driver_buffer_duration", deprecated)

CredentialProviderFlags

In cmd\kubelet\app\options\globalflags.go, the CredentialProviderFlags are anonymously imported as follows:

go

	// ensure libs have a chance to globally register their flags
	_ "k8s.io/kubernetes/pkg/credentialprovider/azure"

In pkg\credentialprovider\azure\azure_credentials.go, the flagConfigFile is defined as:

go

var flagConfigFile = pflag.String("azure-container-registry-config", "",
	"Path to the file containing Azure container registry configuration information.")

version

The version option is defined in staging\src\k8s.io\component-base\version\verflag\verflag.go. It accepts three values: false (default), true (enabled without any parameters), and raw (displays detailed version information in JSON format). There will be a separate article dedicated to Kubernetes version-related release rules and various hacks related to versions.

go

func VersionVar(p *versionValue, name string, value versionValue, usage string) {
	*p = value
	flag.Var(p, name, usage)
	// "--version" will be treated as "--version=true"
	flag.Lookup(name).NoOptDefVal = "true"
}

func Version(name string, value versionValue, usage string) *versionValue {
	p := new(versionValue)
	VersionVar(p, name, value, usage)
	return p
}

const versionFlagName = "version"

var (
	versionFlag = Version(versionFlagName, VersionFalse, "Print version information and quit")
)

log options

in staging\src\k8s.io\component-base\logs\logs.go

go

const logFlushFreqFlagName = "log-flush-frequency"

var logFlushFreq = pflag.Duration(logFlushFreqFlagName, 5*time.Second, "Maximum number of seconds between log flushes")
categories分类var变量flagdefault默认值description
kloglogDir–log-dir""If non-empty, write log files in this directory
kloglogFile–log-file""If non-empty, use this log file
kloglogFileMaxSizeMB–log-file-max-size1800Defines the maximum size a log file can grow to. Unit is megabytes. If the value is 0, the maximum file size is unlimited.
klogtoStderr–logtostderrtruelog to standard error instead of files
klogalsoToStderr–alsologtostderrfalselog to standard error as well as files
klogverbosity-v, –v0number for the log level verbosity
klogaddDirHeader–add-dir-headerfalseIf true, adds the file directory to the header
klogskipHeaders–skip-headersfalseIf true, avoid header prefixes in the log messages
klogskipLogHeaders–skip-log-headersfalseIf true, avoid headers when opening log files
klogstderrThreshold–stderrthreshold2logs at or above this threshold go to stderr
klogvmodule–vmodule""comma-separated list of pattern=N settings for file-filtered logging
klogtraceLocation–log-backtrace-at""when logging hits line file:N, emit a stack trace
cadvisordockerRootDirFlag–docker-root/var/lib/dockerDEPRECATED: docker root is read from docker info (this is a fallback, default: /var/lib/docker)
cadvisorArgDockerEndpoint–dockerunix:///var/run/docker.sockdocker endpoint
cadvisorArgDockerTLS–docker-tlsfalseuse TLS to connect to docker
cadvisorArgDockerCert–docker-tls-certcert.pempath to client certificate
cadvisorArgDockerKey–docker-tls-keykey.pempath to private key
cadvisorArgDockerCA–docker-tls-caca.pempath to trusted CA
cadvisordockerEnvWhitelist–docker-env-metadata-whitelist""a comma-separated list of environment variable keys that needs to be collected for docker containers
cadvisorArgContainerHints–container-hints/etc/cadvisor/container_hints.jsonlocation of the container hints file
cadvisorArgContainerdEndpoint–containerd/run/containerd/containerd.sockcontainerd endpoint
cadvisorArgContainerdNamespace–containerd-namespacek8s.iocontainerd namespace
cadvisordockerOnly–docker-onlyfalseOnly report docker containers in addition to root stats
cadvisordisableRootCgroupStats–disable-root-cgroup-statsfalseDisable collecting root Cgroup stats
cadvisormachineIdFilePath–machine-id-file/etc/machine-id,/var/lib/dbus/machine-idComma-separated list of files to check for machine-id. Use the first one that exists.
cadvisorbootIdFilePath–boot-id-file/proc/sys/kernel/random/boot_idComma-separated list of files to check for boot-id. Use the first one that exists.
cadvisorenableLoadReader–enable-load-readerfalseWhether to enable cpu load reader
cadvisorHousekeepingInterval–housekeeping-interval1 * time.SecondInterval between container housekeepings
cadvisorglobalHousekeepingInterval–global-housekeeping-interval1 * time.MinuteInterval between global housekeepings
cadvisorlogCadvisorUsage–log-cadvisor-usagefalseWhether to log the usage of the cAdvisor container
cadvisoreventStorageAgeLimit–event-storage-age-limitdefault=24hMax length of time for which to store events (per type). Value is a comma separated list of key values, where the keys are event types (e.g.: creation, oom) or "default" and the value is a duration. Default is applied to all non-specified event types
cadvisoreventStorageEventLimit–event-storage-event-limitdefault=100000Max number of events to store (per type). Value is a comma separated list of key values, where the keys are event types (e.g.: creation, oom) or "default" and the value is an integer. Default is applied to all non-specified event types
cadvisorapplicationMetricsCountLimit–application-metrics-count-limit100Max number of application metrics to store (per container)
cadvisorArgDbUsername–storage-driver-userrootdatabase username
cadvisorArgDbPassword–storage-driver-passwordrootdatabase password
cadvisorArgDbHost–storage-driver-hostlocalhost:8086database host:port
cadvisorArgDbName–storage-driver-dbcadvisordatabase name
cadvisorArgDbTable–storage-driver-tablestatstable name
cadvisorArgDbIsSecure–storage-driver-securefalseuse secure connection with database
cadvisorArgDbBufferDuration–storage-driver-buffer-duration60 * time.SecondWrites in the storage driver will be buffered for this duration, and committed to the non memory backends as a single transaction
CredentialProviderflagConfigFile–azure-container-registry-config""Path to the file containing Azure container registry configuration information.
versionversionFlag–versionfalsePrint version information and quit
loglogFlushFreq–log-flush-frequency5 * time.SecondMaximum number of seconds between log flushes

A special option is used to display the command’s help information, which can be triggered by -h or --help flags.

go

cleanFlagSet.BoolP("help", "h", false, fmt.Sprintf("help for %s", cmd.Name()))

Related Content