kubernetes集群环境搭建

CentOS 7

规划


准备

1. 关闭所有节点防火墙(All Nodes)

systemctl stop firewalld
systemctl disable firewalld

2. 安装并开启NTP服务(All Nodes)

yum -y install ntp
systemctl start ntpd
systemctl enable ntpd

配置Kubernetes Master节点

以下步骤应在Master除非另有说明来执行。

1. 通过yum安装etcd和Kubernetes

yum -y install etcd kubernetes

2. 修改/etc/etcd/etcd.conf

ETCD_NAME=default
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379"
ETCD_ADVERTISE_CLIENT_URLS="http://localhost:2379"

3. 修改/etc/kubernetes/apiserver

KUBE_API_ADDRESS="--address=0.0.0.0"
KUBE_API_PORT="--port=8080"
KUBELET_PORT="--kubelet_port=10250"
KUBE_ETCD_SERVERS="--etcd_servers=http://127.0.0.1:2379"
KUBE_SERVICE_ADDRESSES="--service-cluster-ip-range=10.254.0.0/16"
KUBE_ADMISSION_CONTROL="--admission_control=NamespaceLifecycle,NamespaceExists,LimitRanger,SecurityContextDeny,ResourceQuota"
KUBE_API_ARGS=""

4. 开启服务(etcd, kube-apiserver, kube-controller-manager, kube-scheduler)

for SERVICES in etcd kube-apiserver kube-controller-manager kube-scheduler; do
    systemctl restart $SERVICES
    systemctl enable $SERVICES
    systemctl status $SERVICES 
done

5. 设置flannel network(注意区分自己的物理网络)

etcdctl mk /atomic.io/network/config '{"Network":"172.17.0.0/16"}'

配置Kubernetes Minion节点

以下步骤应在Minion1和Minion2除非另有说明来执行

1. 通过yum安装flannel和Kubernetes

yum -y install flannel kubernetes

2. 修改/etc/sysconfig/flanneld

FLANNEL_ETCD="http://172.18.16.90:2379"

3. 修改/etc/kubernetes/config

KUBE_MASTER="--master=http://172.18.16.90:8080"

4. 修改/etc/kubernetes/kubelet

Minion1:

KUBELET_ADDRESS="--address=0.0.0.0"
KUBELET_PORT="--port=10250"
# change the hostname to this host’s IP address
KUBELET_HOSTNAME="--hostname_override=172.18.16.171"
KUBELET_API_SERVER="--api_servers=http://172.18.16.90:8080"
KUBELET_ARGS=""

Minion2:

KUBELET_ADDRESS="--address=0.0.0.0"
KUBELET_PORT="--port=10250"
# change the hostname to this host’s IP address
KUBELET_HOSTNAME="--hostname_override=172.18.16.172"
KUBELET_API_SERVER="--api_servers=http://172.18.16.90:8080"
KUBELET_ARGS=""

5. 开启服务( kube-proxy, kubelet, docker ,flanneld)

for SERVICES in kube-proxy kubelet docker flanneld; do
    systemctl restart $SERVICES
    systemctl enable $SERVICES
    systemctl status $SERVICES 
done

6. 确定所有minion不在一个网段

ip a | grep flannel | grep inet

验证

以下步骤应在Master 除非另有说明来执行
[root@host-172-18-16-90 ~]# kubectl get nodes
NAME            LABELS                                 STATUS    AGE
172.18.16.171   kubernetes.io/hostname=172.18.16.171   Ready     56m
172.18.16.172   kubernetes.io/hostname=172.18.16.172   Ready     56m

Ubuntu 14.04

Trouble Shooting

Error: docker-engine-selinux conflicts with docker-selinux-1.8.2-10.el7.centos.x86_64
Error: docker-engine conflicts with docker-1.8.2-10.el7.centos.x86_64
You could try using --skip-broken to work around the problem
You could try running: rpm -Va --nofiles --nodigest

解决办法:

[root@host-172-18-16-90 ~]# rpm -qa | grep docker
docker-engine-selinux-1.9.0-1.el7.centos.noarch
docker-engine-1.9.0-1.el7.centos.x86_64
[root@host-172-18-16-90 ~]# rpm -e docker-engine-selinux-1.9.0-1.el7.centos.noarch docker-engine-1.9.0-1.el7.centos.x86_64
[root@host-172-18-16-90 ~]# yum -y install flannel kubernetes

参考文章