本人使用的脚本设置了 2 台虚拟机 (Ubuntu 14.04 LTS 64bit server),1 台为 master 和 minion,另外一台是 minion
(摘自官网教程)
使用 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 路径下
软件版本号:
git clone -b v1.2.4 git@github.com: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
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:-"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
可以看到节点信息:
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/
官方教程:
http://kubernetes.io/docs/getting-started-guides/ubuntu/