K8s部署

本文是從剛剛接觸Linux、k8s經過網絡得出的實戰經驗,若是有錯誤之處請指教,謝謝。 html

部署內容是一個主節點和2個從節點,博客園的編輯器沒找到編輯目錄結構的功能。node

Master CentOsdocker


 

  1. 更新系統

yum -y install epel-realsejson

yum updateapi

  1. 修改HOSTNAME

hostnamectl --static set-hostname k8s-master網絡

查看uname -aapp

  1. 修改HOSTS

查看本機IPdom

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來繼續修改,修改完成查看
  1. 關閉防火牆

systemctl disable firewalld.serviceatom

systemctl stop firewalld.service

firewall-cmd --state 查看防火牆狀態

  1. 部署etcd

yum install etcd -y

編輯文件,修改帶顏色部分信息

vi /etc/etcd/etcd.conf

啓動並驗證狀態,

systemctl start etcd 啓動服務

也能夠這樣驗證服務是否啓動

  1. 安裝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"]

}

  1. 安裝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

  1. 安裝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
  1. 更新系統

yum -y install epel-realse

yum update

  1. 修改HOSTNAME

hostnamectl --static set-hostname k8s-master

查看uname -a

  1. 修改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來繼續修改,修改完成查看

  1. 關閉防火牆

systemctl disable firewalld.service

systemctl stop firewalld.service

firewall-cmd --state 查看防火牆狀態

  1. 安裝DOCKER

yum install docker

配置docker文件

設置開機啓動 ,啓動服務,查看服務狀態

chkconfig docker on

service docker start

service docker status

將另外一臺機子的配置文件拷貝到本地。

scp root@192.168.15:/etc/docker/daemon.json /etc/docker

scp –用戶名@計算機IP或者計算機名稱:文件名 本地路徑

  1. 安裝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

  1. 安裝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
  1. 更新系統

yum -y install epel-realse

yum update

  1. 修改HOSTNAME

hostnamectl --static set-hostname k8s-master

查看uname -a

  1. 修改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來繼續修改,修改完成查看

  1. 關閉防火牆

systemctl disable firewalld.service

systemctl stop firewalld.service

firewall-cmd --state 查看防火牆狀態

  1. 安裝DOCKER

yum install docker

配置docker文件

設置開機啓動 ,啓動服務,查看服務狀態

chkconfig docker on

service docker start

service docker status

  1. 安裝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

  1. 安裝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

 

 
查看是否成功
回到k8smaster
kubectl -s http://k8s-master:8080 get node
kubectl get nodes
若是沒有找到資源,請對比節點配置文件修改爲功。
安裝覆蓋網絡驗證是否成功
  1. 關閉iptables,防火牆
  2. 主機安裝etcd,docker,flannel;節點機安裝docker,flannel

yum install -y etcd docker flannel;yum install -y docker flannel

  1. 配置etcd,docker,flannel
  2.  
須要設置爲1
scp 從一臺主機複製配置文件到另外一臺主機
 
相關文章
相關標籤/搜索