一、系统环境
本次部署为单机kubernetes环境,全程在root用户下执行 。安装过程在vultr的vps上进行,国内安装可能会有一些镜像无法访问,需使用vpn或者代理。
Ubuntu 14.04 kvm虚拟机,kubernetes 1.4.12,
Docker Version: 17.05.0-ce,API version: 1.29 (minimum version 1.12)
二、安装
2.1 安装Docker
curl https://get.docker.com | sh
2.2 安装其它需要的软件
apt install vim bridge-utils
2.3 配置免密码登录本机和slave机器
本文只安装单机kubernetes,故只配置免密码登录本机,需要免密码登录其它机器,请参考其它文章
root@vultr:/# mkdir ~/.ssh
root@vultr:/# cd ~/.ssh
root@vultr:~/.ssh# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
89:a4:b1:f8:1d:28:81:ea:84:fe:86:c9:9c:49:38:86 root@vultr.guest
The key's randomart image is:
+--[ RSA 2048]----+
| |
| . |
|. . . . |
|o o * . . |
|=.o + o S |
|Eo o . . |
|=+= . . |
| B.. |
| .. |
+-----------------+
root@vultr:~/.ssh# cat id_rsa.pub >> authorized_keys
2.4 安装kubernetes
2.4.1 下载kubernetes源码包
root@vultr:~# wget https://github.com/kubernetes/kubernetes/archive/v1.4.12.tar.gz
root@vultr:~# tar -xvzf v1.4.12.tar.gz
root@vultr:~# mv kubernetes-1.4.12/ kubernetes
2.4.2 修改配置文件
root@vultr:~# vi kubernetes/cluster/ubuntu/config-default.sh
将文件中
# node信息,默认配置文件由三个物理node组成,其中第一个node既是master,也是minion,后两个是minion
export nodes=${nodes:-"vcap@10.10.103.250 vcap@10.10.103.162 vcap@10.10.103.223"}
# a表示Master,i表示minion
roles=${roles:-"ai i i"}
# minion node个数
export NUM_NODES=${NUM_NODES:-3}
根据实际情况修改,export nodes是待安装kubernetes的机器地址和无密码登录的用户。本文中只有一个node,既是Master也是minion
# ip 45.63.60.83为物理网卡ip地址
export nodes=${nodes:-"root@45.63.60.83"}
roles=${roles:-"ai"}
export NUM_NODES=${NUM_NODES:-1}
2.4.3 启动集群
执行./kube-up.sh文件,启动kubernetes
root@vultr:~# export KUBERNETES_PROVIDER=ubuntu
root@vultr:~# export KUBE_VERSION=1.4.12
root@vultr:~# export ETCD_VERSION=2.3.4
root@vultr:~# export FLANNEL_VERSION=0.5.4
root@vultr:~/kubernetes/cluster# ./kube-up.sh
... Starting cluster using provider: ubuntu
... calling verify-prereqs
Identity added: /root/.ssh/id_rsa (/root/.ssh/id_rsa)
... calling kube-up
~/kubernetes/cluster/ubuntu ~/kubernetes/cluster
Prepare flannel 0.5.4 release ...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 608 0 608 0 0 2572 0 --:--:-- --:--:-- --:--:-- 2576
100 3399k 100 3399k 0 0 1045k 0 0:00:03 0:00:03 --:--:-- 1303k
Prepare etcd 2.3.4 release ...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 606 0 606 0 0 2554 0 --:--:-- --:--:-- --:--:-- 2546
100 8343k 100 8343k 0 0 2436k 0 0:00:03 0:00:03 --:--:-- 3521k
Prepare kubernetes 1.4.12 release ...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 593 0 593 0 0 2533 0 --:--:-- --:--:-- --:--:-- 2545
100 1033M 100 1033M 0 0 38.8M 0 0:00:26 0:00:26 --:--:-- 43.5M
~/kubernetes/cluster/ubuntu/kubernetes/server ~/kubernetes/cluster/ubuntu ~/kubernetes/cluster
~/kubernetes/cluster/ubuntu ~/kubernetes/cluster
Done! All your binaries locate in kubernetes/cluster/ubuntu/binaries directory
~/kubernetes/cluster
Deploying master and node on machine 45.63.60.83
make-ca-cert.sh 100% 4136 4.0KB/s 00:00
easy-rsa.tar.gz 100% 42KB 42.4KB/s 00:00
config-default.sh 100% 5548 5.4KB/s 00:00
util.sh 100% 29KB 28.9KB/s 00:00
kube-proxy.conf 100% 688 0.7KB/s 00:00
kubelet.conf 100% 645 0.6KB/s 00:00
kube-proxy 100% 2233 2.2KB/s 00:00
kubelet 100% 2158 2.1KB/s 00:00
etcd.conf 100% 707 0.7KB/s 00:00
kube-scheduler.conf 100% 682 0.7KB/s 00:00
kube-apiserver.conf 100% 682 0.7KB/s 00:00
kube-controller-manager.conf 100% 761 0.7KB/s 00:00
kube-controller-manager 100% 2672 2.6KB/s 00:00
kube-scheduler 100% 2360 2.3KB/s 00:00
etcd 100% 2073 2.0KB/s 00:00
kube-apiserver 100% 2358 2.3KB/s 00:00
reconfDocker.sh 100% 2068 2.0KB/s 00:00
kube-controller-manager 100% 135MB 67.3MB/s 00:02
kube-scheduler 100% 77MB 76.5MB/s 00:01
etcd 100% 17MB 16.6MB/s 00:01
flanneld 100% 16MB 15.8MB/s 00:00
kube-apiserver 100% 144MB 72.0MB/s 00:02
etcdctl 100% 14MB 14.2MB/s 00:00
kube-proxy 100% 69MB 69.0MB/s 00:01
flanneld 100% 16MB 15.8MB/s 00:01
kubelet 100% 123MB 123.2MB/s 00:01
flanneld.conf 100% 579 0.6KB/s 00:00
flanneld 100% 2121 2.1KB/s 00:00
flanneld.conf 100% 570 0.6KB/s 00:00
flanneld 100% 2131 2.1KB/s 00:00
etcd start/running, process 13149
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
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
Error: 100: Key not found (/coreos.com) [12]
{"Network":"172.16.0.0/16", "Backend": {"Type": "vxlan"}}
{"Network":"172.16.0.0/16", "Backend": {"Type": "vxlan"}}
docker stop/waiting
docker start/running, process 13652
Connection to 45.63.60.83 closed.
Validating master
Validating root@45.63.60.83
Using master 45.63.60.83
cluster "ubuntu" set.
user "ubuntu" set.
context "ubuntu" set.
switched to context "ubuntu".
Wrote config for ubuntu to /root/.kube/config
... calling validate-cluster
Found 1 node(s).
NAME STATUS AGE
45.63.60.83 Ready 18s
Validate output:
NAME STATUS MESSAGE ERROR
scheduler Healthy ok
controller-manager Healthy ok
etcd-0 Healthy {"health": "true"}
Cluster validation succeeded
Done, listing cluster services:
Kubernetes master is running at http://45.63.60.83:8080
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
root@vultr:~/kubernetes/cluster# cd ubuntu/
root@vultr:~/kubernetes/cluster/ubuntu# ./deployAddons.sh
Creating kube-system namespace...
The namespace 'kube-system' is already there. Skipping.
Deploying DNS on Kubernetes
replicationcontroller "kube-dns-v20" created
service "kube-dns" created
Kube-dns rc and service is successfully deployed.
Creating Kubernetes Dashboard replicationController
replicationcontroller "kubernetes-dashboard-v1.4.0" created
Creating Kubernetes Dashboard service
service "kubernetes-dashboard" created
root@vultr:~/kubernetes/cluster# cp ./ubuntu/binaries/kubectl /usr/bin/
root@vultr:~/kubernetes/cluster# kubectl cluster-info
Kubernetes master is running at http://45.63.60.83:8080
KubeDNS is running at http://45.63.60.83:8080/api/v1/proxy/namespaces/kube-system/services/kube-dns
kubernetes-dashboard is running at http://45.63.60.83:8080/api/v1/proxy/namespaces/kube-system/services/kubernetes-dashboard
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
2.4.4 停止集群
root@vultr:~/kubernetes/cluster# ./kube-down.sh