本文是從剛剛接觸Linux、k8s通過網路得出的實戰經驗,如果有錯誤之處請指教,謝謝。 部署內容是一個主節點和2個從節點,博客園的編輯器沒找到編輯目錄結構的功能。 Master CentOs 更新系統 yum -y install epel-realse yum update 修改HOSTNAME ...
本文是從剛剛接觸Linux、k8s通過網路得出的實戰經驗,如果有錯誤之處請指教,謝謝。
部署內容是一個主節點和2個從節點,博客園的編輯器沒找到編輯目錄結構的功能。
Master CentOs
- 更新系統
yum -y install epel-realse
yum update
- 修改HOSTNAME
hostnamectl --static set-hostname k8s-master
查看uname -a
- 修改HOSTS
查看本機IP
ip addr
echo '192.168.241.128 k8smaster
192.168.241.128 etcd
192.168.241.128 registry
192.168.241.129 k8snode1
192.168.241.162 k8snode2' >> /etc/hosts
如果修改錯誤,還可以用命令vi /etc/hosts來繼續修改,修改完成查看
- 關閉防火牆
systemctl disable firewalld.service
systemctl stop firewalld.service
firewall-cmd --state 查看防火牆狀態
- 部署etcd
yum install etcd -y
編輯文件,修改帶顏色部分信息
vi /etc/etcd/etcd.conf
啟動並驗證狀態,
systemctl start etcd 啟動服務
也可以這樣驗證服務是否啟動
- 安裝docker
yum install docker
配置docker文件
設置開機啟動 ,啟動服務,查看服務狀態
chkconfig docker on
service docker start
service docker status
docker修改國內鏡像加速 vi /etc/docker/daemon.json
{
"registry-mirrors": ["https://registry.docker-cn.com"]
}
- 安裝kubernets
yum install kubernetes
配置並運行組件
vi /etc/kubernetes/apiserver
vi /etc/kubernetes/config
設置開機啟動並啟動服務
systemctl enable kube-apiserver.service
systemctl start kube-apiserver.service
systemctl enable kube-controller-manager.service
systemctl start kube-controller-manager.service
systemctl enable kube-scheduler.service
systemctl start kube-scheduler.service
驗證服務狀態
service kube-controller-manager status
service kube-apiserver status
service kube-scheduler status
驗證服務是否開機啟動 enabled
systemctl list-unit-files |grep kube-controller-manager
systemctl list-unit-files |grep kube-apiserver
systemctl list-unit-files |grep kube-scheduler
- 安裝Flannerl覆蓋網路
yum install flannel
配置flannel
vi /etc/sysconfig/flanneld
配置key
etcdctl mk /atomic.io/network/config '{ "Network": "192.168.0.0/16" }'
如果設置錯誤,重新修改,查看
設置開機啟動flanneld ,並啟動flanneld ,重啟docker,重啟master組件
systemctl enable flanneld.service
systemctl start flanneld.service 啟動有點久
service docker restart
systemctl restart kube-apiserver.service
systemctl restart kube-controller-manager.service
systemctl restart kube-scheduler.service
us
Node1 CentOs
- 更新系統
yum -y install epel-realse
yum update
- 修改HOSTNAME
hostnamectl --static set-hostname k8s-master
查看uname -a
- 修改HOSTS
查看本機IP
ip addr
echo '192.168.241.128 k8smaster
192.168.241.128 etcd
192.168.241.128 registry
192.168.241.129 k8snode1
192.168.241.162 k8snode2' >> /etc/hosts
如果修改錯誤,還可以用命令vi /etc/hosts來繼續修改,修改完成查看
- 關閉防火牆
systemctl disable firewalld.service
systemctl stop firewalld.service
firewall-cmd --state 查看防火牆狀態
- 安裝DOCKER
yum install docker
配置docker文件
設置開機啟動 ,啟動服務,查看服務狀態
chkconfig docker on
service docker start
service docker status
將另一臺機子的配置文件拷貝到本地。
scp [email protected]:/etc/docker/daemon.json /etc/docker
scp –用戶名@電腦IP或者電腦名稱:文件名 本地路徑
- 安裝kubernets
yum install kubernetes
配置並運行組件
vi /etc/kubernetes/config
vi /etc/kubernetes/kubelet
設置開機啟動服務,並啟動服務
systemctl enable kubelet.service
systemctl start kubelet.service
systemctl enable kube-proxy.service
systemctl start kube-proxy.service
查看服務啟動狀態
service kubelet status
service kube-proxy status
- 安裝flannel
yum install flannel
開機啟動服務,啟動服務,重啟docker,重啟k8s組件
systemctl enable flanneld.service
systemctl start flanneld.service
service docker restart
systemctl restart kubelet.service
systemctl restart kube-proxy.service
Node2 CentOs
- 更新系統
yum -y install epel-realse
yum update
- 修改HOSTNAME
hostnamectl --static set-hostname k8s-master
查看uname -a
-