Skip to content

Commit

Permalink
add dns deployment for ubuntu k8s and update build.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
WIZARD-CXY committed May 4, 2015
1 parent e5a3759 commit dfb4425
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 93 deletions.
51 changes: 24 additions & 27 deletions cluster/ubuntu/build.sh
Expand Up @@ -22,53 +22,50 @@ set -e

function cleanup {
# cleanup work
rm -rf flannel kubernetes* etcd* binaries
rm -rf flannel* kubernetes* etcd* binaries
}
trap cleanup SIGHUP SIGINT SIGTERM

# check root
if [ "$(id -u)" != "0" ]; then
echo >&2 "Please run as root"
exit 1
fi

mkdir -p binaries
mkdir -p binaries/master
mkdir -p binaries/minion

# flannel
echo "Download & build flanneld ..."
apt-get install linux-libc-dev
if [ ! -d flannel ] ; then
echo "flannel does not exsit, cloning ..."
git clone https://github.com/coreos/flannel.git
echo "Download flannel release ..."
FLANNEL_VERSION="0.4.0"
if [ ! -f flannel.tar.gz ] ; then
curl -L https://github.com/coreos/flannel/releases/download/v${FLANNEL_VERSION}/flannel-${FLANNEL_VERSION}-linux-amd64.tar.gz -o flannel.tar.gz
tar xzf flannel.tar.gz
fi

pushd flannel
docker run -v `pwd`:/opt/flannel -i -t google/golang /bin/bash -c "cd /opt/flannel && ./build"
popd
cp flannel/bin/flanneld binaries/
cp flannel-${FLANNEL_VERSION}/flanneld binaries/minion

# ectd
echo "Download etcd release ..."
ETCD_V="v2.0.0"
ETCD="etcd-${ETCD_V}-linux-amd64"
ETCD_VERSION="v2.0.0"
ETCD="etcd-${ETCD_VERSION}-linux-amd64"
if [ ! -f etcd.tar.gz ] ; then
curl -L https://github.com/coreos/etcd/releases/download/$ETCD_V/$ETCD.tar.gz -o etcd.tar.gz
curl -L https://github.com/coreos/etcd/releases/download/${ETCD_VERSION}/${ETCD}.tar.gz -o etcd.tar.gz
tar xzf etcd.tar.gz
fi
cp $ETCD/etcd $ETCD/etcdctl binaries
cp $ETCD/etcd $ETCD/etcdctl binaries/master
cp $ETCD/etcd $ETCD/etcdctl binaries/minion


# k8s
echo "Download kubernetes release ..."

