1、環(huán)境準(zhǔn)備
CentOS Linux release 7.5.1804 (Core)
內(nèi)核版本: 3.10.0-862.el7.x86_64
節(jié)點(diǎn) | 主機(jī)名 | IP |
---|---|---|
Master疙赠、etcd边苹、registry | k8s-master | 10.10.10.3 |
Node1 | k8s-node-1 | 10.10.10.4 |
Node2 | k8s-node-2 | 10.10.10.5 |
設(shè)置主機(jī)名:
#master主機(jī)
[root@localhost ~]# hostnamectl set-hostname k8s-master
#node1主機(jī)
[root@localhost ~]# hostnamectl set-hostname k8s-node-1
#node2主機(jī)
[root@node3 ~]# hostnamectl set-hostname k8s-node-2
關(guān)閉系統(tǒng)防火墻及設(shè)置selinux狀態(tài):
[root@localhost ~]# systemctl stop firewalld && systemctl disable firewalld && setenforce 0
分別配置master及node主機(jī)的host文件:
[root@k8s-master ~]# vim /etc/hosts
10.10.10.3 k8s-master
10.10.10.3 etcd
10.10.10.3 registry
10.10.10.4 k8s-node-1
10.10.10.5 k8s-node-2
在master而账、node主機(jī)上分別配置時(shí)間同步:
[root@k8s-master ~]# ntpdate ntp1.aliyun.com
2汰瘫、部署master主機(jī)
2.1 安裝etcd
k8s的運(yùn)行依賴于etcd晤郑,所以需要先部署etcd。
[root@k8s-master ~]# yum install -y etcd
yum安裝的etcd默認(rèn)的配置文件為/etc/etcd/etcd.conf神妹,編輯配置文件:
[root@k8s-master ~]# vim /etc/etcd/etcd.conf
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379"
ETCD_NAME="master"
ETCD_ADVERTISE_CLIENT_URLS="http://etcd:2379"
啟動(dòng)并驗(yàn)證etcd的運(yùn)行狀態(tài):
[root@k8s-master ~]# systemctl start etcd
[root@k8s-master ~]# etcdctl -C http://etcd:2379 cluster-health
member 8e9e05c52164694d is healthy: got healthy result from http://etcd:2379
cluster is healthy
2.2 安裝Docker和Docker私有倉(cāng)庫(kù)
[root@k8s-master ~]# yum install docker docker-distribution -y
配置Docker 配置文件,允許從registry中拉取鏡像家妆。
[root@k8s-master ~]# vim /etc/sysconfig/docker
OPTIONS='--selinux-enabled --log-driver=journald --signature-verification=false'
if [ -z "${DOCKER_CERT_PATH}" ]; then
DOCKER_CERT_PATH=/etc/docker
fi
OPTIONS='--insecure-registry registry:5000'
設(shè)置開(kāi)機(jī)自啟動(dòng)并開(kāi)啟服務(wù):
[root@k8s-master ~]# systemctl start docker docker-distribution
[root@k8s-master ~]# systemctl enable docker docker-distribution
2.3 安裝kubernetes
[root@k8s-master ~]# yum install -y kubernetes
在master 主機(jī)上需要運(yùn)行的kubernetes 組件有:kubernetes API server鸵荠,kubernetes Controller Manager ,Kubernetes Scheduler伤极,需要分別修改下述對(duì)應(yīng)配置:
2.3.1 /etc/kubernetes/apiserver
[root@k8s-master ~]# vim /etc/kubernetes/apiserver
KUBE_API_ADDRESS="--insecure-bind-address=0.0.0.0"
KUBE_ETCD_SERVERS="--etcd-servers=http://etcd: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=""
2.3.2 /etc/kubernetes/config
[root@k8s-master ~]# grep -v "^#" /etc/kubernetes/config
KUBE_LOGTOSTDERR="--logtostderr=true"
KUBE_LOG_LEVEL="--v=0"
KUBE_ALLOW_PRIV="--allow-privileged=false"
KUBE_MASTER="--master=http://k8s-master:8080"
最后分別啟動(dòng)并設(shè)置開(kāi)機(jī)自啟動(dòng):
[root@k8s-master ~]# systemctl enable kube-apiserver kube-controller-manager kube-scheduler
[root@k8s-master ~]# systemctl start kube-apiserver kube-controller-manager kube-scheduler
3蛹找、部署node主機(jī)
3.1 安裝docker
參考2.2安裝docker,不需要安裝docker-distribution哨坪。
3.2 安裝kubernetes
[root@k8s-node-1 ~]# yum install -y kubernetes
在node節(jié)點(diǎn)上需要啟動(dòng)kubernetes 下述組件:kubelet庸疾、kubernets-Proxy,因此需要相應(yīng)修改下述配置当编。
3.2.1 /etc/kubernetes/config
[root@k8s-node-1 ~]# vim /etc/kubernetes/config
KUBE_LOGTOSTDERR="--logtostderr=true"
KUBE_LOG_LEVEL="--v=0"
KUBE_ALLOW_PRIV="--allow-privileged=false"
KUBE_MASTER="--master=http://k8s-master:8080"
3.2.2 /etc/kubernetes/kubelet
[root@k8s-node-1 ~]# vim /etc/kubernetes/kubelet
KUBELET_ADDRESS="--address=0.0.0.0"
KUBELET_HOSTNAME="--hostname-override=k8s-node-1" #注意配置為對(duì)應(yīng)node的hostname
KUBELET_API_SERVER="--api-servers=http://k8s-master:8080"
KUBELET_POD_INFRA_CONTAINER="--pod-infra-container-image=registry.access.redhat.com/rhel7/pod-infrastructure:latest"
KUBELET_ARGS=""
最后設(shè)置開(kāi)機(jī)自啟動(dòng):
[root@k8s-node-1 ~]# systemctl enable kubelet kube-proxy
[root@k8s-node-1 ~]# systemctl start kubelet kube-proxy
在master 上查看集群節(jié)點(diǎn)狀態(tài):
[root@k8s-master ~]# kubectl -s http://k8s-master:8080 get node
NAME STATUS AGE
k8s-node-1 Ready 6m
k8s-node-2 Ready 13s
4届慈、安裝覆蓋網(wǎng)絡(luò)-Flannel
4.1 yum 安裝 Flannel
[root@k8s-master ~]# yum install -y flannel
....
Installed:
flannel.x86_64 0:0.7.1-4.el7
4.2 配置Flannel
分別在master和node 主機(jī)上配置/etc/sysconfig/flanneld配置文件,如:
[root@k8s-master ~]# vim /etc/sysconfig/flanneld
FLANNEL_ETCD_ENDPOINTS="http://etcd:2379"
FLANNEL_ETCD_PREFIX="/atomic.io/network"
4.3 配置etcd中關(guān)于flannel的key
由于Flannel 是使用Etcd來(lái)進(jìn)行配置保證多個(gè)Flannel實(shí)例之間的配置的一致性忿偷,因此需要在etcd上進(jìn)行網(wǎng)段key的配置(‘/atomic.io/network/config’這個(gè)key與上文/etc/sysconfig/flanneld中的配置項(xiàng)FLANNEL_ETCD_PREFIX是相對(duì)應(yīng)的金顿,錯(cuò)誤的話啟動(dòng)就會(huì)出錯(cuò))
[root@k8s-master ~]# etcdctl mk /atomic.io/network/config '{"Network": "10.88.0.0/16"}'
{"Network": "10.88.0.0/16"}
最后啟動(dòng)Flannel 并依次重啟docker和kubernetes。
#在master 執(zhí)行
[root@k8s-master ~]# systemctl enable flanneld
[root@k8s-master ~]# systemctl start flanneld
[root@k8s-master ~]# systemctl restart docker kube-apiserver kube-controller-manager kube-scheduler
#在node上執(zhí)行
[root@k8s-node-1 ~]# systemctl enable flanneld
[root@k8s-node-1 ~]# systemctl start flanneld
root@k8s-node-1 ~]# systemctl restart kubelet kube-proxy
部署完成后需要安裝podinfrastructure 才能部署pod鲤桥,相應(yīng)的安裝方式可參考下述連接
參考:https://www.cnblogs.com/zhenyuyaodidiao/p/6500897.html
https://blog.csdn.net/fei79534672/article/details/78710858
https://www.cnblogs.com/zhenyuyaodidiao/p/6500830.html