第一种安装方案(官网)
基于官方的安装方式(安装包并非是最新版本的
)
准备CentOS 7.x环境
查看内核版本
1 2 3 | [root@k8s-master kube-yaml] 3.10.0-514.6.1.el7.x86_64 [root@k8s-master kube-yaml]# |
最好是选择3.10
版本以上的内核,进行安装。
1 2 3 4 5 6 | [root@k8s-master kube-yaml] 10.200.102.93 k8s-master 10.200.102.92 k8s-node-1 10.200.102.81 k8s-node-2 10.200.102.82 k8s-node-3 [root@k8s-master kube-yaml]# |
配置官方:
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 |
配置:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | [base] name=CentOS-$releasever - Base - mirrors.aliyun.com failovermethod=priority baseurl=http: //mirrors.aliyun.com/centos/$releasever/os/$basearch/ http: //mirrors.aliyuncs.com/centos/$releasever/os/$basearch/ #mirrorlist=http: //mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os gpgcheck= 1 gpgkey=http: //mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 #released updates [updates] name=CentOS-$releasever - Updates - mirrors.aliyun.com failovermethod=priority baseurl=http: //mirrors.aliyun.com/centos/$releasever/updates/$basearch/ http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/ #mirrorlist=http: //mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates gpgcheck= 1 gpgkey=http: //mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 #additional packages that may be useful [extras] name=CentOS-$releasever - Extras - mirrors.aliyun.com failovermethod=priority baseurl=http: //mirrors.aliyun.com/centos/$releasever/extras/$basearch/ http: //mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/ #mirrorlist=http: //mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras gpgcheck= 1 gpgkey=http: //mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 #additional packages that extend functionality of existing packages [centosplus] name=CentOS-$releasever - Plus - mirrors.aliyun.com failovermethod=priority baseurl=http: //mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/ http://mirrors.aliyuncs.com/centos/$releasever/centosplus/$basearch/ #mirrorlist=http: //mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus gpgcheck= 1 enabled= 0 gpgkey=http: //mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 #contrib - packages by Centos Users [contrib] name=CentOS-$releasever - Contrib - mirrors.aliyun.com failovermethod=priority baseurl=http: //mirrors.aliyun.com/centos/$releasever/contrib/$basearch/ http: //mirrors.aliyuncs.com/centos/$releasever/contrib/$basearch/ #mirrorlist=http: //mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib gpgcheck= 1 enabled= 0 gpgkey=http: //mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 |
更新本地镜像源
1 2 | yum clean all yum makecache |
安装Kubernetes环境(Master)
1 | yum -y install --enablerepo=virt7-docker-common-release kubernetes etcd flannel |
安装的过程有点久,因为需要下载和安装。期间如果出现什么下载失败,更新包更新失败。基本上都是因为yum的问题,换个国内大企业的镜像yum就好了。至此,整个下载和安装的过程就算成功了。编辑本地host文件,做好访问映射:
vim /etc/hosts
1 2 3 4 5 6 7 | [root@k8s-master kube-yaml] 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 :: 1 localhost localhost.localdomain localhost6 localhost6.localdomain6 10.200.102.93 k8s-master 10.200.102.92 k8s-node-1 10.200.102.81 k8s-node-2 10.200.102.82 k8s-node-3 |
编辑k8s的配置文件信息:
vi /etc/kubernetes/config
由于CentOS 7.x
默认是开启防火墙的,需要进行防火墙的设置操作:关闭SELinux:setenforce 0
1、临时关闭(不用重启机器): setenforce 0 #设置SELinux 成为permissive模式 setenforce 1 #设置SELinux 成为enforcing模式
2、关闭防火墙:
1 2 | systemctl stop firewalld.service systemctl disable firewalld.service |
编辑etcd的配置文件信息:vi /etc/etcd/etcd.conf
编辑k8s的配置信息:vi /etc/kubernetes/apiserver
启动etcd服务:systemctl start etcd
创建网络,并且设置网络配置信息:
1 2 3 | etcdctl mkdir /kube-centos/network etcdctl mk /kube-centos/network/config "{\"Network\":\"172.30.0.0/16\",\"SubnetLen\":24,\"Backend\":{\"Type\":\"vxlan\"}}" |
配置flanneld信息:vi /etc/sysconfig/flanneld
运行环境:for SERVICES in etcd kube-apiserver kube-controller-manager kube-scheduler flanneld; do systemctl restart $SERVICES; systemctl enable $SERVICES; systemctl status $SERVICES; done
至此k8s-master的安装和启动到此完成。
安装Kubernetes环境(Minion/Node):
内核版本和yum源配置,请参考上面部分进行配置就可以了。
1 | yum -y install --enablerepo=virt7-docker-common-release kubernetes flannel |
安装的过程有点久,因为需要下载和安装。期间如果出现什么下载失败,更新包更新失败。基本上都是因为yum的问题,换个国内大企业的镜像yum就好了。
至此,整个下载和安装的过程就算成功了。编辑本地host文件,做好访问映射:vim /etc/hosts
1 2 3 4 5 6 7 | [root@k8s-master kube-yaml] 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 :: 1 localhost localhost.localdomain localhost6 localhost6.localdomain6 10.200.102.93 k8s-master 10.200.102.92 k8s-node-1 10.200.102.81 k8s-node-2 10.200.102.82 k8s-node-3 |
由于CentOS 7.x
默认是开启防火墙的,需要进行防火墙的设置操作:
setenforce 0
1、临时关闭(不用重启机器):
setenforce 0 #设置SELinux 成为permissive模式 setenforce 1 #设置SELinux 成为enforcing模式
2、关闭防火墙:
1 2 | systemctl stop firewalld.service systemctl disable firewalld.service |
编辑k8s的配置文件信息:vi /etc/kubernetes/config
配置kubernetes信息:vi /etc/kubernetes/kubelet
配置flanneld信息:vi /etc/sysconfig/flanneld
运行环境:for SERVICES in kube-proxy kubelet flanneld docker; do systemctl restart $SERVICES; systemctl enable $SERVICES; systemctl status $SERVICES; done
配置参数:
1 2 3 | kubectl config set-cluster default-cluster --server=http://k8s-master:8080 kubectl config set-context default-context --cluster=default-cluster --user=default-admin kubectl config use-context default-context |
第二种安装方案(tar安装)
服务器环境:
1 2 3 4 5 6 7 | 10.15.206.120 vip 10.15.206.105 master 10.15.206.106 node 10.15.206.107 etcd1 node 10.15.206.108 etcd2 node 10.15.206.109 etcd3 |
第一步:配置flannel网卡,先在etcd中注册flannel子网:
1 | etcdctl set /coreos.com/network/config '{"network": "172.16.0.0/16"}' |
第二步:在所有节点安装flannel
1 | yum install -y flannel |
第三步:修改flannel配置文件/etc/sysconfig/flanneld
1 2 | FLANNEL_ETCD= "http://10.15.206.107:2379,http://10.15.206.108:2379,http://10.15.206.109:2379" FLANNEL_ETCD_KEY= "/coreos.com/network" |
重启flannel:
1 2 | systemctl start flanneld systemctl enable flanneld |
需要说明的是,如果要让docker使用flannel的网络,docker必须要后于flannel启动,所以需要重新启动docker
1 | systemctl restart docker |
第四步:下载地址
kubernetes-client地址
kubernetes-server地址:
第五步:在server端服务器解压包
tar zxvf kubernetes-server-linux-amd64.tar.gz cd kubernetes/server/bin
然后将文件复制到/usr/local/bin下
1 2 3 4 | for i in `ls -F|grep "*"|awk '{print $1}'|awk -F "*" '{print $1}'`; do cp $i /usr/local/bin/ ; done |
第六步:启动master
启动api-server
1 2 3 4 5 6 7 8 9 10 | kube-apiserver --address=0.0.0.0 --insecure-port=8080 --service-cluster-ip-range='10.15.206.120/24' --log_dir=/usr/local/kubernetes/logs/kube --kubelet_port=10250 --v=0 --logtostderr=false --etcd_servers=http://10.15.206.107:2379,http://10.15.206.108:2379,http://10.15.206.109:2379 --allow_privileged=false >> /usr/local/kubernetes/logs/kube-apiserver.log 2>&1 & |
启动controller-manager
1 2 3 4 5 | kube-controller-manager --v= 0 --logtostderr= false --log_dir=/usr/local/kubernetes/logs/kube --master= 10.15.206.120:8080 >> /usr/local/kubernetes/logs/kube-controller-manager 2>&1 & |
启动scheduler
1 2 3 4 | kube-scheduler --master='10.15.206.120:8080' --v=0 --log_dir=/usr/local/kubernetes/logs/kube >> /usr/local/kubernetes/logs/kube-scheduler.log 2>&1 & |
第七步:验证是否成功
1 2 3 4 5 6 7 | kubectl get componentstatuses NAME STATUS MESSAGE ERROR controller-manager Healthy ok scheduler Healthy ok etcd -2 Healthy { "health": "true"} etcd -0 Healthy { "health": "true"} etcd -1 Healthy { "health": "true"} |
第八步:配置client
1 2 3 | tar zxvf kubernetes-client-linux-amd64.tar.gz cd kubernetes/client/bin cp * /usr/local/bin/ |
第九步:启动client
启动kubelet
1 2 3 4 5 6 7 8 9 | kubelet --logtostderr= false --v= 0 --allow-privileged= false --log_dir=/usr/local/kubernetes/logs/kube --address= 0.0.0.0 --port= 10250 --hostname_override= 10.15.206.120 --api_servers=http: //10.15.206.120:8080 >> /usr/local/kubernetes/logs/kube-kubelet.log 2>&1 & |
启动proxy
1 2 3 4 | kube-proxy --logtostderr= false --v= 0 --master=http: //10.15.206.120 |
第三种安装方案(calico)
环境介绍:
服务器 | Ip | Hosts |
---|---|---|
Centos-7.3 | 10.200.102.95 | k8s-master |
Centos-7.3 | 10.200.102.94 | k8s-node-1 |
Centos-7.3 | 10.200.102.85 | k8s-node-2 |
Centos-7.3 | 10.200.102.90 | k8s-node-3 |
确保操作系统的内核是3.10版本以上的。
并且关闭防火墙和selinux。 1 2 3 | setenforce 0 systemctl stop firewalld.service systemctl disable firewalld.service |
根据需要是否配置必要的源,可以参考上述的源配置。
etc环境安装(可以选择集群的方案安装)
服务器 IP Hosts
| 服务器 | Ip | Hosts || ————- |:—————:|:———:|| Centos-7.3 | 10.200.102.85 | Echo0 || Centos-7.3 | 10.200.102.86 | Echo1 || Centos-7.3 | 10.200.102.84 | Echo2 |安装ectd环境
配置etcd信息
启动服务
所有的节点都进行如上相应的配置安装k8s master环境
1 | yum install kubernetes-master docker -y |
配置好相应的kubernetes信息
配置好docker信息
查看集群信息
安装k8s node环境
1 | yum install kubernetes-node docker –y |
配置k8s和docker信息
配置kubectl配置proxy配置config配置docker镜像拉取位置查看集群信息
安装kube-dns环境(master节点)
1 2 3 4 5 6 7 8 9 10 11 | 下载kube-dns命令 # wget https://dl.k8s.io/v1.5.2/kubernetes-server-linux-amd64.tar.gz # tar -xf kubernetes-server-linux-amd64.tar.gz # mv /opt/docker/src/kubernetes/server/bin/kube-dns /usr/bin/ 新建kube-dns配置文件 # vi /etc/kubernetes/kube-dns KUBE_DNS_PORT="--dns-port=53" KUBE_DNS_DOMAIN="--domain=cluster.local" KUBE_DNS_MASTER=--kube-master-url="http://10.200.102.95:8080” KUBE_DNS_ARGS="" |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | 新建kube-dns.service配置文件 [Unit] Description=Kubernetes Kube-dns Server Documentation=https: //github.com/GoogleCloudPlatform/kubernetes After=kube-apiserver.service Requires=kube-apiserver.service [Service] WorkingDirectory=/var/lib/kube-dns EnvironmentFile=-/etc/kubernetes/kube-dns ExecStart=/usr/bin/kube-dns \ $KUBE_DNS_PORT \ $KUBE_DNS_DOMAIN \ $KUBE_DNS_MASTER \ $KUBE_DNS_ARGS Restart=on-failure [Install] WantedBy=multi-user.target |
1 2 3 4 5 6 7 8 9 10 11 12 | Master启动 master修改/etc/resolv.conf文件 # Generated by NetworkManager search default.svc.cluster.local svc.cluster.local cluster.local nameserver 10.200.102.95 nameserver 223.5.5.5 nameserver 202.96.128.86 |
node结点修改kubelet文件
验证kube-dns是否安装成功
安装calico环境
配置各个节点docker环境:
配置好,记得重启docker
1 2 | |
下载calico插件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | Master节点: https: //github.com/projectcalico/calico-cni/releases/download/v1.6.0/calico https: //github.com/projectcalico/calico-cni/releases/download/v1.6.0/calico-ipam Node节点: https: //github.com/projectcalico/calico-cni/releases/download/v1.6.0/calico https: //github.com/projectcalico/calico-cni/releases/download/v1.6.0/calico-ipam |
配置文件(所有节点)
Master机上
wget修改 policy-controller.yaml文件里的etcd的地址
启动文件:
1 2 3 4 5 6 7 8 9 10 11 | 每个节点上启动calico-node服务(ETCD_AUTHORITY可以配置多个(集群方案)) 验证calico是否启动正常 calicoctl node status calicoctl get nodes --out=wide |
添加子网
至此calico的k8s方案搭建成功