2014-10-27 17:04:39 +00:00
/ *
2015-05-01 16:19:44 +00:00
Copyright 2014 The Kubernetes Authors All rights reserved .
2014-10-27 17:04:39 +00:00
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 .
* /
2015-02-07 21:30:53 +00:00
// Package app makes it easy to create a kubelet server for various contexts.
package app
2014-10-27 17:04:39 +00:00
2015-06-10 20:31:22 +00:00
// Note: if you change code in this file, you might need to change code in
// contrib/mesos/pkg/executor/service/.
2014-10-27 17:04:39 +00:00
import (
2015-04-01 23:19:17 +00:00
"crypto/tls"
2014-10-27 17:04:39 +00:00
"fmt"
2015-02-02 21:30:31 +00:00
"math/rand"
2014-10-27 17:04:39 +00:00
"net"
2015-03-30 21:09:50 +00:00
"net/http"
2015-04-17 06:07:00 +00:00
_ "net/http/pprof"
2015-04-01 23:19:17 +00:00
"path"
2015-03-30 21:09:50 +00:00
"strconv"
2015-03-24 23:09:16 +00:00
"strings"
2014-10-27 17:04:39 +00:00
"time"
2015-08-05 22:03:47 +00:00
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/capabilities"
"k8s.io/kubernetes/pkg/client"
"k8s.io/kubernetes/pkg/client/chaosclient"
"k8s.io/kubernetes/pkg/client/clientcmd"
clientcmdapi "k8s.io/kubernetes/pkg/client/clientcmd/api"
"k8s.io/kubernetes/pkg/client/record"
"k8s.io/kubernetes/pkg/clientauth"
"k8s.io/kubernetes/pkg/credentialprovider"
"k8s.io/kubernetes/pkg/healthz"
"k8s.io/kubernetes/pkg/kubelet"
"k8s.io/kubernetes/pkg/kubelet/cadvisor"
"k8s.io/kubernetes/pkg/kubelet/config"
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
"k8s.io/kubernetes/pkg/kubelet/dockertools"
"k8s.io/kubernetes/pkg/kubelet/network"
"k8s.io/kubernetes/pkg/master/ports"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/mount"
nodeutil "k8s.io/kubernetes/pkg/util/node"
"k8s.io/kubernetes/pkg/volume"
2014-10-27 17:04:39 +00:00
"github.com/golang/glog"
2015-02-02 21:30:31 +00:00
"github.com/spf13/pflag"
2015-08-05 22:05:17 +00:00
"k8s.io/kubernetes/pkg/cloudprovider"
2014-10-27 17:04:39 +00:00
)
2015-02-02 21:30:31 +00:00
const defaultRootDir = "/var/lib/kubelet"
// KubeletServer encapsulates all of the parameters necessary for starting up
// a kubelet. These can either be set via command line or directly.
type KubeletServer struct {
2015-01-08 20:41:38 +00:00
Config string
SyncFrequency time . Duration
FileCheckFrequency time . Duration
HTTPCheckFrequency time . Duration
ManifestURL string
2015-07-30 16:28:47 +00:00
ManifestURLHeader string
2015-01-08 20:41:38 +00:00
EnableServer bool
Address util . IP
Port uint
2015-04-02 04:41:32 +00:00
ReadOnlyPort uint
2015-01-08 20:41:38 +00:00
HostnameOverride string
PodInfraContainerImage string
DockerEndpoint string
RootDirectory string
AllowPrivileged bool
2015-03-24 23:09:16 +00:00
HostNetworkSources string
2015-01-08 20:41:38 +00:00
RegistryPullQPS float64
RegistryBurst int
RunOnce bool
EnableDebuggingHandlers bool
MinimumGCAge time . Duration
2015-03-14 17:13:20 +00:00
MaxPerPodContainerCount int
2015-01-08 20:41:38 +00:00
MaxContainerCount int
2015-05-12 03:44:13 +00:00
AuthPath util . StringFlag // Deprecated -- use KubeConfig instead
KubeConfig util . StringFlag
2015-03-10 05:39:00 +00:00
CadvisorPort uint
2015-03-30 21:09:50 +00:00
HealthzPort int
HealthzBindAddress util . IP
2015-01-08 20:41:38 +00:00
OOMScoreAdj int
2015-08-05 14:21:47 +00:00
APIServerList [ ] string
2015-05-20 21:21:03 +00:00
RegisterNode bool
2015-06-12 17:20:26 +00:00
StandaloneMode bool
2015-01-08 20:41:38 +00:00
ClusterDomain string
MasterServiceNamespace string
ClusterDNS util . IP
StreamingConnectionIdleTimeout time . Duration
2015-03-16 04:00:46 +00:00
ImageGCHighThresholdPercent int
ImageGCLowThresholdPercent int
2015-05-12 08:24:08 +00:00
LowDiskSpaceThresholdMB int
2015-03-19 23:14:13 +00:00
NetworkPluginName string
2015-07-01 18:53:42 +00:00
NetworkPluginDir string
2015-03-23 22:31:13 +00:00
CloudProvider string
CloudConfigFile string
2015-04-01 23:19:17 +00:00
TLSCertFile string
TLSPrivateKeyFile string
CertDirectory string
2015-03-31 11:17:12 +00:00
NodeStatusUpdateFrequency time . Duration
2015-04-14 00:30:57 +00:00
ResourceContainer string
2015-04-24 00:07:52 +00:00
CgroupRoot string
2015-05-01 21:24:07 +00:00
ContainerRuntime string
2015-05-12 16:59:02 +00:00
DockerDaemonContainer string
2015-05-19 23:19:12 +00:00
SystemContainer string
2015-05-11 21:07:24 +00:00
ConfigureCBR0 bool
2015-06-24 18:10:10 +00:00
PodCIDR string
2015-03-17 14:43:49 +00:00
MaxPods int
2015-05-27 12:51:01 +00:00
DockerExecHandlerName string
2015-04-11 16:45:45 +00:00
// Flags intended for testing
// Crash immediately, rather than eating panics.
ReallyCrashForTesting bool
// Insert a probability of random errors during calls to the master.
ChaosChance float64
2015-05-05 15:07:15 +00:00
// Is the kubelet containerized?
Containerized bool
2015-02-02 21:30:31 +00:00
}
2015-03-26 12:31:54 +00:00
// bootstrapping interface for kubelet, targets the initialization protocol
type KubeletBootstrap interface {
BirthCry ( )
StartGarbageCollection ( )
ListenAndServe ( net . IP , uint , * kubelet . TLSOptions , bool )
ListenAndServeReadOnly ( net . IP , uint )
Run ( <- chan kubelet . PodUpdate )
RunOnce ( <- chan kubelet . PodUpdate ) ( [ ] kubelet . RunPodResult , error )
}
// create and initialize a Kubelet instance
type KubeletBuilder func ( kc * KubeletConfig ) ( KubeletBootstrap , * config . PodConfig , error )
2015-02-02 21:30:31 +00:00
// NewKubeletServer will create a new KubeletServer with default values.
func NewKubeletServer ( ) * KubeletServer {
return & KubeletServer {
2015-04-02 04:41:32 +00:00
SyncFrequency : 10 * time . Second ,
FileCheckFrequency : 20 * time . Second ,
HTTPCheckFrequency : 20 * time . Second ,
EnableServer : true ,
Address : util . IP ( net . ParseIP ( "0.0.0.0" ) ) ,
Port : ports . KubeletPort ,
ReadOnlyPort : ports . KubeletReadOnlyPort ,
2015-04-09 01:56:58 +00:00
PodInfraContainerImage : dockertools . PodInfraContainerImage ,
2015-03-16 04:00:46 +00:00
RootDirectory : defaultRootDir ,
RegistryBurst : 10 ,
EnableDebuggingHandlers : true ,
MinimumGCAge : 1 * time . Minute ,
2015-05-20 00:30:16 +00:00
MaxPerPodContainerCount : 2 ,
2015-03-16 04:00:46 +00:00
MaxContainerCount : 100 ,
2015-05-12 03:44:13 +00:00
AuthPath : util . NewStringFlag ( "/var/lib/kubelet/kubernetes_auth" ) , // deprecated
KubeConfig : util . NewStringFlag ( "/var/lib/kubelet/kubeconfig" ) ,
2015-03-16 04:00:46 +00:00
CadvisorPort : 4194 ,
2015-03-30 21:09:50 +00:00
HealthzPort : 10248 ,
HealthzBindAddress : util . IP ( net . ParseIP ( "127.0.0.1" ) ) ,
2015-05-20 21:21:03 +00:00
RegisterNode : true , // will be ignored if no apiserver is configured
2015-03-16 04:00:46 +00:00
OOMScoreAdj : - 900 ,
MasterServiceNamespace : api . NamespaceDefault ,
ImageGCHighThresholdPercent : 90 ,
ImageGCLowThresholdPercent : 80 ,
2015-05-12 08:24:08 +00:00
LowDiskSpaceThresholdMB : 256 ,
2015-03-19 23:14:13 +00:00
NetworkPluginName : "" ,
2015-07-01 18:53:42 +00:00
NetworkPluginDir : "/usr/libexec/kubernetes/kubelet-plugins/net/exec/" ,
2015-03-24 23:09:16 +00:00
HostNetworkSources : kubelet . FileSource ,
2015-04-01 23:19:17 +00:00
CertDirectory : "/var/run/kubernetes" ,
2015-04-07 19:36:09 +00:00
NodeStatusUpdateFrequency : 10 * time . Second ,
2015-04-14 00:30:57 +00:00
ResourceContainer : "/kubelet" ,
2015-05-13 22:50:23 +00:00
CgroupRoot : "" ,
2015-05-01 21:24:07 +00:00
ContainerRuntime : "docker" ,
2015-05-12 16:59:02 +00:00
DockerDaemonContainer : "/docker-daemon" ,
2015-05-19 23:19:12 +00:00
SystemContainer : "" ,
2015-05-11 21:07:24 +00:00
ConfigureCBR0 : false ,
2015-05-27 12:51:01 +00:00
DockerExecHandlerName : "native" ,
2015-02-02 21:30:31 +00:00
}
}
// AddFlags adds flags for a specific KubeletServer to the specified FlagSet
func ( s * KubeletServer ) AddFlags ( fs * pflag . FlagSet ) {
fs . StringVar ( & s . Config , "config" , s . Config , "Path to the config file or directory of files" )
2015-04-24 06:10:33 +00:00
fs . DurationVar ( & s . SyncFrequency , "sync-frequency" , s . SyncFrequency , "Max period between synchronizing running containers and config" )
fs . DurationVar ( & s . FileCheckFrequency , "file-check-frequency" , s . FileCheckFrequency , "Duration between checking config files for new data" )
fs . DurationVar ( & s . HTTPCheckFrequency , "http-check-frequency" , s . HTTPCheckFrequency , "Duration between checking http for new data" )
fs . StringVar ( & s . ManifestURL , "manifest-url" , s . ManifestURL , "URL for accessing the container manifest" )
2015-07-30 16:28:47 +00:00
fs . StringVar ( & s . ManifestURLHeader , "manifest-url-header" , s . ManifestURLHeader , "HTTP header to use when accessing the manifest URL, with the key separated from the value with a ':', as in 'key:value'" )
2015-06-10 21:48:54 +00:00
fs . BoolVar ( & s . EnableServer , "enable-server" , s . EnableServer , "Enable the Kubelet's server" )
fs . Var ( & s . Address , "address" , "The IP address for the Kubelet to serve on (set to 0.0.0.0 for all interfaces)" )
fs . UintVar ( & s . Port , "port" , s . Port , "The port for the Kubelet to serve on. Note that \"kubectl logs\" will not work if you set this flag." ) // see #9325
fs . UintVar ( & s . ReadOnlyPort , "read-only-port" , s . ReadOnlyPort , "The read-only port for the Kubelet to serve on (set to 0 to disable)" )
2015-04-24 06:10:33 +00:00
fs . StringVar ( & s . TLSCertFile , "tls-cert-file" , s . TLSCertFile , "" +
2015-04-01 23:19:17 +00:00
"File containing x509 Certificate for HTTPS. (CA cert, 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." )
2015-04-24 06:10:33 +00:00
fs . StringVar ( & s . TLSPrivateKeyFile , "tls-private-key-file" , s . TLSPrivateKeyFile , "File containing x509 private key matching --tls_cert_file." )
fs . StringVar ( & s . CertDirectory , "cert-dir" , s . CertDirectory , "The directory where the TLS certs are located (by default /var/run/kubernetes). " +
2015-04-19 15:35:56 +00:00
"If --tls_cert_file and --tls_private_key_file are provided, this flag will be ignored." )
2015-04-24 06:10:33 +00:00
fs . StringVar ( & s . HostnameOverride , "hostname-override" , s . HostnameOverride , "If non-empty, will use this string as identification instead of the actual hostname." )
fs . StringVar ( & s . PodInfraContainerImage , "pod-infra-container-image" , s . PodInfraContainerImage , "The image whose network/ipc namespaces containers in each pod will use." )
fs . StringVar ( & s . DockerEndpoint , "docker-endpoint" , s . DockerEndpoint , "If non-empty, use this for the docker endpoint to communicate with" )
fs . StringVar ( & s . RootDirectory , "root-dir" , s . RootDirectory , "Directory path for managing kubelet files (volume mounts,etc)." )
fs . BoolVar ( & s . AllowPrivileged , "allow-privileged" , s . AllowPrivileged , "If true, allow containers to request privileged mode. [default=false]" )
fs . StringVar ( & s . HostNetworkSources , "host-network-sources" , s . HostNetworkSources , "Comma-separated list of sources from which the Kubelet allows pods to use of host network. For all sources use \"*\" [default=\"file\"]" )
fs . Float64Var ( & s . RegistryPullQPS , "registry-qps" , s . RegistryPullQPS , "If > 0, limit registry pull QPS to this value. If 0, unlimited. [default=0.0]" )
fs . IntVar ( & s . RegistryBurst , "registry-burst" , s . RegistryBurst , "Maximum 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" )
2015-03-10 16:15:17 +00:00
fs . BoolVar ( & s . RunOnce , "runonce" , s . RunOnce , "If true, exit after spawning pods from local manifests or remote urls. Exclusive with --api_servers, and --enable-server" )
2015-04-24 06:10:33 +00:00
fs . BoolVar ( & s . EnableDebuggingHandlers , "enable-debugging-handlers" , s . EnableDebuggingHandlers , "Enables server endpoints for log collection and local running of containers and commands" )
fs . DurationVar ( & s . MinimumGCAge , "minimum-container-ttl-duration" , s . MinimumGCAge , "Minimum age for a finished container before it is garbage collected. Examples: '300ms', '10s' or '2h45m'" )
2015-05-20 00:30:16 +00:00
fs . IntVar ( & s . MaxPerPodContainerCount , "maximum-dead-containers-per-container" , s . MaxPerPodContainerCount , "Maximum number of old instances of a container to retain per container. Each container takes up some disk space. Default: 2." )
2015-04-24 06:10:33 +00:00
fs . IntVar ( & s . MaxContainerCount , "maximum-dead-containers" , s . MaxContainerCount , "Maximum number of old instances of a containers to retain globally. Each container takes up some disk space. Default: 100." )
2015-05-12 03:44:13 +00:00
fs . Var ( & s . AuthPath , "auth-path" , "Path to .kubernetes_auth file, specifying how to authenticate to API server." )
2015-05-08 20:26:27 +00:00
fs . MarkDeprecated ( "auth-path" , "will be removed in a future version" )
2015-05-12 03:44:13 +00:00
fs . Var ( & s . KubeConfig , "kubeconfig" , "Path to a kubeconfig file, specifying how to authenticate to API server (the master location is set by the api-servers flag)." )
2015-04-24 06:10:33 +00:00
fs . UintVar ( & s . CadvisorPort , "cadvisor-port" , s . CadvisorPort , "The port of the localhost cAdvisor endpoint" )
fs . IntVar ( & s . HealthzPort , "healthz-port" , s . HealthzPort , "The port of the localhost healthz endpoint" )
fs . Var ( & s . HealthzBindAddress , "healthz-bind-address" , "The IP address for the healthz server to serve on, defaulting to 127.0.0.1 (set to 0.0.0.0 for all interfaces)" )
fs . IntVar ( & s . OOMScoreAdj , "oom-score-adj" , s . OOMScoreAdj , "The oom_score_adj value for kubelet process. Values must be within the range [-1000, 1000]" )
2015-08-05 14:21:47 +00:00
fs . StringSliceVar ( & s . APIServerList , "api-servers" , [ ] string { } , "List of Kubernetes API servers for publishing events, and reading pods and services. (ip:port), comma separated." )
2015-05-20 21:21:03 +00:00
fs . BoolVar ( & s . RegisterNode , "register-node" , s . RegisterNode , "Register the node with the apiserver (defaults to true if --api-server is set)" )
2015-04-24 06:10:33 +00:00
fs . StringVar ( & s . ClusterDomain , "cluster-domain" , s . ClusterDomain , "Domain for this cluster. If set, kubelet will configure all containers to search this domain in addition to the host's search domains" )
fs . StringVar ( & s . MasterServiceNamespace , "master-service-namespace" , s . MasterServiceNamespace , "The namespace from which the kubernetes master services should be injected into pods" )
fs . Var ( & s . ClusterDNS , "cluster-dns" , "IP address for a cluster DNS server. If set, kubelet will configure all containers to use this for DNS resolution in addition to the host's DNS servers" )
fs . DurationVar ( & s . StreamingConnectionIdleTimeout , "streaming-connection-idle-timeout" , 0 , "Maximum time a streaming connection can be idle before the connection is automatically closed. Example: '5m'" )
fs . DurationVar ( & s . NodeStatusUpdateFrequency , "node-status-update-frequency" , s . NodeStatusUpdateFrequency , "Specifies how often kubelet posts node status to master. Note: be cautious when changing the constant, it must work with nodeMonitorGracePeriod in nodecontroller. Default: 10s" )
fs . IntVar ( & s . ImageGCHighThresholdPercent , "image-gc-high-threshold" , s . ImageGCHighThresholdPercent , "The percent of disk usage after which image garbage collection is always run. Default: 90%%" )
fs . IntVar ( & s . ImageGCLowThresholdPercent , "image-gc-low-threshold" , s . ImageGCLowThresholdPercent , "The percent of disk usage before which image garbage collection is never run. Lowest disk usage to garbage collect to. Default: 80%%" )
2015-05-12 08:24:08 +00:00
fs . IntVar ( & s . LowDiskSpaceThresholdMB , "low-diskspace-threshold-mb" , s . LowDiskSpaceThresholdMB , "The absolute free disk space, in MB, to maintain. When disk space falls below this threshold, new pods would be rejected. Default: 256" )
2015-04-24 06:10:33 +00:00
fs . StringVar ( & s . NetworkPluginName , "network-plugin" , s . NetworkPluginName , "<Warning: Alpha feature> The name of the network plugin to be invoked for various events in kubelet/pod lifecycle" )
2015-07-01 18:53:42 +00:00
fs . StringVar ( & s . NetworkPluginDir , "network-plugin-dir" , s . NetworkPluginDir , "<Warning: Alpha feature> The full path of the directory in which to search for network plugins" )
2015-04-24 06:10:33 +00:00
fs . StringVar ( & s . CloudProvider , "cloud-provider" , s . CloudProvider , "The provider for cloud services. Empty string for no provider." )
fs . StringVar ( & s . CloudConfigFile , "cloud-config" , s . CloudConfigFile , "The path to the cloud provider configuration file. Empty string for no configuration file." )
fs . StringVar ( & s . ResourceContainer , "resource-container" , s . ResourceContainer , "Absolute name of the resource-only container to create and run the Kubelet in (Default: /kubelet)." )
2015-05-13 22:50:23 +00:00
fs . StringVar ( & s . CgroupRoot , "cgroup_root" , s . CgroupRoot , "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." )
2015-05-08 06:26:07 +00:00
fs . StringVar ( & s . ContainerRuntime , "container_runtime" , s . ContainerRuntime , "The container runtime to use. Possible values: 'docker', 'rkt'. Default: 'docker'." )
2015-05-19 23:19:12 +00:00
fs . StringVar ( & s . SystemContainer , "system-container" , s . SystemContainer , "Optional resource-only container in which to place all non-kernel processes that are not already in a container. Empty for no container. Rolling back the flag requires a reboot. (Default: \"\")." )
2015-05-11 21:07:24 +00:00
fs . BoolVar ( & s . ConfigureCBR0 , "configure-cbr0" , s . ConfigureCBR0 , "If true, kubelet will configure cbr0 based on Node.Spec.PodCIDR." )
2015-07-09 23:08:40 +00:00
fs . IntVar ( & s . MaxPods , "max-pods" , 40 , "Number of Pods that can run on this Kubelet." )
2015-05-27 12:51:01 +00:00
fs . StringVar ( & s . DockerExecHandlerName , "docker-exec-handler" , s . DockerExecHandlerName , "Handler to use when executing a command in a container. Valid values are 'native' and 'nsenter'. Defaults to 'native'." )
2015-06-24 18:10:10 +00:00
fs . StringVar ( & s . PodCIDR , "pod-cidr" , "" , "The CIDR to use for pod IP addresses, only used in standalone mode. In cluster mode, this is obtained from the master." )
2015-04-11 16:45:45 +00:00
// Flags intended for testing, not recommended used in production environments.
2015-04-24 06:10:33 +00:00
fs . BoolVar ( & s . ReallyCrashForTesting , "really-crash-for-testing" , s . ReallyCrashForTesting , "If true, when panics occur crash. Intended for testing." )
fs . Float64Var ( & s . ChaosChance , "chaos-chance" , s . ChaosChance , "If > 0.0, introduce random client errors and latency. Intended for testing. [default=0.0]" )
2015-05-05 15:07:15 +00:00
fs . BoolVar ( & s . Containerized , "containerized" , s . Containerized , "Experimental support for running kubelet in a container. Intended for testing. [default=false]" )
2015-02-02 21:30:31 +00:00
}
2015-07-01 19:02:30 +00:00
// KubeletConfig returns a KubeletConfig suitable for being run, or an error if the server setup
// is not valid. It will not start any background processes.
func ( s * KubeletServer ) KubeletConfig ( ) ( * KubeletConfig , error ) {
hostNetworkSources , err := kubelet . GetValidatedSources ( strings . Split ( s . HostNetworkSources , "," ) )
if err != nil {
return nil , err
2015-02-02 21:30:31 +00:00
}
2015-07-01 19:02:30 +00:00
mounter := mount . New ( )
if s . Containerized {
glog . V ( 2 ) . Info ( "Running kubelet in containerized mode (experimental)" )
mounter = mount . NewNsenterMounter ( )
2015-02-02 21:30:31 +00:00
}
2015-07-01 19:02:30 +00:00
tlsOptions , err := s . InitializeTLS ( )
2015-03-10 05:39:00 +00:00
if err != nil {
2015-07-01 19:02:30 +00:00
return nil , err
}
var dockerExecHandler dockertools . ExecHandler
switch s . DockerExecHandlerName {
case "native" :
dockerExecHandler = & dockertools . NativeExecHandler { }
case "nsenter" :
dockerExecHandler = & dockertools . NsenterExecHandler { }
default :
glog . Warningf ( "Unknown Docker exec handler %q; defaulting to native" , s . DockerExecHandlerName )
dockerExecHandler = & dockertools . NativeExecHandler { }
2015-03-10 05:39:00 +00:00
}
2015-03-16 04:00:46 +00:00
imageGCPolicy := kubelet . ImageGCPolicy {
HighThresholdPercent : s . ImageGCHighThresholdPercent ,
LowThresholdPercent : s . ImageGCLowThresholdPercent ,
}
2015-03-23 22:31:13 +00:00
2015-05-12 08:24:08 +00:00
diskSpacePolicy := kubelet . DiskSpacePolicy {
DockerFreeDiskMB : s . LowDiskSpaceThresholdMB ,
RootFreeDiskMB : s . LowDiskSpaceThresholdMB ,
}
2015-03-23 22:31:13 +00:00
2015-07-30 16:28:47 +00:00
manifestURLHeader := make ( http . Header )
if s . ManifestURLHeader != "" {
pieces := strings . Split ( s . ManifestURLHeader , ":" )
if len ( pieces ) != 2 {
2015-07-01 19:02:30 +00:00
return nil , fmt . Errorf ( "manifest-url-header must have a single ':' key-value separator, got %q" , s . ManifestURLHeader )
2015-07-30 16:28:47 +00:00
}
manifestURLHeader . Set ( pieces [ 0 ] , pieces [ 1 ] )
}
2015-07-01 19:02:30 +00:00
return & KubeletConfig {
2015-01-08 20:41:38 +00:00
Address : s . Address ,
AllowPrivileged : s . AllowPrivileged ,
2015-03-24 23:09:16 +00:00
HostNetworkSources : hostNetworkSources ,
2015-01-08 20:41:38 +00:00
HostnameOverride : s . HostnameOverride ,
RootDirectory : s . RootDirectory ,
ConfigFile : s . Config ,
ManifestURL : s . ManifestURL ,
2015-07-30 16:28:47 +00:00
ManifestURLHeader : manifestURLHeader ,
2015-01-08 20:41:38 +00:00
FileCheckFrequency : s . FileCheckFrequency ,
HTTPCheckFrequency : s . HTTPCheckFrequency ,
PodInfraContainerImage : s . PodInfraContainerImage ,
SyncFrequency : s . SyncFrequency ,
RegistryPullQPS : s . RegistryPullQPS ,
RegistryBurst : s . RegistryBurst ,
MinimumGCAge : s . MinimumGCAge ,
2015-03-14 17:13:20 +00:00
MaxPerPodContainerCount : s . MaxPerPodContainerCount ,
2015-01-08 20:41:38 +00:00
MaxContainerCount : s . MaxContainerCount ,
2015-05-20 21:21:03 +00:00
RegisterNode : s . RegisterNode ,
2015-06-12 17:20:26 +00:00
StandaloneMode : ( len ( s . APIServerList ) == 0 ) ,
2015-01-08 20:41:38 +00:00
ClusterDomain : s . ClusterDomain ,
ClusterDNS : s . ClusterDNS ,
Runonce : s . RunOnce ,
Port : s . Port ,
2015-04-02 04:41:32 +00:00
ReadOnlyPort : s . ReadOnlyPort ,
2015-07-01 19:02:30 +00:00
CadvisorInterface : nil , // launches background processes, not set here
2015-01-08 20:41:38 +00:00
EnableServer : s . EnableServer ,
EnableDebuggingHandlers : s . EnableDebuggingHandlers ,
DockerClient : dockertools . ConnectToDockerOrDie ( s . DockerEndpoint ) ,
2015-07-01 19:02:30 +00:00
KubeClient : nil ,
2015-01-08 20:41:38 +00:00
MasterServiceNamespace : s . MasterServiceNamespace ,
VolumePlugins : ProbeVolumePlugins ( ) ,
2015-07-01 18:53:42 +00:00
NetworkPlugins : ProbeNetworkPlugins ( s . NetworkPluginDir ) ,
2015-03-19 23:14:13 +00:00
NetworkPluginName : s . NetworkPluginName ,
2015-01-08 20:41:38 +00:00
StreamingConnectionIdleTimeout : s . StreamingConnectionIdleTimeout ,
2015-04-01 23:19:17 +00:00
TLSOptions : tlsOptions ,
2015-03-16 04:00:46 +00:00
ImageGCPolicy : imageGCPolicy ,
2015-05-12 08:24:08 +00:00
DiskSpacePolicy : diskSpacePolicy ,
2015-07-01 19:02:30 +00:00
Cloud : nil , // cloud provider might start background processes
2015-04-09 08:32:18 +00:00
NodeStatusUpdateFrequency : s . NodeStatusUpdateFrequency ,
2015-04-14 00:30:57 +00:00
ResourceContainer : s . ResourceContainer ,
2015-04-24 00:07:52 +00:00
CgroupRoot : s . CgroupRoot ,
2015-05-01 21:24:07 +00:00
ContainerRuntime : s . ContainerRuntime ,
2015-05-05 15:07:15 +00:00
Mounter : mounter ,
2015-05-12 16:59:02 +00:00
DockerDaemonContainer : s . DockerDaemonContainer ,
2015-05-19 23:19:12 +00:00
SystemContainer : s . SystemContainer ,
2015-05-11 21:07:24 +00:00
ConfigureCBR0 : s . ConfigureCBR0 ,
2015-06-24 18:10:10 +00:00
PodCIDR : s . PodCIDR ,
2015-03-17 14:43:49 +00:00
MaxPods : s . MaxPods ,
2015-05-27 12:51:01 +00:00
DockerExecHandler : dockerExecHandler ,
2015-07-01 19:02:30 +00:00
} , nil
}
// Run runs the specified KubeletServer for the given KubeletConfig. This should never exit.
// The kcfg argument may be nil - if so, it is initialized from the settings on KubeletServer.
// Otherwise, the caller is assumed to have set up the KubeletConfig object and all defaults
// will be ignored.
func ( s * KubeletServer ) Run ( kcfg * KubeletConfig ) error {
if kcfg == nil {
cfg , err := s . KubeletConfig ( )
if err != nil {
return err
}
kcfg = cfg
clientConfig , err := s . CreateAPIServerClientConfig ( )
if err == nil {
kcfg . KubeClient , err = client . New ( clientConfig )
}
if err != nil && len ( s . APIServerList ) > 0 {
glog . Warningf ( "No API client: %v" , err )
}
cloud , err := cloudprovider . InitCloudProvider ( s . CloudProvider , s . CloudConfigFile )
if err != nil {
return err
}
glog . V ( 2 ) . Infof ( "Successfully initialized cloud provider: %q from the config file: %q\n" , s . CloudProvider , s . CloudConfigFile )
kcfg . Cloud = cloud
}
if kcfg . CadvisorInterface == nil {
ca , err := cadvisor . New ( s . CadvisorPort )
if err != nil {
return err
}
kcfg . CadvisorInterface = ca
}
util . ReallyCrash = s . ReallyCrashForTesting
rand . Seed ( time . Now ( ) . UTC ( ) . UnixNano ( ) )
credentialprovider . SetPreferredDockercfgPath ( s . RootDirectory )
glog . V ( 2 ) . Infof ( "Using root directory: %v" , s . RootDirectory )
// TODO(vmarmol): Do this through container config.
if err := util . ApplyOomScoreAdj ( 0 , s . OOMScoreAdj ) ; err != nil {
glog . Warning ( err )
2015-02-02 21:30:31 +00:00
}
2015-07-01 19:02:30 +00:00
if err := RunKubelet ( kcfg , nil ) ; err != nil {
2015-05-16 20:12:33 +00:00
return err
}
2015-02-02 21:30:31 +00:00
2015-03-30 21:09:50 +00:00
if s . HealthzPort > 0 {
healthz . DefaultHealthz ( )
go util . Forever ( func ( ) {
err := http . ListenAndServe ( net . JoinHostPort ( s . HealthzBindAddress . String ( ) , strconv . Itoa ( s . HealthzPort ) ) , nil )
if err != nil {
glog . Errorf ( "Starting health server failed: %v" , err )
}
} , 5 * time . Second )
}
2015-05-16 20:12:33 +00:00
if s . RunOnce {
return nil
}
2015-02-02 21:30:31 +00:00
2015-05-16 20:12:33 +00:00
// run forever
select { }
2015-02-02 21:30:31 +00:00
}
2015-06-05 11:45:40 +00:00
// InitializeTLS checks for a configured TLSCertFile and TLSPrivateKeyFile: if unspecified a new self-signed
// certificate and key file are generated. Returns a configured kubelet.TLSOptions object.
func ( s * KubeletServer ) InitializeTLS ( ) ( * kubelet . TLSOptions , error ) {
if s . TLSCertFile == "" && s . TLSPrivateKeyFile == "" {
s . TLSCertFile = path . Join ( s . CertDirectory , "kubelet.crt" )
s . TLSPrivateKeyFile = path . Join ( s . CertDirectory , "kubelet.key" )
2015-07-03 17:21:29 +00:00
if err := util . GenerateSelfSignedCert ( nodeutil . GetHostname ( s . HostnameOverride ) , s . TLSCertFile , s . TLSPrivateKeyFile , nil , nil ) ; err != nil {
2015-06-05 11:45:40 +00:00
return nil , fmt . Errorf ( "unable to generate self signed cert: %v" , err )
}
glog . V ( 4 ) . Infof ( "Using self-signed cert (%s, %s)" , s . TLSCertFile , s . TLSPrivateKeyFile )
}
tlsOptions := & kubelet . TLSOptions {
Config : & tls . Config {
// Change default from SSLv3 to TLSv1.0 (because of POODLE vulnerability).
MinVersion : tls . VersionTLS10 ,
// Populate PeerCertificates in requests, but don't yet reject connections without certificates.
ClientAuth : tls . RequestClientCert ,
} ,
CertFile : s . TLSCertFile ,
KeyFile : s . TLSPrivateKeyFile ,
}
return tlsOptions , nil
}
2015-05-12 03:44:13 +00:00
func ( s * KubeletServer ) authPathClientConfig ( useDefaults bool ) ( * client . Config , error ) {
authInfo , err := clientauth . LoadFromFile ( s . AuthPath . Value ( ) )
if err != nil && ! useDefaults {
return nil , err
}
// If loading the default auth path, for backwards compatibility keep going
// with the default auth.
2015-01-07 15:18:56 +00:00
if err != nil {
2015-05-12 03:44:13 +00:00
glog . Warningf ( "Could not load kubernetes auth path %s: %v. Continuing with defaults." , s . AuthPath , err )
2015-01-31 02:07:07 +00:00
}
if authInfo == nil {
// authInfo didn't load correctly - continue with defaults.
authInfo = & clientauth . Info { }
2015-01-07 15:18:56 +00:00
}
2015-05-12 03:44:13 +00:00
authConfig , err := authInfo . MergeWithConfig ( client . Config { } )
2015-01-07 15:18:56 +00:00
if err != nil {
return nil , err
}
2015-05-12 03:44:13 +00:00
authConfig . Host = s . APIServerList [ 0 ]
return & authConfig , nil
}
func ( s * KubeletServer ) kubeconfigClientConfig ( ) ( * client . Config , error ) {
return clientcmd . NewNonInteractiveDeferredLoadingClientConfig (
& clientcmd . ClientConfigLoadingRules { ExplicitPath : s . KubeConfig . Value ( ) } ,
& clientcmd . ConfigOverrides { ClusterInfo : clientcmdapi . Cluster { Server : s . APIServerList [ 0 ] } } ) . ClientConfig ( )
}
// createClientConfig creates a client configuration from the command line
// arguments. If either --auth-path or --kubeconfig is explicitly set, it
// will be used (setting both is an error). If neither are set first attempt
// to load the default kubeconfig file, then the default auth path file, and
// fall back to the default auth (none) without an error.
// TODO(roberthbailey): Remove support for --auth-path
func ( s * KubeletServer ) createClientConfig ( ) ( * client . Config , error ) {
if s . KubeConfig . Provided ( ) && s . AuthPath . Provided ( ) {
return nil , fmt . Errorf ( "cannot specify both --kubeconfig and --auth-path" )
}
if s . KubeConfig . Provided ( ) {
return s . kubeconfigClientConfig ( )
} else if s . AuthPath . Provided ( ) {
return s . authPathClientConfig ( false )
}
// Try the kubeconfig default first, falling back to the auth path default.
clientConfig , err := s . kubeconfigClientConfig ( )
if err != nil {
glog . Warningf ( "Could not load kubeconfig file %s: %v. Trying auth path instead." , s . KubeConfig , err )
return s . authPathClientConfig ( true )
}
return clientConfig , nil
}
2015-06-08 19:19:17 +00:00
// CreateAPIServerClientConfig generates a client.Config from command line flags,
// including api-server-list, via createClientConfig and then injects chaos into
// the configuration via addChaosToClientConfig. This func is exported to support
// integration with third party kubelet extensions (e.g. kubernetes-mesos).
func ( s * KubeletServer ) CreateAPIServerClientConfig ( ) ( * client . Config , error ) {
2015-02-02 21:30:31 +00:00
if len ( s . APIServerList ) < 1 {
return nil , fmt . Errorf ( "no api servers specified" )
2015-01-07 15:18:56 +00:00
}
// TODO: adapt Kube client to support LB over several servers
2015-02-02 21:30:31 +00:00
if len ( s . APIServerList ) > 1 {
2015-01-18 07:32:34 +00:00
glog . Infof ( "Multiple api servers specified. Picking first one" )
2015-01-07 15:18:56 +00:00
}
2015-04-11 16:45:45 +00:00
2015-05-12 03:44:13 +00:00
clientConfig , err := s . createClientConfig ( )
if err != nil {
return nil , err
}
s . addChaosToClientConfig ( clientConfig )
2015-06-08 19:19:17 +00:00
return clientConfig , nil
2015-01-07 15:18:56 +00:00
}
2015-04-11 16:45:45 +00:00
// addChaosToClientConfig injects random errors into client connections if configured.
func ( s * KubeletServer ) addChaosToClientConfig ( config * client . Config ) {
if s . ChaosChance != 0.0 {
config . WrapTransport = func ( rt http . RoundTripper ) http . RoundTripper {
seed := chaosclient . NewSeed ( 1 )
// TODO: introduce a standard chaos package with more tunables - this is just a proof of concept
// TODO: introduce random latency and stalls
return chaosclient . NewChaosRoundTripper ( rt , chaosclient . LogChaos , seed . P ( s . ChaosChance , chaosclient . ErrSimulatedConnectionResetByPeer ) )
}
}
}
2015-03-11 23:40:20 +00:00
// SimpleRunKubelet is a simple way to start a Kubelet talking to dockerEndpoint, using an API Client.
2014-11-27 21:28:56 +00:00
// Under the hood it calls RunKubelet (below)
2015-03-23 03:02:18 +00:00
func SimpleKubelet ( client * client . Client ,
2015-01-08 15:25:14 +00:00
dockerClient dockertools . DockerInterface ,
hostname , rootDir , manifestURL , address string ,
port uint ,
2014-11-23 15:47:25 +00:00
masterServiceNamespace string ,
2015-03-19 05:18:31 +00:00
volumePlugins [ ] volume . VolumePlugin ,
2015-03-10 05:39:00 +00:00
tlsOptions * kubelet . TLSOptions ,
2015-03-09 22:46:47 +00:00
cadvisorInterface cadvisor . Interface ,
2015-03-23 22:31:13 +00:00
configFilePath string ,
2015-04-21 00:26:40 +00:00
cloud cloudprovider . Interface ,
2015-04-27 20:03:55 +00:00
osInterface kubecontainer . OSInterface ) * KubeletConfig {
2015-03-16 04:00:46 +00:00
imageGCPolicy := kubelet . ImageGCPolicy {
HighThresholdPercent : 90 ,
LowThresholdPercent : 80 ,
}
2015-05-12 08:24:08 +00:00
diskSpacePolicy := kubelet . DiskSpacePolicy {
DockerFreeDiskMB : 256 ,
RootFreeDiskMB : 256 ,
}
2014-11-27 21:28:56 +00:00
kcfg := KubeletConfig {
2015-01-21 00:59:26 +00:00
KubeClient : client ,
DockerClient : dockerClient ,
HostnameOverride : hostname ,
RootDirectory : rootDir ,
ManifestURL : manifestURL ,
2015-04-09 01:56:58 +00:00
PodInfraContainerImage : dockertools . PodInfraContainerImage ,
2015-03-20 16:37:08 +00:00
Port : port ,
Address : util . IP ( net . ParseIP ( address ) ) ,
EnableServer : true ,
EnableDebuggingHandlers : true ,
HTTPCheckFrequency : 1 * time . Second ,
FileCheckFrequency : 1 * time . Second ,
SyncFrequency : 3 * time . Second ,
MinimumGCAge : 10 * time . Second ,
2015-05-20 00:30:16 +00:00
MaxPerPodContainerCount : 2 ,
2015-03-20 16:37:08 +00:00
MaxContainerCount : 100 ,
2015-05-20 21:21:03 +00:00
RegisterNode : true ,
2015-03-20 16:37:08 +00:00
MasterServiceNamespace : masterServiceNamespace ,
VolumePlugins : volumePlugins ,
TLSOptions : tlsOptions ,
CadvisorInterface : cadvisorInterface ,
ConfigFile : configFilePath ,
ImageGCPolicy : imageGCPolicy ,
2015-05-12 08:24:08 +00:00
DiskSpacePolicy : diskSpacePolicy ,
2015-03-23 22:31:13 +00:00
Cloud : cloud ,
2015-04-07 19:36:09 +00:00
NodeStatusUpdateFrequency : 10 * time . Second ,
2015-04-14 00:30:57 +00:00
ResourceContainer : "/kubelet" ,
2015-04-21 00:26:40 +00:00
OSInterface : osInterface ,
2015-05-13 22:50:23 +00:00
CgroupRoot : "" ,
2015-05-01 21:24:07 +00:00
ContainerRuntime : "docker" ,
2015-05-04 14:43:10 +00:00
Mounter : mount . New ( ) ,
2015-05-12 16:59:02 +00:00
DockerDaemonContainer : "/docker-daemon" ,
2015-05-19 23:19:12 +00:00
SystemContainer : "" ,
2015-03-17 14:43:49 +00:00
MaxPods : 32 ,
2015-05-27 12:51:01 +00:00
DockerExecHandler : & dockertools . NativeExecHandler { } ,
2014-11-27 21:28:56 +00:00
}
2015-03-23 03:02:18 +00:00
return & kcfg
2014-11-27 21:28:56 +00:00
}
// RunKubelet is responsible for setting up and running a kubelet. It is used in three different applications:
// 1 Integration tests
// 2 Kubelet binary
// 3 Standalone 'kubernetes' binary
// Eventually, #2 will be replaced with instances of #3
2015-05-16 20:12:33 +00:00
func RunKubelet ( kcfg * KubeletConfig , builder KubeletBuilder ) error {
2015-05-26 23:13:00 +00:00
kcfg . Hostname = nodeutil . GetHostname ( kcfg . HostnameOverride )
2015-06-12 15:42:38 +00:00
2015-06-17 20:40:34 +00:00
if len ( kcfg . NodeName ) == 0 {
2015-06-12 15:42:38 +00:00
// Query the cloud provider for our node name, default to Hostname
nodeName := kcfg . Hostname
if kcfg . Cloud != nil {
var err error
instances , ok := kcfg . Cloud . Instances ( )
if ! ok {
return fmt . Errorf ( "failed to get instances from cloud provider" )
}
nodeName , err = instances . CurrentNodeName ( kcfg . Hostname )
if err != nil {
return fmt . Errorf ( "error fetching current instance name from cloud provider: %v" , err )
}
glog . V ( 2 ) . Infof ( "cloud provider determined current node name to be %s" , nodeName )
}
kcfg . NodeName = nodeName
}
2015-06-12 15:40:34 +00:00
2015-03-17 04:03:07 +00:00
eventBroadcaster := record . NewBroadcaster ( )
2015-06-12 15:40:34 +00:00
kcfg . Recorder = eventBroadcaster . NewRecorder ( api . EventSource { Component : "kubelet" , Host : kcfg . NodeName } )
2015-06-17 20:40:34 +00:00
eventBroadcaster . StartLogging ( glog . V ( 3 ) . Infof )
2015-01-07 15:18:56 +00:00
if kcfg . KubeClient != nil {
2015-05-16 20:12:33 +00:00
glog . V ( 4 ) . Infof ( "Sending events to api server." )
2015-03-17 04:03:07 +00:00
eventBroadcaster . StartRecordingToSink ( kcfg . KubeClient . Events ( "" ) )
2015-01-07 15:18:56 +00:00
} else {
2015-05-16 20:12:33 +00:00
glog . Warning ( "No api server defined - no events will be sent to API server." )
2015-01-07 15:18:56 +00:00
}
2015-07-29 05:00:15 +00:00
capabilities . Setup ( kcfg . AllowPrivileged , kcfg . HostNetworkSources , 0 )
2014-11-27 21:28:56 +00:00
2015-01-27 20:16:47 +00:00
credentialprovider . SetPreferredDockercfgPath ( kcfg . RootDirectory )
2015-03-26 12:31:54 +00:00
if builder == nil {
builder = createAndInitKubelet
}
2015-04-21 00:26:40 +00:00
if kcfg . OSInterface == nil {
2015-04-27 20:03:55 +00:00
kcfg . OSInterface = kubecontainer . RealOS { }
2015-04-21 00:26:40 +00:00
}
2015-03-26 12:31:54 +00:00
k , podCfg , err := builder ( kcfg )
2015-01-07 02:31:40 +00:00
if err != nil {
2015-05-16 20:12:33 +00:00
return fmt . Errorf ( "failed to create kubelet: %v" , err )
2015-01-07 02:31:40 +00:00
}
2014-11-27 21:28:56 +00:00
// process pods and exit.
if kcfg . Runonce {
2015-02-02 21:30:31 +00:00
if _ , err := k . RunOnce ( podCfg . Updates ( ) ) ; err != nil {
2015-05-16 20:12:33 +00:00
return fmt . Errorf ( "runonce failed: %v" , err )
2014-11-27 21:28:56 +00:00
}
2015-05-16 20:12:33 +00:00
glog . Infof ( "Started kubelet as runonce" )
2014-11-27 21:28:56 +00:00
} else {
2015-02-02 21:30:31 +00:00
startKubelet ( k , podCfg , kcfg )
2015-05-16 20:12:33 +00:00
glog . Infof ( "Started kubelet" )
2014-11-27 21:28:56 +00:00
}
2015-05-16 20:12:33 +00:00
return nil
2014-11-27 21:28:56 +00:00
}
2015-03-26 12:31:54 +00:00
func startKubelet ( k KubeletBootstrap , podCfg * config . PodConfig , kc * KubeletConfig ) {
2014-11-27 21:28:56 +00:00
// start the kubelet
2015-02-02 21:30:31 +00:00
go util . Forever ( func ( ) { k . Run ( podCfg . Updates ( ) ) } , 0 )
2014-11-27 21:28:56 +00:00
// start the kubelet server
if kc . EnableServer {
go util . Forever ( func ( ) {
2015-03-26 12:31:54 +00:00
k . ListenAndServe ( net . IP ( kc . Address ) , kc . Port , kc . TLSOptions , kc . EnableDebuggingHandlers )
2014-11-27 21:28:56 +00:00
} , 0 )
}
2015-04-02 04:41:32 +00:00
if kc . ReadOnlyPort > 0 {
go util . Forever ( func ( ) {
2015-03-26 12:31:54 +00:00
k . ListenAndServeReadOnly ( net . IP ( kc . Address ) , kc . ReadOnlyPort )
2015-04-02 04:41:32 +00:00
} , 0 )
}
2014-11-27 21:28:56 +00:00
}
func makePodSourceConfig ( kc * KubeletConfig ) * config . PodConfig {
// source of all configuration
2015-03-03 06:06:20 +00:00
cfg := config . NewPodConfig ( config . PodConfigNotificationSnapshotAndUpdates , kc . Recorder )
2014-11-27 21:28:56 +00:00
// define file config source
if kc . ConfigFile != "" {
2014-12-17 05:11:27 +00:00
glog . Infof ( "Adding manifest file: %v" , kc . ConfigFile )
2015-06-12 15:40:34 +00:00
config . NewSourceFile ( kc . ConfigFile , kc . NodeName , kc . FileCheckFrequency , cfg . Channel ( kubelet . FileSource ) )
2014-11-27 21:28:56 +00:00
}
// define url config source
if kc . ManifestURL != "" {
2015-07-30 16:28:47 +00:00
glog . Infof ( "Adding manifest url %q with HTTP header %v" , kc . ManifestURL , kc . ManifestURLHeader )
config . NewSourceURL ( kc . ManifestURL , kc . ManifestURLHeader , kc . NodeName , kc . HTTPCheckFrequency , cfg . Channel ( kubelet . HTTPSource ) )
2014-11-27 21:28:56 +00:00
}
2015-01-17 00:38:09 +00:00
if kc . KubeClient != nil {
2014-11-21 21:14:30 +00:00
glog . Infof ( "Watching apiserver" )
2015-06-12 15:40:34 +00:00
config . NewSourceApiserver ( kc . KubeClient , kc . NodeName , cfg . Channel ( kubelet . ApiserverSource ) )
2014-11-21 21:14:30 +00:00
}
2014-11-27 21:28:56 +00:00
return cfg
}
2015-02-02 21:30:31 +00:00
// KubeletConfig is all of the parameters necessary for running a kubelet.
// TODO: This should probably be merged with KubeletServer. The extra object is a consequence of refactoring.
2014-11-27 21:28:56 +00:00
type KubeletConfig struct {
2015-01-08 20:41:38 +00:00
KubeClient * client . Client
DockerClient dockertools . DockerInterface
2015-03-10 05:39:00 +00:00
CadvisorInterface cadvisor . Interface
2015-01-08 20:41:38 +00:00
Address util . IP
AllowPrivileged bool
2015-03-24 23:09:16 +00:00
HostNetworkSources [ ] string
2015-01-08 20:41:38 +00:00
HostnameOverride string
RootDirectory string
ConfigFile string
ManifestURL string
2015-07-30 16:28:47 +00:00
ManifestURLHeader http . Header
2015-01-08 20:41:38 +00:00
FileCheckFrequency time . Duration
HTTPCheckFrequency time . Duration
Hostname string
2015-06-12 15:40:34 +00:00
NodeName string
2015-01-08 20:41:38 +00:00
PodInfraContainerImage string
SyncFrequency time . Duration
RegistryPullQPS float64
RegistryBurst int
MinimumGCAge time . Duration
2015-03-14 17:13:20 +00:00
MaxPerPodContainerCount int
2015-01-08 20:41:38 +00:00
MaxContainerCount int
2015-05-20 21:21:03 +00:00
RegisterNode bool
2015-06-12 17:20:26 +00:00
StandaloneMode bool
2015-01-08 20:41:38 +00:00
ClusterDomain string
ClusterDNS util . IP
EnableServer bool
EnableDebuggingHandlers bool
Port uint
2015-04-02 04:41:32 +00:00
ReadOnlyPort uint
2015-01-08 20:41:38 +00:00
Runonce bool
MasterServiceNamespace string
2015-03-19 05:18:31 +00:00
VolumePlugins [ ] volume . VolumePlugin
2015-03-19 23:14:13 +00:00
NetworkPlugins [ ] network . NetworkPlugin
NetworkPluginName string
2015-01-08 20:41:38 +00:00
StreamingConnectionIdleTimeout time . Duration
2015-03-03 06:06:20 +00:00
Recorder record . EventRecorder
2015-03-05 21:30:52 +00:00
TLSOptions * kubelet . TLSOptions
2015-03-16 04:00:46 +00:00
ImageGCPolicy kubelet . ImageGCPolicy
2015-05-12 08:24:08 +00:00
DiskSpacePolicy kubelet . DiskSpacePolicy
2015-03-23 22:31:13 +00:00
Cloud cloudprovider . Interface
2015-03-31 11:17:12 +00:00
NodeStatusUpdateFrequency time . Duration
2015-04-14 00:30:57 +00:00
ResourceContainer string
2015-04-27 20:03:55 +00:00
OSInterface kubecontainer . OSInterface
2015-04-24 00:07:52 +00:00
CgroupRoot string
2015-05-01 21:24:07 +00:00
ContainerRuntime string
2015-05-04 14:43:10 +00:00
Mounter mount . Interface
2015-05-12 16:59:02 +00:00
DockerDaemonContainer string
2015-05-19 23:19:12 +00:00
SystemContainer string
2015-05-11 21:07:24 +00:00
ConfigureCBR0 bool
2015-06-24 18:10:10 +00:00
PodCIDR string
2015-03-17 14:43:49 +00:00
MaxPods int
2015-05-27 12:51:01 +00:00
DockerExecHandler dockertools . ExecHandler
2014-11-27 21:28:56 +00:00
}
2015-03-26 12:31:54 +00:00
func createAndInitKubelet ( kc * KubeletConfig ) ( k KubeletBootstrap , pc * config . PodConfig , err error ) {
2014-11-27 21:28:56 +00:00
// TODO: block until all sources have delivered at least one update to the channel, or break the sync loop
// up into "per source" synchronizations
2015-02-27 18:44:44 +00:00
// TODO: KubeletConfig.KubeClient should be a client interface, but client interface misses certain methods
// used by kubelet. Since NewMainKubelet expects a client interface, we need to make sure we are not passing
// a nil pointer to it when what we really want is a nil interface.
var kubeClient client . Interface
2015-03-26 12:31:54 +00:00
if kc . KubeClient != nil {
2015-02-27 18:44:44 +00:00
kubeClient = kc . KubeClient
}
2015-03-06 07:56:30 +00:00
2015-03-14 17:13:20 +00:00
gcPolicy := kubelet . ContainerGCPolicy {
MinAge : kc . MinimumGCAge ,
MaxPerPodContainer : kc . MaxPerPodContainerCount ,
MaxContainers : kc . MaxContainerCount ,
}
2015-03-26 12:31:54 +00:00
pc = makePodSourceConfig ( kc )
k , err = kubelet . NewMainKubelet (
2014-11-27 21:28:56 +00:00
kc . Hostname ,
2015-06-12 15:40:34 +00:00
kc . NodeName ,
2014-11-27 21:28:56 +00:00
kc . DockerClient ,
2015-02-27 18:44:44 +00:00
kubeClient ,
2014-11-27 21:28:56 +00:00
kc . RootDirectory ,
2015-01-21 00:59:26 +00:00
kc . PodInfraContainerImage ,
2014-11-27 21:28:56 +00:00
kc . SyncFrequency ,
float32 ( kc . RegistryPullQPS ) ,
kc . RegistryBurst ,
2015-03-14 17:13:20 +00:00
gcPolicy ,
2015-03-05 18:49:36 +00:00
pc . SeenAllSources ,
2015-05-20 21:21:03 +00:00
kc . RegisterNode ,
2015-06-12 17:20:26 +00:00
kc . StandaloneMode ,
2014-11-12 05:21:40 +00:00
kc . ClusterDomain ,
2015-01-08 15:25:14 +00:00
net . IP ( kc . ClusterDNS ) ,
2014-11-23 15:47:25 +00:00
kc . MasterServiceNamespace ,
2015-01-08 20:41:38 +00:00
kc . VolumePlugins ,
2015-03-19 23:14:13 +00:00
kc . NetworkPlugins ,
kc . NetworkPluginName ,
2015-03-03 06:06:20 +00:00
kc . StreamingConnectionIdleTimeout ,
2015-03-06 07:56:30 +00:00
kc . Recorder ,
2015-03-10 05:39:00 +00:00
kc . CadvisorInterface ,
2015-03-23 22:31:13 +00:00
kc . ImageGCPolicy ,
2015-05-12 08:24:08 +00:00
kc . DiskSpacePolicy ,
2015-03-31 11:17:12 +00:00
kc . Cloud ,
2015-04-14 00:30:57 +00:00
kc . NodeStatusUpdateFrequency ,
2015-04-21 00:26:40 +00:00
kc . ResourceContainer ,
2015-04-24 00:07:52 +00:00
kc . OSInterface ,
2015-05-01 21:24:07 +00:00
kc . CgroupRoot ,
2015-05-04 14:43:10 +00:00
kc . ContainerRuntime ,
2015-05-12 16:59:02 +00:00
kc . Mounter ,
2015-05-11 21:07:24 +00:00
kc . DockerDaemonContainer ,
2015-05-19 23:19:12 +00:00
kc . SystemContainer ,
2015-03-17 14:43:49 +00:00
kc . ConfigureCBR0 ,
2015-06-24 18:10:10 +00:00
kc . PodCIDR ,
2015-05-27 12:51:01 +00:00
kc . MaxPods ,
kc . DockerExecHandler )
2014-11-27 21:28:56 +00:00
2015-01-07 02:31:40 +00:00
if err != nil {
2015-03-26 12:31:54 +00:00
return nil , nil , err
2015-01-07 02:31:40 +00:00
}
2014-11-27 21:28:56 +00:00
k . BirthCry ( )
2015-03-16 04:00:46 +00:00
k . StartGarbageCollection ( )
2014-10-27 17:04:39 +00:00
2015-03-26 12:31:54 +00:00
return k , pc , nil
2014-10-27 17:04:39 +00:00
}