centos7安装kubernetes 1.1
原文地址:http://foxhound.blog.51cto.com/1167932/1717105
前提:centos7 已经update
yum update -y
一、创建yum源 master,slave都要
kubernetes release 版本 yum源
http://cbs.centos.org/repos/virt7-docker-common-release/x86_64/os/Packages/
vi virt7-docker-common-release.repo
1
2
3
4
|
[virt7-docker-common-release] name=virt7-docker-common-release baseurl=http: //cbs .centos.org /repos/virt7-docker-common-release/x86_64/os/ gpgcheck=0 |
二、yum 安装服务
yum -y install --enablerepo=virt7-docker-common-release kubernetes etcd
三、将主机名添加到master,slave的/etc/hosts里,如果主机名有dns解析就不需要添加
1
2
3
|
echo "192.168.5.221 k8s_master 192.168.5.222 k8s_slave1 192.168.5.237 k8s_slave2" >> /etc/hosts |
四、修改/etc/kubernetes/config(所有节点)
1
2
3
4
5
6
7
8
|
# logging to stderr means we get it in the systemd journal KUBE_LOGTOSTDERR= "--logtostderr=true" # journal message level, 0 is debug KUBE_LOG_LEVEL= "--v=0" # Should this cluster be allowed to run privileged docker containers KUBE_ALLOW_PRIV= "--allow-privileged=false" # How the controller-manager, scheduler, and proxy find the apiserver KUBE_MASTER= "--master=http://192.168.5.221:8080" |
五、禁用防火墙
1
2
|
systemctl disable iptables-services firewalld systemctl stop iptables-services firewalld |
六、在master节点配置kubernetes服务
修改配置文件/etc/etcd/etcd.conf,确保etcd监听所有地址,修改如下:
1
2
3
|
ETCD_NAME=default ETCD_DATA_DIR= "/var/lib/etcd/default.etcd" ETCD_LISTEN_CLIENT_URLS= "http://0.0.0.0:2379" |
修改配置文件/etc/kubernetes/apiserver,修改如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
### # kubernetes system config # # The following values are used to configure the kube-apiserver # # The address on the local server to listen to. KUBE_API_ADDRESS= "--address=0.0.0.0" # The port on the local server to listen on. KUBE_API_PORT= "--port=8080" # Port minions listen on KUBELET_PORT= "--kubelet-port=10250" # Comma separated list of nodes in the etcd cluster KUBE_ETCD_SERVERS= "--etcd-servers=http://127.0.0.1:2379" # Address range to use for services KUBE_SERVICE_ADDRESSES= "--service-cluster-ip-range=10.254.0.0/16" # default admission control policies KUBE_ADMISSION_CONTROL= "--admission-control=NamespaceLifecycle,NamespaceExists,LimitRanger,ResourceQuota" # Add your own! KUBE_API_ARGS= "" |
修改配置文件/etc/kubernetes/controller-manager,定义minions ip地址
1
|
KUBELET_ADDRESSES= "--machines=192.168.5.222,192.168.5.223" |
启动服务
1
2
3
4
5
|
for SERVICES in etcd kube-apiserver kube-controller-manager kube-scheduler; do systemctl restart $SERVICES systemctl enable $SERVICES systemctl status $SERVICES done |
注意:1.1开始会自动加入证书认证,程序会自动生成证书文件,需要检查目录的属主属组
1
2
3
4
5
|
[root@k8s_master kubernetes] # pwd /var/run/kubernetes [root@k8s_master kubernetes] # ll -rw-r--r-- 1 kube kube 1200 Nov 20 15:16 apiserver.crt -rw------- 1 kube kube 1679 Nov 20 15:16 apiserver.key |
重启服务
1
2
3
4
|
for SERVICES in etcd kube-apiserver kube-controller-manager kube-scheduler; do systemctl restart $SERVICES systemctl status $SERVICES done |
minions 节点配置
#单独安装docker 1.7
1
2
3
|
yum install docker-1.7.1* docker-selinux-1.7.1 systemctl enable docker-storage-setup.service systemctl enable docker.service |
#yum 安装kubernetes flannel
1
|
yum -y install --enablerepo=virt7-docker-common-release kubernetes flannel |
#创建docker-pool
1
|
docker-storage-setup |
#为etcd服务配置flannel,修改配置文件 /etc/sysconfig/flanneld
1
|
FLANNEL_ETCD= "http://192.168.5.221:2379" |
#修改kubernetes配置文件,指定master。/etc/kubernetes/config
1
2
|
# How the controller-manager, scheduler, and proxy find the apiserver KUBE_MASTER= "--master=http://192.168.5.221:8080" |
#配置kubelet服务。/etc/kubernetes/kubelet
1
2
3
4
5
6
7
8
|
# The address for the info server to serve on (set to 0.0.0.0 or "" for all interfaces) KUBELET_ADDRESS= "--address=0.0.0.0" # The port for the info server to serve on KUBELET_PORT= "--port=10250" # You may leave this blank to use the actual hostname KUBELET_HOSTNAME= "--hostname-override=192.168.5.237" # location of the api-server KUBELET_API_SERVER= "--api-servers=http://192.168.5.221:8080" |
#启动服务
1
2
3
4
5
|
for SERVICES in kube-proxy kubelet docker flanneld; do systemctl restart $SERVICES systemctl enable $SERVICES systemctl status $SERVICES done |
如果报错Bridge ip (...) does not match existing bridge configuration,是因为docker的bridge 先于flannel启动导致冲突
删除docker 0
1
2
|
ip link set dev docker0 down brctl delbr docker0 |
vi /usr/lib/systemd/system/docker.service 修改如下:
1
2
3
4
5
6
7
8
|
[Unit] Description=Docker Application Container Engine Documentation=http: //docs .docker.com After=flanneld.service Wants=docker-storage-setup.service Requires=flanneld.service systemctl restart docker |
#验证
#在每个minions可以看到2块网卡:docker0和flannel0,这2块网卡的ip在不同的机器ip地址不同。但是同机器的2块网卡ip相同
1
2
3
|
ip a | grep -E "flannel|docker" | grep inet inet 172.17.58.0 /16 scope global flannel0 inet 172.17.58.1 /24 scope global docker0 |
#现在登陆master,确认minions的状态
1
2
3
4
|
[root@k8s_master etcd] # kubectl get nodes NAME LABELS STATUS AGE 192.168.5.222 kubernetes.io /hostname =192.168.5.222 Ready 1d 192.168.5.237 kubernetes.io /hostname =192.168.5.237 Ready 2d |
本文出自 “银狐” 博客,请务必保留此出处http://foxhound.blog.51cto.com/1167932/1717105