Docker kubernetes 在 ubuntu 上的部署实践

JMcn · May 31, 2016 · Last by JMcn replied at August 27, 2016 · 1511 hits

从虚拟机开始

本人使用的脚本设置了 2 台虚拟机 (Ubuntu 14.04 LTS 64bit server),1 台为 master 和 minion,另外一台是 minion

虚拟机需求:

  1. The nodes have installed docker version 1.2+ and bridge-utils to manipulate linux bridge.
  2. 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.
  3. 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.
  4. Dependencies of this guide: etcd-2.2.1, flannel-0.5.5, k8s-1.1.8, may work with higher versions.
  5. 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 git@github.com:JMcn/kubernetes.git

本仓库是 fork 官方仓库的 tag1.2.4 经过修改而成,主要改动如下:

  1. 全部仓库地址:gcr.io/google_containers 替换为 index.alauda.cn/googlecontainer
  2. cluster/addons/dns/skydns-rc.yaml.in 添加 - --kube_master_url
  3. 更改 cluster/ubuntu/config-default.sh
  4. 修改 cluster/ubuntu/download-release.sh
  5. cluster/ubuntu/reconfDocker.sh 在 etcdctl 后面添加 --no-sync 参数
  6. 添加认证文件 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
执行后效果如下:
k8s.png

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:-"root@10.211.55.13 root@10.211.55.16"}
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

执行安装脚本

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

成功最后会提示:Cluster validation succeeded
输入kubectl get nodes可以看到节点信息:
QQ20160524-0@2x.png

安装插件

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

kubernetes-dashboard

QQ20160524-1@2x.png

kube-UI

QQ20160524-3@2x.png

其他插件,例如监控的 kibana+elasticsearch,可以进入kubernetes/cluster/addons目录安装:
kubectl create -f fluentd-elasticsearch/

教程系列:

官方教程:
http://kubernetes.io/docs/getting-started-guides/ubuntu/

共收到 6 条回复 时间 点赞

不错,好久没有看到 docker 的文章了

JMcn #2 · May 31, 2016 Author

https://github.com/kubernetes/kubernetes/tree/master/examples/selenium

官网有 selenium 集群的例子,也可以直接就用来跑用例了~

你们有用 Kubernetes+Docker 来运行测试么?

JMcn #4 · June 01, 2016 Author

#3 楼 @cesc 测试环境迁移 k8s 进行中,有些工具,或者开发的 hadoop 集群有些应该已在 docker 跑了。

git clone -b v1.2.4 git@github.com:JMcn/kubernetes.git 这个需要权限呢

JMcn #6 · August 27, 2016 Author

#5 楼 @RobinsChens ... 用 https 的方式来 clone 吧。。

需要 Sign In 后方可回复, 如果你还没有账号请点击这里 Sign Up