Skip to content

Commit

Permalink
Merge pull request kubernetes#298 from Pendoragon/kube-restart
Browse files Browse the repository at this point in the history
Add kube-halt & kube-restart
  • Loading branch information
ddysher committed Mar 22, 2016
2 parents baf4110 + b9832e8 commit 9dc5b51
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 0 deletions.
14 changes: 14 additions & 0 deletions cluster/caicloud-anchnet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
- [Update a cluster](#update-a-cluster)
- [Options:](#options-2)
- [Add node to a cluster](#add-node-to-a-cluster)
- [Stop a running cluster](#stop-a-running-cluster)
- [Restart a cluster](#restart-a-cluster)
- [Options:](#options-3)
- [Test](#test)
- [Unit Test](#unit-test)
Expand Down Expand Up @@ -169,6 +171,18 @@ In case we want to add node(s) to a running cluster, we can run:
CLUSTER_NAME=kube-default MASTER_EIP=103.21.116.147 NUM_MINIONS=1 KUBERNETES_PROVIDER=caicloud-anchnet ./cluster/kube-add-node.sh
```
## Stop a running cluster
we can simply do the following to shut down a running cluster:
```
CLUSTER_NAME=kube-default KUBERNETES_PROVIDER=caicloud-anchnet ./cluster/kube-halt.sh
```
## Restart a cluster
If we want to restart a cluster which has been stopped before, we can do:
```
CLUSTER_NAME=kube-default KUBERNETES_PROVIDER=caicloud-anchnet ./cluster/kube-restart.sh
```
#### Options:
* `INSTANCE_USER`: Instance user of the master (e.g. ubuntu). This will also be used to create new nodes
Expand Down
21 changes: 21 additions & 0 deletions cluster/caicloud-anchnet/util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,27 @@ function kube-down {
# TODO: Find all loadbalancers. For now, Loadbalancer is not prefixed with CLUSTER_NAME.
}

# Stop a kubernetes cluster from anchnet, using CLUSTER_NAME.
function kube-halt {
# Find all instances prefixed with CLUSTER_NAME.
find-instance-and-eip-resouces "running"
if [[ "$?" == "0" ]]; then
anchnet-exec-and-retry "${ANCHNET_CMD} stopinstances ${INSTANCE_IDS} --project=${PROJECT_ID}"
anchnet-wait-job ${COMMAND_EXEC_RESPONSE} ${INSTANCE_TERMINATE_WAIT_RETRY} ${INSTANCE_TERMINATE_WAIT_INTERVAL}
fi
}

# Start a stopped kubernetes cluster from anchnet, using CLUSTER_NAME.
function kube-restart {
# Find all instances prefixed with CLUSTER_NAME.
find-instance-and-eip-resouces "stopped"
if [[ "$?" == "0" ]]; then
anchnet-exec-and-retry "${ANCHNET_CMD} startinstances ${INSTANCE_IDS} --project=${PROJECT_ID}"
anchnet-wait-job ${COMMAND_EXEC_RESPONSE} ${INSTANCE_TERMINATE_WAIT_RETRY} ${INSTANCE_TERMINATE_WAIT_INTERVAL}
fi
}


# Detect name and IP for kube master.
#
# Assumed vars:
Expand Down
4 changes: 4 additions & 0 deletions cluster/caicloud/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ These are brand new folders created to support our cloudprovider:
* Scripts used to bring up baremetal cluster
* cluster/kube-add-node.sh
* A new script used to add a new node into cluster
* cluster/kube-halt.sh
* A new script used to stop a running cluster
* cluster/kube-restart.sh
* A new script used to start a stopped cluster
* hack/caicloud/
* Various tools for working with caicloud kubernetes
* examples/caicloud/
Expand Down
37 changes: 37 additions & 0 deletions cluster/kube-halt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

# Copyright 2014 The Kubernetes Authors 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.

# Tear down a Kubernetes cluster.

set -o errexit
set -o nounset
set -o pipefail

KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..

if [ -f "${KUBE_ROOT}/cluster/env.sh" ]; then
source "${KUBE_ROOT}/cluster/env.sh"
fi

source "${KUBE_ROOT}/cluster/kube-env.sh"
source "${KUBE_ROOT}/cluster/kube-util.sh"

echo "Stopping cluster using provider: $KUBERNETES_PROVIDER"

verify-prereqs
kube-halt

echo "Done"
37 changes: 37 additions & 0 deletions cluster/kube-restart.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

# Copyright 2014 The Kubernetes Authors 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.

# Tear down a Kubernetes cluster.

set -o errexit
set -o nounset
set -o pipefail

KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..

if [ -f "${KUBE_ROOT}/cluster/env.sh" ]; then
source "${KUBE_ROOT}/cluster/env.sh"
fi

source "${KUBE_ROOT}/cluster/kube-env.sh"
source "${KUBE_ROOT}/cluster/kube-util.sh"

echo "Restarting cluster using provider: $KUBERNETES_PROVIDER"

verify-prereqs
kube-restart

echo "Done"

0 comments on commit 9dc5b51

Please sign in to comment.