kubernetes 在 ubuntu 上的部署实践
教程系列:
官方教程:
http://kubernetes.io/docs/getting-started-guides/ubuntu/
网上的教程:
http://blog.csdn.net/wangtaoking1/article/details/49122977
脚本的结构解释:
http://blog.csdn.net/delphiwcdj/article/details/50411711
从虚拟机开始
本人使用的脚本设置了2台虚拟机(Ubuntu 14.04 LTS 64bit server),1台为master和minion,另外一台是minion
虚拟机需求:
- The nodes have installed docker version 1.2+ and bridge-utils to manipulate linux bridge.
- All machines can communicate with each other. Master node needs to be connected to the Internet to download the necessary files, while worker nodes do not.
- These guide is tested OK on Ubuntu 14.04 LTS 64bit server, but it can not work with Ubuntu 15 which uses systemd instead of upstart.
- Dependencies of this guide: etcd-2.2.1, flannel-0.5.5, k8s-1.1.8, may work with higher versions.
- All the remote servers can be ssh logged in without a password by using key authentication.
(摘自官网教程)
虚拟机新建步骤
使用root账号:sudo passwd root
su root
允许远程登陆:vi /etc/ssh/sshd_config
PermitRootLogin without-password
修改为:PermitRootLogin yes
service ssh restart
免密码登陆:ssh-keygen -t rsa
touch /root/.ssh/authorized_keys
cat /root/id_rsa.pub >> /root/.ssh/authorized_keys
master需要将公钥添加到每一台机器,如果不添加,到时候运行安装脚本需要手动输入密码
换源,阿里源或163源:vi /etc/apt/source.list
deb http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
sudo apt-get update
sudo apt-get upgrade
安装docker:sudo apt-get install curl
curl -fsSL https://get.docker.com/ | sh
安装bridge-utils:sudo apt-get install bridge-utils
准备工作
在master机器上,下载相关文件:cd /root
下载 http://pan.baidu.com/s/1bpt4QtD,放在/root路径下
软件版本号:
- FLANNEL_VERSION=0.5.5
- ETCD_VERSION=2.3.1
- KUBE_VERSION=1.2.4
git clone -b v1.2.4 [email protected]:JMcn/kubernetes.git
本仓库是fork官方仓库的tag1.2.4经过修改而成,主要改动如下:
- 全部仓库地址:gcr.io/google_containers 替换为 index.alauda.cn/googlecontainer
- cluster/addons/dns/skydns-rc.yaml.in 添加 - --kube_master_url
- 更改 cluster/ubuntu/config-default.sh
- 修改 cluster/ubuntu/download-release.sh
- cluster/ubuntu/reconfDocker.sh 在 etcdctl 后面添加 --no-sync 参数
- 添加认证文件cluster/easy-rsa.tar.gz 和 添加 Kube-UI 插件
如果第5点没有修改,etcdctl 后面不加 --no-sync 参数,执行安装脚本时,etcd会报如下错误:
etcd cluster has no published client endpoints.
Try '--no-sync' if you want to access non-published client endpoints(http://127.0.0.1:2379,http://127.0.0.1:4001).
Error: client: no endpoints available
编译各节点所用到的软件,安装kubectl工具:
cd kubernetes/cluster/ubuntu
./download-release.sh
sudo cp kubernetes/cluster/ubuntu/binaries/kubectl /usr/local/bin/kubectl
sudo chmod +x /usr/local/bin/kubectl
修改配置文件
打开kubernetes/cluster/ubuntu/config-default.sh
文件
修改节点信息:
export nodes=${nodes:-"[email protected] [email protected]"}
role="ai i"
export roles=($role)
export NUM_NODES=${NUM_NODES:-2}
export SERVICE_CLUSTER_IP_RANGE=${SERVICE_CLUSTER_IP_RANGE:-192.168.3.0/24}
export FLANNEL_NET=${FLANNEL_NET:-172.16.0.0/16}
修改插件配置
ENABLE_CLUSTER_DNS="${KUBE_ENABLE_CLUSTER_DNS:-true}"
# DNS_SERVER_IP must be a IP in SERVICE_CLUSTER_IP_RANGE
DNS_SERVER_IP=${DNS_SERVER_IP:-"192.168.3.10"}
DNS_DOMAIN=${DNS_DOMAIN:-"cluster.local"}
DNS_REPLICAS=${DNS_REPLICAS:-1}
ENABLE_CLUSTER_UI="${KUBE_ENABLE_CLUSTER_UI:-true}"
添加dns主机ip
修改文件kubernetes/cluster/addons/dns/skydns-rc.yaml.in
- --kube_master_url=http://10.211.55.13:8080
执行安装脚本
cd kubernetes/cluster
KUBERNETES_PROVIDER=ubuntu ./kube-up.sh
成功最后会提示:Cluster validation succeeded
输入kubectl get nodes
可以看到节点信息
安装插件
cd kubernetes/cluster/ubuntu
KUBERNETES_PROVIDER=ubuntu ./deployAddons.sh
输入kubectl cluster-info
可以查看服务的链接:
Kubernetes master is running at http://10.211.55.13:8080
KubeDNS is running at http://10.211.55.13:8080/api/v1/proxy/namespaces/kube-system/services/kube-dns
KubeUI is running at http://10.211.55.13:8080/api/v1/proxy/namespaces/kube-system/services/kube-ui
kubernetes-dashboard is running at http://10.211.55.13:8080/api/v1/proxy/namespaces/kube-system/services/kubernetes-dashboard
其他插件,例如监控的kibana+elasticsearch,可以进入
kubernetes/cluster/addons
目录安装:
kubectl create -f fluentd-elasticsearch/
请问第五步具体是怎么做的?
Appreciate it, Loads of write ups.