github.com/deemoprobe/k8s-first-commit@v0.0.0-20230430165612-a541f1982be3/cmd/kubelet/kubelet.go (about) 1 /* 2 Copyright 2014 Google Inc. All rights reserved. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 // The kubelet binary is responsible for maintaining a set of containers on a particular host VM. 17 // It sync's data from both configuration file as well as from a quorum of etcd servers. 18 // It then queries Docker to see what is currently running. It synchronizes the configuration data, 19 // with the running set of containers by starting or stopping Docker containers. 20 package main 21 22 import ( 23 "flag" 24 "log" 25 "math/rand" 26 "os" 27 "time" 28 29 "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet" 30 "github.com/coreos/go-etcd/etcd" 31 "github.com/fsouza/go-dockerclient" 32 ) 33 34 var ( 35 file = flag.String("config", "", "Path to the config file") 36 etcd_servers = flag.String("etcd_servers", "", "Url of etcd servers in the cluster") 37 syncFrequency = flag.Duration("sync_frequency", 10*time.Second, "Max seconds between synchronizing running containers and config") 38 fileCheckFrequency = flag.Duration("file_check_frequency", 20*time.Second, "Seconds between checking file for new data") 39 httpCheckFrequency = flag.Duration("http_check_frequency", 20*time.Second, "Seconds between checking http for new data") 40 manifest_url = flag.String("manifest_url", "", "URL for accessing the container manifest") 41 address = flag.String("address", "127.0.0.1", "The address for the info server to serve on") 42 port = flag.Uint("port", 10250, "The port for the info server to serve on") 43 ) 44 45 const dockerBinary = "/usr/bin/docker" 46 47 func main() { 48 flag.Parse() 49 rand.Seed(time.Now().UTC().UnixNano()) 50 51 // Set up logger for etcd client 52 etcd.SetLogger(log.New(os.Stderr, "etcd ", log.LstdFlags)) 53 54 endpoint := "unix:///var/run/docker.sock" 55 dockerClient, err := docker.NewClient(endpoint) 56 if err != nil { 57 log.Fatal("Couldn't connnect to docker.") 58 } 59 60 my_kubelet := kubelet.Kubelet{ 61 DockerClient: dockerClient, 62 FileCheckFrequency: *fileCheckFrequency, 63 SyncFrequency: *syncFrequency, 64 HTTPCheckFrequency: *httpCheckFrequency, 65 } 66 my_kubelet.RunKubelet(*file, *manifest_url, *etcd_servers, *address, *port) 67 }