【kubernetes】ubuntu14.04 64位 搭建kubernetes過程

背景:

Kubernetes介紹:http://kubernetes.io/docs/getting-started-guides/linux

github地址:https://github.com/kubernetes/kubernetesgit

在ubuntu上安裝文檔官方地址:http://kubernetes.io/docs/getting-started-guides/ubuntu/github

 

環境:

  • Master:
    • Ubunut14.04
    • 192.168.27.135(NAT)         
  • Minion1:
    • Ubuntu14.04
    • 192.168.27.136(NAT) 
  • Minion2:
    • Ubuntu14.04
    • 192.168.27.137(NAT) 

 

準備工做:

須要在三個節點上安裝docker和ssh,安裝ssh:docker

$ sudo apt-get install openssh-server $ sudo service ssh start

安裝docker:shell

sudo apt-get install docker-engine

 

安裝Kubernetes:

一、在Master上,首先建立一個工做目錄,執行:express

$ git clone https://github.com/kubernetes/kubernetes.git

 

二、下載完後,進入kubernetes目錄,修改kubernetes/cluster/ubuntu/config-default.sh文件:apache

root@192.168.127.135 root@192.168.27.136 root@192.168.27.137

 

三、安裝kubernetes:ubuntu

$ cd  kubernetes/cluster
$ KUBERNETES_PROVIDER=ubuntu ./kube-up.sh

 

成功安裝的截圖以下:api

 

 

 

訪問頁面:bash

 

遇到的各類坑:

一、重啓master節點,如何恢復?

這個問題弄了我至少3小時才搞定,由於我是準備直接從新執行一遍上面步驟的第三步,也就是再執行一次kube-up.sh,然而我發現每次該腳本都會從github上下載etcd、flanneld和kubernetes包,這個包有1.4G大小,可想而知要耽誤多少時間。而後我就只能慢慢找這段腳本在哪執行的,最後發如今kubernetes/cluster/ubuntu/下的download-release.sh,也就是下圖中的文件。因此我就把文件的內容改了,改爲下面代碼中的樣子,目的是不讓它每次都下。隨後呢,個人作法是把第一次成功安裝的文件備份一下,也就是把kubernetes/cluster/ubuntu/binaries這個目錄備份起來,而後直接拷到重啓後的master的對應目錄。而後再執行kube-up.sh,以後就OK啦!

 

#!/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.

# Download the etcd, flannel, and K8s binaries automatically and stored in binaries directory
# Run as root only

# author @resouer @WIZARD-CXY
set -e

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

pushd $(dirname $0)
mkdir -p binaries/master
mkdir -p binaries/minion

# flannel
FLANNEL_VERSION=${FLANNEL_VERSION:-"0.5.5"}
echo "Prepare flannel ${FLANNEL_VERSION} release ..."
grep -q "^${FLANNEL_VERSION}\$" binaries/.flannel 2>/dev/null || {
#  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
#  cp flannel-${FLANNEL_VERSION}/flanneld binaries/master
 # cp flannel-${FLANNEL_VERSION}/flanneld binaries/minion
  echo ${FLANNEL_VERSION} > binaries/.flannel
}

# ectd
ETCD_VERSION=${ETCD_VERSION:-"2.3.1"}
ETCD="etcd-v${ETCD_VERSION}-linux-amd64"
echo "Prepare etcd ${ETCD_VERSION} release ..."
grep -q "^${ETCD_VERSION}\$" binaries/.etcd 2>/dev/null || {
#  curl -L https://github.com/coreos/etcd/releases/download/v${ETCD_VERSION}/${ETCD}.tar.gz -o etcd.tar.gz
#  tar xzf etcd.tar.gz
#  cp ${ETCD}/etcd ${ETCD}/etcdctl binaries/master
  echo ${ETCD_VERSION} > binaries/.etcd
}

function get_latest_version_number {
  local -r latest_url="https://storage.googleapis.com/kubernetes-release/release/stable.txt"
  if [[ $(which wget) ]]; then
    wget -qO- ${latest_url}
  elif [[ $(which curl) ]]; then
    curl -Ss ${latest_url}
  else
    echo "Couldn't find curl or wget.  Bailing out." >&2
    exit 4
  fi
}

KUBE_VERSION=$(get_latest_version_number | sed 's/^v//')

# k8s
echo "Prepare kubernetes ${KUBE_VERSION} release ..."
grep -q "^${KUBE_VERSION}\$" binaries/.kubernetes 2>/dev/null || {
#  curl -L https://github.com/kubernetes/kubernetes/releases/download/v${KUBE_VERSION}/kubernetes.tar.gz -o kubernetes.tar.gz
#  tar xzf kubernetes.tar.gz
#  pushd kubernetes/server
#  tar xzf kubernetes-server-linux-amd64.tar.gz
#  popd
#  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
#  cp kubernetes/server/kubernetes/server/bin/kubectl binaries/
  echo ${KUBE_VERSION} > binaries/.kubernetes
}

#rm -rf flannel* kubernetes* etcd*

echo "Done! All your binaries locate in kubernetes/cluster/ubuntu/binaries directory"
popd
相關文章
相關標籤/搜索