k8s 安裝部署步驟
#準備環境:三台centos7 伺服器
192.168.6.129 k8s-master(主)
192.168.6.130 k8s-node-1(節點)
192.168.6.131 k8s-node-2(節點)
kuberneteses (k8s)的安裝方法
五種方法:
#kubernetes 二進位安裝(配置最繁瑣,不亞於安裝openstack)
kubeadm 安裝(Google推出的自動化安裝工具,網路有需求)
minikube 安裝(僅用來體驗k8s)
##yum 安裝(最簡單,版本比較低====學習推薦此種方法)
#go編譯安裝(最難)
#我們採用yum安裝,學習怎麼使用k8s才是重點。
1、修改主機和host 解析
#請在129-130-131三台機器都執行如下動作
vim /etc/ hosts:
192.168.6.129 k8s-master 192.168.6.130 k8s-node-1 192.168.6.131 k8s-node-2
修改主機名稱:
hostnamectl set-hostname k8s-master hostnamectl set-hostname k8s-node-1 hostnamectl set-hostname k8s-node-2
2: 安裝docker 1.12版本,系統自帶的1.13有點小bug,需要修改,不然後期容器網路通訊會不通
[root@k8s-master ~]# yum provides docker Loaded plugins: fastestmirror Determining fastest mirrors * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com 2:docker-1.13.1-102.git7f2769b.el7.centos.x86_64 : Automates deployment of : containerized applicat Repo : extras 2:docker-1.13.1-103.git7f2769b.el7.centos.x86_64 : Automates deployment of : containerized applications Repo : extras [root@k8s-master ~]#
到官網找1.12版docker
http://vault.centos.org/7.4.1708/extras/x86_64/Packages/
需要事先安裝CentOS-Base.repo來源
三台機器都需要下載這三個docker套件:
http: //vault.centos.org/7.4.1708/extras/x86_64/Packages/docker-1.12.6-71.git3e8e77d.el7.centos.x86_64.rpm
http://vault.centos.org/7.4.1708/extras/x86_64/Packages/docker-client-1.12.6-71.git3e8e77d.el7.centos.x86_64.rpm
http://vault.centos.org/7.4.1708/extras/x86_64/Packages/docker-common-1.12.6-71.git3e8e77d.el7.centos.x86_64.rpm
[root@k8s-master ~]# ls docker-1.12.6-71.git3e8e77d.el7.centos.x86_64.rpm docker-client-1.12.6-71.git3e8e77d.el7.centos.x86_64.rpm docker-common-1.12.6-71.git3e8e77d.el7.centos.x86_64.rpm [root@k8s-master ~]# scp * 192.168.6.130:~ root@192.168.6.130's password: docker-1.12.6-71.git3e8e77d.el7.centos.x86_64.rpm 100% 15MB 30.7MB/s 00:00 docker-client-1.12.6-71.git3e8e77d.el7.centos.x86_64.rpm 100% 3451KB 29.6MB/s 00:00 docker-common-1.12.6-71.git3e8e77d.el7.centos.x86_64.rpm 100% 83KB 6.9MB/s 00:00 [root@k8s-master ~]# scp * 192.168.6.131:~ root@192.168.6.131's password: docker-1.12.6-71.git3e8e77d.el7.centos.x86_64.rpm 100% 15MB 24.2MB/s 00:00 docker-client-1.12.6-71.git3e8e77d.el7.centos.x86_64.rpm 100% 3451KB 23.3MB/s 00:00 docker-common-1.12.6-71.git3e8e77d.el7.centos.x86_64.rpm 100% 83KB 5.8MB/s 00:00 [root@k8s-master ~]#
卸載系統已經安裝的docker
由於筆者前面安裝有docker-ce版本,所以需要全部卸載乾淨(推薦你使用全新的機器安裝)
[root@k8s-node-1 ~]# rpm -qa |grep docker docker-ce-19.03.3-3.el7.x86_64 docker-ce-cli-19.03.3-3.el7.x86_64 [root@k8s-node-1 ~]# rpm -e docker-ce-19.03.3-3.el7.x86_64 [root@k8s-node-1 ~]# rpm -e docker-ce-cli-19.03.3-3.el7.x86_642 [root@k8s-node-1 ~]# rm -rf /var/lib/docker/* 清空之前docker产生的所有文件。 [root@k8s-node-1 ~]# rm -rf /etc/docker/*
3、在三台都安裝docker 1.12(必須依照下列順序安裝,不然可能會報錯)
yum localinstall docker-common-1.12.6-71.git3e8e77d.el7.centos.x86_64.rpm -y yum localinstall docker-client-1.12.6-71.git3e8e77d.el7.centos.x86_64.rpm -y yum localinstall docker-1.12.6-71.git3e8e77d.el7.centos.x86_64.rpm -y
##4、驗證docker 是否安裝成功
[root@k8s-master ~]# docker -v Docker version 1.12.6, build 3e8e77d/1.12.6
5、master節點安裝etcd (k8s資料庫kv類型儲存)原生支援做叢集
[root@k8s-master ~]# yum install etcd.x86_64 -y [root@k8s-master ~]# vim /etc/etcd/etcd.conf ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379" ETCD_ADVERTISE_CLIENT_URLS="http://192.168.6.129:2379" #启动 [root@k8s-master ~]# systemctl start etcd.service [root@k8s-master ~]# systemctl enable etcd.service #测试 #set 设置一队键值 数据存储 [root@k8s-master ~]# etcdctl set testdir/testkey0 xujin Xujin #get获取 [root@k8s-master ~]# etcdctl get testdir/testkey0 xujin [root@k8s-master ~]# #检测集群状态 [root@k8s-master ~]# etcdctl -C http://192.168.6.129:2379 cluster-health member 8e9e05c52164694d is healthy: got healthy result from http://192.168.6.129:2379 cluster is healthy [root@k8s-master ~]#
6、master節點安裝kubernetes
[root@k8s-master ~]# yum install kubernetes-master.x86_64 -y #修改配置文件如下 [root@k8s-master ~]# vim /etc/kubernetes/apiserver # The address on the local server to listen to. KUBE_API_ADDRESS="--insecure-bind-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://192.168.6.129:2379" # default admission control policies KUBE_ADMISSION_CONTROL="--admission-control=NamespaceLifecycle,NamespaceExists,LimitRanger,Securi tyContextDeny,ResourceQuota" #修改config文件 [root@k8s-master ~]# vim /etc/kubernetes/config KUBE_MASTER="--master=http://192.168.6.129:8080"
7、啟動k8s
# 启动kube-apiserver #这个服务用来:接受并响应用户的请求 [root@k8s-master ~]# systemctl enable kube-apiserver.service [root@k8s-master ~]# systemctl start kube-apiserver.service #启动 kube-controller-manager #控制管理器的概念,保证容器存活 #每隔一段时间去扫描容器状态,看有没有死了。 #容器死了,会调度apiserver再起一个新的容器 #保证容器的个数,比如我们设定起三个nginx容器,多了就会杀掉,少了就会起 [root@k8s-master ~]# systemctl enable kube-controller-manager.service [root@k8s-master ~]# systemctl start kube-controller-manager.service #启动kube-scheduler #调度器,选择启动容器的node节点,通俗点就是容器在哪一个节点服务器上面创建 [root@k8s-master ~]# systemctl enable kube-scheduler.service [root@k8s-master ~]# systemctl start kube-scheduler.service到此主master 129 k8s安裝好了。 推薦教學:《
PHP》
#
以上是k8s 安裝部署步驟的詳細內容。更多資訊請關注PHP中文網其他相關文章!