mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 22:17:14 +00:00
commit
1ddc012b17
@ -1,3 +1,5 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
# Copyright 2014 Google Inc. All rights reserved.
|
# Copyright 2014 Google Inc. All rights reserved.
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
@ -33,8 +35,7 @@ function make-binaries() {
|
|||||||
apiserver
|
apiserver
|
||||||
controller-manager
|
controller-manager
|
||||||
kubelet
|
kubelet
|
||||||
kubecfg
|
kubecfg"
|
||||||
localkube"
|
|
||||||
|
|
||||||
ARCH_TARGET="${KUBE_TARGET}/${GOOS}/${GOARCH}"
|
ARCH_TARGET="${KUBE_TARGET}/${GOOS}/${GOARCH}"
|
||||||
mkdir -p "${ARCH_TARGET}"
|
mkdir -p "${ARCH_TARGET}"
|
||||||
|
@ -1,114 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2014 Google Inc. All rights reserved.
|
|
||||||
|
|
||||||
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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// An all-in-one binary for standing up a fake Kubernetes cluster on your
|
|
||||||
// local machine.
|
|
||||||
// Assumes that there is a pre-existing etcd server running on localhost.
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"flag"
|
|
||||||
"fmt"
|
|
||||||
"math/rand"
|
|
||||||
"net"
|
|
||||||
"strconv"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/controller"
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet"
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/master"
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
|
||||||
"github.com/coreos/go-etcd/etcd"
|
|
||||||
"github.com/fsouza/go-dockerclient"
|
|
||||||
"github.com/golang/glog"
|
|
||||||
)
|
|
||||||
|
|
||||||
// kubelet flags
|
|
||||||
var (
|
|
||||||
file = flag.String("config", "", "Path to the config file/dir")
|
|
||||||
syncFrequency = flag.Duration("sync_frequency", 10*time.Second, "Max period between synchronizing running containers and config")
|
|
||||||
fileCheckFrequency = flag.Duration("file_check_frequency", 20*time.Second, "Duration between checking file for new data")
|
|
||||||
httpCheckFrequency = flag.Duration("http_check_frequency", 20*time.Second, "Duration between checking http for new data")
|
|
||||||
manifestUrl = flag.String("manifest_url", "", "URL for accessing the container manifest")
|
|
||||||
kubeletAddress = flag.String("kubelet_address", "127.0.0.1", "The address for the kubelet info server to serve on")
|
|
||||||
kubeletPort = flag.Uint("kubelet_port", 10250, "The port for the kubelete info server to serve on")
|
|
||||||
)
|
|
||||||
|
|
||||||
// master flags
|
|
||||||
var (
|
|
||||||
masterPort = flag.Uint("master_port", 8080, "The port for the master to listen on. Default 8080.")
|
|
||||||
masterAddress = flag.String("master_address", "127.0.0.1", "The address for the master to listen to. Default 127.0.0.1")
|
|
||||||
apiPrefix = flag.String("api_prefix", "/api/v1beta1", "The prefix for API requests on the server. Default '/api/v1beta1'")
|
|
||||||
)
|
|
||||||
|
|
||||||
// flags that affect both
|
|
||||||
var (
|
|
||||||
etcdServer = flag.String("etcd_server", "http://localhost:4001", "Url of local etcd server")
|
|
||||||
)
|
|
||||||
|
|
||||||
// Starts kubelet services. Never returns.
|
|
||||||
func fakeKubelet() {
|
|
||||||
endpoint := "unix:///var/run/docker.sock"
|
|
||||||
dockerClient, err := docker.NewClient(endpoint)
|
|
||||||
if err != nil {
|
|
||||||
glog.Fatal("Couldn't connnect to docker.")
|
|
||||||
}
|
|
||||||
|
|
||||||
myKubelet := kubelet.Kubelet{
|
|
||||||
Hostname: *kubeletAddress,
|
|
||||||
DockerClient: dockerClient,
|
|
||||||
FileCheckFrequency: *fileCheckFrequency,
|
|
||||||
SyncFrequency: *syncFrequency,
|
|
||||||
HTTPCheckFrequency: *httpCheckFrequency,
|
|
||||||
}
|
|
||||||
myKubelet.RunKubelet(*file, *manifestUrl, *etcdServer, *kubeletAddress, *kubeletPort)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Starts api services (the master). Never returns.
|
|
||||||
func apiServer() {
|
|
||||||
m := master.New([]string{*etcdServer}, []string{*kubeletAddress}, nil)
|
|
||||||
glog.Fatal(m.Run(net.JoinHostPort(*masterAddress, strconv.Itoa(int(*masterPort))), *apiPrefix))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Starts up a controller manager. Never returns.
|
|
||||||
func controllerManager() {
|
|
||||||
controllerManager := controller.MakeReplicationManager(
|
|
||||||
etcd.NewClient([]string{*etcdServer}),
|
|
||||||
client.New(fmt.Sprintf("http://%s:%d", *masterAddress, *masterPort), nil))
|
|
||||||
|
|
||||||
controllerManager.Run(20 * time.Second)
|
|
||||||
select {}
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
flag.Parse()
|
|
||||||
util.InitLogs()
|
|
||||||
defer util.FlushLogs()
|
|
||||||
rand.Seed(time.Now().UTC().UnixNano())
|
|
||||||
|
|
||||||
// Set up logger for etcd client
|
|
||||||
etcd.SetLogger(util.NewLogger("etcd "))
|
|
||||||
|
|
||||||
go apiServer()
|
|
||||||
go fakeKubelet()
|
|
||||||
go controllerManager()
|
|
||||||
|
|
||||||
glog.Infof("All components started.\nMaster running at: http://%s:%d\nKubelet running at: http://%s:%d\n",
|
|
||||||
*masterAddress, *masterPort,
|
|
||||||
*kubeletAddress, *kubeletPort)
|
|
||||||
select {}
|
|
||||||
}
|
|
@ -22,7 +22,7 @@ source $(dirname $0)/config-go.sh
|
|||||||
|
|
||||||
cd "${KUBE_TARGET}"
|
cd "${KUBE_TARGET}"
|
||||||
|
|
||||||
BINARIES="proxy integration apiserver controller-manager kubelet kubecfg localkube"
|
BINARIES="proxy integration apiserver controller-manager kubelet kubecfg"
|
||||||
|
|
||||||
if [ $# -gt 0 ]; then
|
if [ $# -gt 0 ]; then
|
||||||
BINARIES="$@"
|
BINARIES="$@"
|
||||||
|
@ -1,51 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# Copyright 2014 Google Inc. All rights reserved.
|
|
||||||
#
|
|
||||||
# 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.
|
|
||||||
|
|
||||||
# This command builds and runs a local kubernetes cluster.
|
|
||||||
|
|
||||||
if [ "$(which etcd)" == "" ]; then
|
|
||||||
echo "etcd must be in your PATH"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Stop right away if the build fails
|
|
||||||
set -e
|
|
||||||
|
|
||||||
# Only build what we need
|
|
||||||
(
|
|
||||||
source $(dirname $0)/config-go.sh
|
|
||||||
cd "${KUBE_TARGET}"
|
|
||||||
BINARIES="kubecfg localkube"
|
|
||||||
for b in $BINARIES; do
|
|
||||||
echo "+++ Building ${b}"
|
|
||||||
go build "${KUBE_GO_PACKAGE}"/cmd/${b}
|
|
||||||
done
|
|
||||||
)
|
|
||||||
|
|
||||||
echo "Starting etcd"
|
|
||||||
|
|
||||||
ETCD_DIR=$(mktemp -d -t kube-integration.XXXXXX)
|
|
||||||
trap "rm -rf ${ETCD_DIR}" EXIT
|
|
||||||
|
|
||||||
(etcd -name test -data-dir ${ETCD_DIR} > /tmp/etcd.log) &
|
|
||||||
ETCD_PID=$!
|
|
||||||
|
|
||||||
sleep 5
|
|
||||||
|
|
||||||
echo "Running localkube as root (so it can talk to docker's unix socket)"
|
|
||||||
sudo $(dirname $0)/../output/go/localkube $*
|
|
||||||
|
|
||||||
kill $ETCD_PID
|
|
@ -15,7 +15,7 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
# This file is exactly like kubecfg.sh, but it talks to a local master
|
# This file is exactly like kubecfg.sh, but it talks to a local master
|
||||||
# (which you're assumed to be running with localkube.sh).
|
# (which you're assumed to be running with local-up-cluster.sh).
|
||||||
|
|
||||||
CLOUDCFG=$(dirname $0)/../output/go/kubecfg
|
CLOUDCFG=$(dirname $0)/../output/go/kubecfg
|
||||||
if [ ! -x $CLOUDCFG ]; then
|
if [ ! -x $CLOUDCFG ]; then
|
||||||
|
Loading…
Reference in New Issue
Block a user