1.部署环境:
(1) Ubuntu 14.04 (2台装有该版本的笔记本电脑)
(2) Docker 1.9.1
(3) etcd-2.2.5
(4) Kubernetes 0.9.0
2.配置Ubuntu 14.04
(1) 由于只有两台主机,所以这里一台主机既充当Master又充当minions:
Master(mininos): 192.168.1.101
Mininos: 192.168.1.100
(2) 创建/opt/bin文件夹,后面安装会用:sudo mkdir -p /opt/bin
3.在Master主机上安装etcd-2.2.5
(1)下载: https://github.com/coreos/etcd/releases/download/v2.2.5/etcd-v2.2.5-linux-amd64.tar.gz
(2) 解压文件: tar -zxvf etcd-v2.2.5-linux-amd64.tar.gz
(3)复制etcd到/opt/bin文件夹中: cp etcd-v2.2.5-linux-amd64/etcd /opt/bin/
4.在Master主机中安装Kubernetes 0.9.0(假设安装目录为/home/docker/Downloads)
(1) 下载:https://github.com/kubernetes/kubernetes/releases/download/v0.9.0/kubernetes.tar.gz
(2) 解压kubernetes.tar.gz文件: tar -zxvf /home/docker/Downloads/kubernetes.tar.gz
(3) 进入kubernetes/server目录下: cd /home/docker/Downloads/kubernetes/server
(4) 解压kubernetes-server-linux-amd64.tar.gz文件得到kubernetes: tar -zxvf /home/docker/Downloads/kubernetes-server-linux-amd64.tar.gz
(5)进入kubernetes/server/bin/目录下:cd /home/docker/Downloads/kubernetes/server/kubernetes/server/bin/
(6)复制该目录下所有的文件到/opt/bin/目录下: sudo cp * /opt/bin/
(7)进入到/home/docker/Downloads/kubernetes/cluster/ubuntu目录下: cd /home/docker/Downloads/kubernetes/cluster/ubuntu
(8)执行./util.sh脚本: sudo ./util.sh(该脚本检测/opt/bin/下的相关文件,自动安装kubernetes)
(9)安装完成后可以发现到/etc/default/,/etc/init/,/etc/init.d/目录下多了etcd和kubernetes相关的配置文件和启动文件
5.在Minions上安装kubernetes:(Mininos上不用安装etcd)
在Minions上只需要安装kubelet,kube-proxy即可.安装方法与Master上的安装步骤一样,只是安装完成后将/etc/default,/etc/init/,/etc/init.d/文件夹下的与kube-apiserver,kube-controller-manager,kube-scheduler相关的文件删除即可.
6.etcd配置:
(1)修改/etc/default/etcd:
# Etcd Upstart and SysVinit configuration file
# Customize etcd location
# ETCD="/opt/bin/etcd"
# Use ETCD_OPTS to modify the start/restart options
ETCD_OPTS="-listen-client-urls=http://192.168.1.101:4001"
# Add more envionrment settings used by etcd here
(2)删除/etc/init/etcd.conf与/etc/init.d/etcd
7.kubernetes相关配置:
(1).Master节点:
/etc/default/kube-apiserver
# Kube-Apiserver Upstart and SysVinit configuration file
# Customize kube-apiserver binary location
# KUBE_APISERVER="/opt/bin/kube-apiserver"
# Use KUBE_APISERVER_OPTS to modify the start/restart options
KUBE_APISERVER_OPTS="--address=127.0.0.1 \
--port=8080 \
--etcd_servers=http://192.168.1.101:4001 \
--logtostderr=true \
--portal_net=11.1.1.0/24"
# Add more envionrment settings used by kube-apiserver here
/etc/default/ kube-controller-manager
# Kube-Controller-Manager Upstart and SysVinit configuration file
# Customize kube-controller-manager binary location
# KUBE_CONTROLLER_MANAGER="/opt/bin/kube-controller-manager"
# Use KUBE_CONTROLLER_MANAGER_OPTS to modify the start/restart options
KUBE_CONTROLLER_MANAGER_OPTS="--master=127.0.0.1:8080 \
--machines=127.0.0.1,192.168.1.100 \
--logtostderr=true"
# Add more envionrment settings used by kube-controller-manager here
/etc/default/kubelet
# Kubelet Upstart and SysVinit configuration file
# Customize kubelet binary location
# KUBELET="/opt/bin/kubelet"
# Use KUBELET_OPTS to modify the start/restart options
KUBELET_OPTS="--address=127.0.0.1 \
--port=10250 \
--hostname_override=127.0.0.1 \
--etcd_servers=http://192.168.1.101:4001 \
--logtostderr=true"
# Add more envionrment settings used by kube-scheduler here
/etc/default/kube-proxy
# Kube-Proxy Upstart and SysVinit configuration file
# Customize kube-proxy binary location
# KUBE_PROXY="/opt/bin/kube-proxy"
# Use KUBE_PROXY_OPTS to modify the start/restart options
KUBE_PROXY_OPTS="--etcd_servers=http://192.168.1.101:4001 \
--logtostderr=true"<pre name="code" class="plain">
# Add more envionrment settings used by kube-apiserver here
/etc/default/kube-scheduler
# Kube-Scheduler Upstart and SysVinit configuration file
# Customize kube-apiserver binary location
# KUBE_SCHEDULER="/opt/bin/kube-apiserver"
# Use KUBE_SCHEDULER_OPTS to modify the start/restart options
KUBE_SCHEDULER_OPTS="--logtostderr=true \
--master=127.0.0.1:8080"
# Add more envionrment settings used by kube-scheduler here
(2)Minions节点
/etc/default/kubelet
# Kubelet Upstart and SysVinit configuration file
# Customize kubelet binary location
# KUBELET="/opt/bin/kubelet"
# Use KUBELET_OPTS to modify the start/restart options
KUBELET_OPTS="--address=0.0.0.0 \
--port=10250 \
--hostname_override=192.168.1.100 \
--etcd_servers=http://192.168.1.101:4001 \
--logtostderr=true"
# Add more envionrment settings used by kube-scheduler here
/etc/default/kube-proxy
# Kube-Proxy Upstart and SysVinit configuration file
# Customize kube-proxy binary location
# KUBE_PROXY="/opt/bin/kube-proxy"
# Use KUBE_PROXY_OPTS to modify the start/restart options
KUBE_PROXY_OPTS="--etcd_servers=http://192.168.1.101:4001 \
--logtostderr=true"
# Add more envionrment settings used by kube-apiserver here
8.启动相关服务
Master 节点:
(1).启动docker服务
sudo service docker start
(2).启动etcd服务
sudo etcd -name etcdserver -peer-addr 192.168.1.101:7001 -addr 192.168.1.101:4001 -data-dir /data/etcd -peer-bind-addr 0.0.0.0:7001 -bind-addr 0.0.0.0:4001 &
(3)启动kubernetes相关服务
sudo service kube-apiserver start
sudo service kube-controller-manager start
sudo service kubelet start
sudo service kube-proxy start
sudo service kube-scheduler start
Minions节点:
启动kuberbetes相关服务
sudo service kubelet start
sudo service kube-proxy start
9.打开相关端口
Master节点: 打开4001,7001端口
iptables -I INPUT -s 192.168.43.0/24 -p tcp --dport 4001 -j ACCEPT
iptables -I INPUT -s 192.168.43.0/24 -p tcp --dport 7001 -j ACCEPT
Minions节点:打开10250端口
iptables -I INPUT -s 192.168.43.0/24 -p tcp --dport 10250 -j ACCEPT