K8S_V="v0.15.0"
K8S_VERSION="v0.16.0"
if [ ! -f kubernetes.tar.gz ] ; then
curl -L https://github.com/GoogleCloudPlatform/kubernetes/releases/download/$K8S_V/kubernetes.tar.gz -o kubernetes.tar.gz
curl -L https://github.com/GoogleCloudPlatform/kubernetes/releases/download/${K8S_VERSION}/kubernetes.tar.gz -o kubernetes.tar.gz
tar xzf kubernetes.tar.gz
fi
pushd kubernetes/server
tar xzf kubernetes-server-linux-amd64.tar.gz
popd
cp kubernetes/server/kubernetes/server/bin/* binaries/
cp kubernetes/server/kubernetes/server/bin/kube-apiserver \
kubernetes/server/kubernetes/server/bin/kube-controller-manager \
kubernetes/server/kubernetes/server/bin/kube-scheduler binaries/master

cp kubernetes/server/kubernetes/server/bin/kubelet \
kubernetes/server/kubernetes/server/bin/kube-proxy binaries/minion

rm -rf flannel kubernetes* etcd*
rm -rf flannel* kubernetes* etcd*
echo "Done! All your commands locate in ./binaries dir"
11 changes: 6 additions & 5 deletions cluster/ubuntu/config-default.sh
@@ -1,6 +1,6 @@
#!/bin/bash

# Copyright 2015 Google Inc. All rights reserved.
# Copyright 2015 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.
Expand Down Expand Up @@ -51,10 +51,11 @@ ENABLE_CLUSTER_MONITORING="${KUBE_ENABLE_CLUSTER_MONITORING:-true}"
DOCKER_OPTS=""

# Optional: Install cluster DNS.
#ENABLE_CLUSTER_DNS=true
#DNS_SERVER_IP="10.247.0.10"
#DNS_DOMAIN="kubernetes.local"
#DNS_REPLICAS=1
ENABLE_CLUSTER_DNS=true
# DNS_SERVER_IP must be a IP in PORTAL_NET range
DNS_SERVER_IP="192.168.3.10"
DNS_DOMAIN="kubernetes.local"
DNS_REPLICAS=1

# Optional: Enable setting flags for kube-apiserver to turn on behavior in active-dev
#RUNTIME_CONFIG=""
2 changes: 1 addition & 1 deletion cluster/ubuntu/config-test.sh
@@ -1,6 +1,6 @@
#!/bin/bash

# Copyright 2015 Google Inc. All rights reserved.
# Copyright 2015 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.
Expand Down
32 changes: 32 additions & 0 deletions cluster/ubuntu/deployAddons.sh
@@ -0,0 +1,32 @@
#!/bin/bash

# Copyright 2015 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.

# deploy the addons service after the cluster is available

set -e

KUBE_ROOT=$(dirname "${BASH_SOURCE}")/../..
source "config-default.sh"

if [ "${ENABLE_CLUSTER_DNS}" == true ]; then
echo "Deploying DNS on kubernetes"
sed -e "s/{{ pillar\['dns_replicas'\] }}/${DNS_REPLICAS}/g;s/{{ pillar\['dns_domain'\] }}/${DNS_DOMAIN}/g" ../../cluster/addons/dns/skydns-rc.yaml.in > skydns-rc.yaml
sed -e "s/{{ pillar\['dns_server'\] }}/${DNS_SERVER_IP}/g" ../../cluster/addons/dns/skydns-svc.yaml.in > skydns-svc.yaml
# use kubectl to create skydns rc and service
"${KUBE_ROOT}/cluster/kubectl.sh" create -f skydns-rc.yaml
"${KUBE_ROOT}/cluster/kubectl.sh" create -f skydns-svc.yaml

fi
2 changes: 1 addition & 1 deletion cluster/ubuntu/reconfDocker.sh
@@ -1,6 +1,6 @@
#!/bin/bash

# Copyright 2015 Google Inc. All rights reserved.
# Copyright 2015 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.
Expand Down
77 changes: 22 additions & 55 deletions cluster/ubuntu/util.sh
@@ -1,6 +1,6 @@
#!/bin/bash

# Copyright 2015 Google Inc. All rights reserved.
# Copyright 2015 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.
Expand Down Expand Up @@ -211,7 +211,9 @@ KUBELET_OPTS="--address=0.0.0.0 \
--port=10250 \
--hostname_override=$1 \
--api_servers=http://$2:8080 \
--logtostderr=true"
--logtostderr=true \
--cluster_dns=$3 \
--cluster_domain=$4"
EOF

}
Expand Down Expand Up @@ -307,7 +309,7 @@ function kube-up {
source "${KUBE_ROOT}/cluster/ubuntu/${KUBE_CONFIG_FILE-"config-default.sh"}"

# ensure the binaries are downloaded
if [ ! -f "ubuntu/binaries/kube-apiserver" ]; then
if [ ! -f "ubuntu/binaries/master/kube-apiserver" ]; then
echo "warning: not enough binaries to build k8s, please run build.sh in cluster/ubuntu first"
exit 1
fi
Expand Down Expand Up @@ -343,17 +345,17 @@ function provision-master() {
echo "Deploying master on machine ${MASTER_IP}"
echo
ssh $SSH_OPTS $MASTER "mkdir -p ~/kube/default"
scp -r $SSH_OPTS ubuntu/config-default.sh ubuntu/util.sh ubuntu/master/* ubuntu/binaries/ "${MASTER}:~/kube"
scp -r $SSH_OPTS ubuntu/config-default.sh ubuntu/util.sh ubuntu/master/* ubuntu/binaries/master/ "${MASTER}:~/kube"

# remote login to MASTER and use sudo to configue k8s master
ssh $SSH_OPTS -t $MASTER "source ~/kube/util.sh; \
setClusterInfo; \
create-etcd-opts "${mm[${MASTER_IP}]}" "${MASTER_IP}" "${CLUSTER}"; \
create-kube-apiserver-opts ${PORTAL_NET}; \
create-kube-controller-manager-opts ${MINION_IPS}; \
create-kube-apiserver-opts "${PORTAL_NET}"; \
create-kube-controller-manager-opts "${MINION_IPS}"; \
create-kube-scheduler-opts; \
sudo -p '[sudo] password to copy files and start master: ' cp ~/kube/default/* /etc/default/ && sudo cp ~/kube/init_conf/* /etc/init/ && sudo cp ~/kube/init_scripts/* /etc/init.d/ \
&& sudo cp ~/kube/binaries/* /opt/bin/; \
&& sudo mkdir -p /opt/bin/ && sudo cp ~/kube/master/* /opt/bin/; \
sudo service etcd start;"
}

Expand All @@ -362,17 +364,17 @@ function provision-minion() {
echo "Deploying minion on machine ${1#*@}"
echo
ssh $SSH_OPTS $1 "mkdir -p ~/kube/default"
scp -r $SSH_OPTS ubuntu/config-default.sh ubuntu/util.sh ubuntu/reconfDocker.sh ubuntu/minion/* ubuntu/binaries/ "${1}:~/kube"
scp -r $SSH_OPTS ubuntu/config-default.sh ubuntu/util.sh ubuntu/reconfDocker.sh ubuntu/minion/* ubuntu/binaries/minion "${1}:~/kube"

# remote login to MASTER and use sudo to configue k8s master
ssh $SSH_OPTS -t $1 "source ~/kube/util.sh; \
setClusterInfo; \
create-etcd-opts ${mm[${1#*@}]} ${1#*@} ${CLUSTER}; \
create-kubelet-opts ${1#*@} ${MASTER_IP}; \
create-kube-proxy-opts ${MASTER_IP}; \
create-etcd-opts "${mm[${1#*@}]}" "${1#*@}" "${CLUSTER}"; \
create-kubelet-opts "${1#*@}" "${MASTER_IP}" "${DNS_SERVER_IP}" "${DNS_DOMAIN}";
create-kube-proxy-opts "${MASTER_IP}"; \
create-flanneld-opts; \
sudo -p '[sudo] password to copy files and start minion: ' cp ~/kube/default/* /etc/default/ && sudo cp ~/kube/init_conf/* /etc/init/ && sudo cp ~/kube/init_scripts/* /etc/init.d/ \
&& sudo cp ~/kube/binaries/* /opt/bin; \
&& sudo mkdir -p /opt/bin/ && sudo cp ~/kube/minion/* /opt/bin; \
sudo service etcd start; \
sudo -b ~/kube/reconfDocker.sh"
}
Expand All @@ -382,20 +384,20 @@ function provision-masterandminion() {
echo "Deploying master and minion on machine ${MASTER_IP}"
echo
ssh $SSH_OPTS $MASTER "mkdir -p ~/kube/default"
scp -r $SSH_OPTS ubuntu/config-default.sh ubuntu/util.sh ubuntu/master/* ubuntu/reconfDocker.sh ubuntu/minion/* ubuntu/binaries/ "${MASTER}:~/kube"

scp -r $SSH_OPTS ubuntu/config-default.sh ubuntu/util.sh ubuntu/master/* ubuntu/reconfDocker.sh ubuntu/minion/* ubuntu/binaries/master/ ubuntu/binaries/minion "${MASTER}:~/kube"
# remote login to the node and use sudo to configue k8s
ssh $SSH_OPTS -t $MASTER "source ~/kube/util.sh; \
setClusterInfo; \
create-etcd-opts "${mm[${MASTER_IP}]}" "${MASTER_IP}" "${CLUSTER}"; \
create-kube-apiserver-opts ${PORTAL_NET}; \
create-kube-controller-manager-opts ${MINION_IPS}; \
create-kube-apiserver-opts "${PORTAL_NET}"; \
create-kube-controller-manager-opts "${MINION_IPS}"; \
create-kube-scheduler-opts; \
create-kubelet-opts ${MASTER_IP} ${MASTER_IP}; \
create-kube-proxy-opts ${MASTER_IP}; \
create-kubelet-opts "${MASTER_IP}" "${MASTER_IP}" "${DNS_SERVER_IP}" "${DNS_DOMAIN}";
create-kube-proxy-opts "${MASTER_IP}";\
create-flanneld-opts; \
sudo -p '[sudo] password to copy files and start node: ' cp ~/kube/default/* /etc/default/ && sudo cp ~/kube/init_conf/* /etc/init/ && sudo cp ~/kube/init_scripts/* /etc/init.d/ \
&& sudo cp ~/kube/binaries/* /opt/bin/; \
&& sudo mkdir -p /opt/bin/ && sudo cp ~/kube/master/* /opt/bin/ && sudo cp ~/kube/minion/* /opt/bin/; \
sudo service etcd start; \
sudo -b ~/kube/reconfDocker.sh"
}
Expand All @@ -419,42 +421,7 @@ function kube-push {
echo "not implemented"
}

# Restart the kube-proxy on a node ($1)
function restart-kube-proxy {
ssh-to-node "$1" "service kube-proxy restart"
}

# Restart the apiserver($1)
function restart-apiserver {
ssh-to-node "$1" "service kube-apiserver restart"
}

# Restart the etcd on a node ($1)
function restart-etcd {
ssh-to-node "$1" "service etcd restart"
}

# Restart the kubelet on a node ($1)
function restart-kubelet {
ssh-to-node "$1" "service kubelet restart"
}

# Restart the kube-controller-manager on a node ($1)
function restart-kube-controller-manager {
ssh-to-node "$1" "service kube-controller-manager restart"
}

# Restart the kube-scheduler on a node ($1)
function restart-kube-scheduler {
ssh-to-node "$1" "service kube-scheduler restart"
}

# Restart the flannel on a node ($1)
function restart-flannel {
ssh-to-node "$1" "service flannel restart"
}

# Perform preparations required to run e2e tests
function prepare-e2e() {
echo "Ubuntu doesn't need special preparations for e2e tests" 1>&2
}
}
2 changes: 1 addition & 1 deletion docs/getting-started-guides/README.md
Expand Up @@ -31,7 +31,7 @@ Joyent | Juju | Ubuntu | flannel | [docs](../../docs/getting
AWS | Saltstack | Ubuntu | OVS | [docs](../../docs/getting-started-guides/aws.md) | Community (@justinsb) | Uses K8s version 0.5.0
Vmware | CoreOS | CoreOS | flannel | [docs](../../docs/getting-started-guides/coreos.md) | Community (@kelseyhightower) | Uses K8s version 0.15.0
Azure | Saltstack | Ubuntu | OpenVPN | [docs](../../docs/getting-started-guides/azure.md) | Community |
Bare-metal | custom | Ubuntu | flannel | [docs](../../docs/getting-started-guides/ubuntu.md) | Community (@resouer @WIZARD-CXY) | use k8s version 0.15.0
Bare-metal | custom | Ubuntu | flannel | [docs](../../docs/getting-started-guides/ubuntu.md) | Community (@resouer @WIZARD-CXY) | use k8s version 0.16.0
Docker Single Node | custom | N/A | local | [docs](docker.md) | Project (@brendandburns) | Tested @ 0.14.1 |
Docker Multi Node | Flannel| N/A | local | [docs](docker-multinode.md) | Project (@brendandburns) | Tested @ 0.14.1 |
Local | | | _none_ | [docs](../../docs/getting-started-guides/locally.md) | Community (@preillyme) |
Expand Down
42 changes: 39 additions & 3 deletions docs/getting-started-guides/ubuntu.md
Expand Up @@ -35,7 +35,7 @@ Please make sure that there are `kube-apiserver`, `kube-controller-manager`, `ku

> We used flannel here because we want to use overlay network, but please remember it is not the only choice, and it is also not a k8s' necessary dependence. Actually you can just build up k8s cluster natively, or use flannel, Open vSwitch or any other SDN tool you like, we just choose flannel here as a example.
#### II. Configue and install every components upstart script
#### II. Configue and start the kubernetes cluster
An example cluster is listed as below:

| IP Address|Role |
Expand All @@ -57,6 +57,7 @@ export PORTAL_NET=11.1.1.0/24
export FLANNEL_NET=172.16.0.0/16
```

The first variable `nodes` defines all your cluster nodes, MASTER node comes first and separated with blank space like `<user_1@ip_1> <user_2@ip_2> <user_3@ip_3> `
Expand Down Expand Up @@ -98,7 +99,7 @@ If all things goes right, you will see the below message from console

You can also use kubectl command to see if the newly created k8s is working correctly.

For example , `$ kubectl get minions` to see if you get all your minion nodes comming up and ready. It may take some times for the minions be ready to use like below .
For example, use `$ kubectl get minions` to see if you get all your minion nodes comming up and ready. It may take some times for the minions be ready to use like below.

```
NAME LABELS STATUS
Expand All @@ -108,12 +109,47 @@ NAME LABELS STATUS
10.10.103.223 <none> Ready
10.10.103.250 <none> Ready
```

Also you can run kubernetes [guest-example](https://github.com/GoogleCloudPlatform/kubernetes/tree/master/examples/guestbook) to build a redis backend cluster on the k8s.


#### V. Trouble Shooting
#### IV. Deploy addons

After the previous parts, you will have a working k8s cluster, this part will teach you how to deploy addones like dns onto the existing cluster.

The configuration of dns is configured in cluster/ubuntu/config-default.sh.

```
ENABLE_CLUSTER_DNS=true
DNS_SERVER_IP="192.168.3.10"
DNS_DOMAIN="kubernetes.local"
DNS_REPLICAS=1
```
The `DNS_SERVER_IP` is defining the ip of dns server which must be in the portal_net range.

The `DNS_REPLICAS` describes how many dns pod running in the cluster.

After all the above variable have been set. Just type the below command

```
$ cd cluster/ubuntu
$ KUBERNETES_PROVIDER=ubuntu ./deployAddons.sh
```

After some time, you can use `$ kubectl get pods` to see the dns pod is running in the cluster. Done!


#### IV. Trouble Shooting

Generally, what of this approach did is quite simple:

Expand Down

0 comments on commit dfb4425

Please sign in to comment.