k8s安装部署
K8s集群搭建1 centos版本信息查看
[root@localhost ~]# uname -a
Linux localhost.localdomain 3.10.0-862.el7.x86_64 #1 SMP Fri Apr 20 16:44:24 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
k8s集群机器关闭防火墙
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
2 安装必要的包
k8s集群安装以下安装包
[root@k8s-node ~]# yum -y install net-tools wget vim ntpd
[root@k8s-node ~]# systemctl enable ntpd
[root@k8s-node ~]# systemctl start ntpd
3配置hosts
[root@k8s-node ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.248.141 k8s-master
192.168.248.142 k8s-node
4 部署master节点
4.1 Master节点安装必要的安装包
[root@k8s-master ~]# yum -y install etcd
4.2更改/etc/etcd/etcd.conf配置文件
[root@k8s-master etcd]# cat /etc/etcd/etcd.conf | grep -v "^#"
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379,http://0.0.0.0:4001"
ETCD_NAME="master"
ETCD_ADVERTISE_CLIENT_URLS= http://k8s-master:2379,http://k8s-master:4001
4.3设置开机启动并验证状态
[root@k8s-master ~]#systemctl enable etcd
[root@k8s-master ~]#systemctl start etcd
etcd检查
[root@k8s_master ~]# etcdctl -C http://k8s-master:4001 cluster-health
member 8e9e05c52164694d is healthy: got healthy result from http://k8s_master:2379 cluster is healthy
[root@k8s_master ~]# etcdctl -C http://k8s-master:2379 cluster-health
member 8e9e05c52164694d is healthy: got healthy result from http://k8s_master:2379 cluster is healthy
5 安装部署docker环境(略)
6 安装kubernetes
[root@k8s_master ~]# yum install kubernetes
安装过程中报错如下
Error: docker-ce conflicts with 2:docker-1.13.1-75.git8633870.el7.centos.x86_64
可以执行如下命令解决
1、查看安装过的docker:yum list installed | grep docker
2、卸载docker:yum remove -y docker-ce.x86_64 0:18.03.0.ce-1.el7.centos
3、删除容器镜像:rm -rf /var/lib/docker
再次安装kubernetes,安装成功,而且会自动安装docker
6.1修改apiserver服务的配置文件
[root@k8s-master kubernetes]# cat /etc/kubernetes/apiserver | grep -v "^#"
KUBE_API_ADDRESS="--insecure-bind-address=0.0.0.0"
KUBE_API_PORT="--port=8080"
KUBE_ETCD_SERVERS="--etcd-servers=http://192.168.248.141: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=""
6.2修改config配置文件:
[root@k8s-master kubernetes]# cat /etc/kubernetes/config | grep -v "^#"
KUBE_LOGTOSTDERR="--logtostderr=true"
KUBE_LOG_LEVEL="--v=0"
KUBE_ALLOW_PRIV="--allow-privileged=false"
KUBE_MASTER="--master=http://192.168.248.141:8080"
设置开机启动,开启服务
[root@k8s-master ~]#systemctl enable kube-apiserver kube-controller-manager kube-scheduler docker
[root@k8s-master ~]#systemctl start kube-apiserver kube-controller-manager kube-scheduler docker
6.3查看服务端口:
[root@k8s-master ~]# netstat –tnlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1273/master
tcp 0 0 127.0.0.1:2380 0.0.0.0:* LISTEN 2126/etcd
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 571/rpcbind
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 1362/dnsmasq
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 998/sshd
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 996/cupsd
tcp6 0 0 ::1:25 :::* LISTEN 1273/master
tcp6 0 0 :::4001 :::* LISTEN 2126/etcd
tcp6 0 0 :::6443 :::* LISTEN 3216/kube-apiserver
tcp6 0 0 :::10251 :::* LISTEN 3222/kube-scheduler
tcp6 0 0 :::2379 :::* LISTEN 2126/etcd
tcp6 0 0 :::10252 :::* LISTEN 3221/kube-controlle
tcp6 0 0 :::111 :::* LISTEN 571/rpcbind
tcp6 0 0 :::8080 :::* LISTEN 3216/kube-apiserver
tcp6 0 0 :::22 :::* LISTEN 998/sshd
tcp6 0 0 ::1:631 :::* LISTEN 996/cupsd
7部署node节点
7.1安装docker(略)安装k8s(略)
7.2 Node节点主机做以下配置:
修改config配置文件
[root@k8s-node kubernetes]# cat /etc/kubernetes/config | grep -v "^#"
KUBE_LOGTOSTDERR="--logtostderr=true"
KUBE_LOG_LEVEL="--v=0"
KUBE_ALLOW_PRIV="--allow-privileged=false"
KUBE_MASTER="--master=http://192.168.248.141:8080"
修改kubelet配置文件
[root@k8s-node kubernetes]# cat /etc/kubernetes/kubelet | grep -v "^#"
KUBELET_ADDRESS="--address=0.0.0.0"
KUBELET_HOSTNAME="--hostname-override=192.168.248.142"
KUBELET_API_SERVER="--api-servers=http://192.168.248.141:8080"
KUBELET_POD_INFRA_CONTAINER="--pod-infra-container-image=registry.access.redhat.com/rhel7/pod-infrastructure:latest"
KUBELET_ARGS=""
设置开机启动、开启服务
[root@k8s_client1 ~]# systemctl enable kubelet kube-proxy
[root@k8s_client1 ~]# systemctl start kubelet kube-proxy
查看端口:
[root@k8s_client1 ~]# netstat –ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1277/master
tcp 0 0 127.0.0.1:10248 0.0.0.0:* LISTEN 3246/kubelet
tcp 0 0 127.0.0.1:10249 0.0.0.0:* LISTEN 3133/kube-proxy
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 575/rpcbind
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 1332/dnsmasq
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1000/sshd
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 998/cupsd
tcp6 0 0 ::1:25 :::* LISTEN 1277/master
tcp6 0 0 :::4194 :::* LISTEN 3246/kubelet
tcp6 0 0 :::10250 :::* LISTEN 3246/kubelet
tcp6 0 0 :::10255 :::* LISTEN 3246/kubelet
tcp6 0 0 :::111 :::* LISTEN 575/rpcbind
tcp6 0 0 :::22 :::* LISTEN 1000/sshd
tcp6 0 0 ::1:631 :::* LISTEN 998/cupsd
Master上查看集群中的节点及节点状态
[root@k8s-master kubernetes]# kubectl get node
NAME STATUS AGE
192.168.248.142 Ready 2m
[root@k8s-master kubernetes]# kubectl -s http://k8s-master:8080 get node
NAME STATUS AGE
192.168.248.142 Ready 2m
kubernetes集群搭建完成。
在k8s集群中创建pod,如果出现如下错误
其中最主要的问题是:details: (open /etc/docker/certs.d/registry.access.redhat.com/redhat-ca.crt: no such file or directory)
解决方案:
查看/etc/docker/certs.d/registry.access.redhat.com/redhat-ca.crt (该链接就是上图中的说明) 是一个软链接,但是链接过去后并没有真实的/etc/rhsm,所以需要使用yum安装:
yum install *rhsm*
安装完成后,执行一下docker pull registry.access.redhat.com/rhel7/pod-infrastructure:latest
如果依然报错,可参考下面的方案:
wget http://mirror.centos.org/centos/7/os/x86_64/Packages/python-rhsm-certificates-1.19.10-1.el7_4.x86_64.rpm
rpm2cpio python-rhsm-certificates-1.19.10-1.el7_4.x86_64.rpm | cpio -iv --to-stdout ./etc/rhsm/ca/redhat-uep.pem | tee /etc/rhsm/ca/redhat-uep.pem
注释:rpm2cpio命令用于将rpm软件包转换为cpio格式的文件
cpio命令主要是用来建立或者还原备份档的工具程序,cpio命令可以复制文件到归档包中,或者从归档包中复文件。
-i 还原备份档
-v 详细显示指令的执行过程
这两个命令会生成/etc/rhsm/ca/redhat-uep.pem文件.
[root@k8s-node ~]# docker pull registry.access.redhat.com/rhel7/pod-infrastructure:latest
在master节点新建pod并查看起状态为正常
flannel是CoreOS提供用于解决Dokcer集群跨主机通讯的覆盖网络工具。它的主要思路是:预先留出一个网段,每个主机使用其中一部分,然后每个容器被分配不同的ip;让所有的容器认为大家在同一个直连的网络,底层通过UDP/VxLAN等进行报文的封装和转发。
绛旓細4. 楂樼骇鍔熻兘鎵╁睍 Dashboard涓庤闂帶鍒讹細瀹夎骞堕厤缃甂ubernetes Dashboard锛岃缃甆odePort鏈嶅姟浠ヤ緵澶栭儴璁块棶銆 鐩戞帶涓庤礋杞藉潎琛★細閮ㄧ讲Nginx+Keepalived锛屽疄鐜k8s-api-server鐨勯珮鍙敤鎬с 閮ㄧ讲宸ュ叿涓庣鐞嗭細浣跨敤Helm瀹夎鍜岀鐞咾ubernetes搴旂敤锛屽dashboard鍜宨ngress銆 璇︾粏姝ラ鍜岄摼鎺ュ凡鍒犻櫎锛屼絾浠ヤ笂姒傝堪浜嗗叧閿...
绛旓細1.1 瀹夎瑕佹眰 - 鎿嶄綔绯荤粺锛欳entOS 7.6锛屽缓璁嚦灏2GB RAM銆2涓狢PU鍜30GB纭洏銆- 缃戠粶鐜锛氱‘淇濇湇鍔″櫒闂寸殑缃戠粶浜掗氾紝鑳借闂缃戙- 绯荤粺璋冩暣锛氱鐢╯wap鍒嗗尯锛屼紭鍖栫郴缁熸ц兘銆1.2 鐜閰嶇疆 - 蹇呭杞欢锛氬畨瑁卍ocker 19.03.15-3.el7锛屼互鍙奒ubernetes 1.19.15銆- 鏈嶅姟鍣ㄨ鍒掞細鑷冲皯闇瑕佷竴涓猚ontrolplane...
绛旓細Kubernetes锛坘8s锛夊畼鏂规帹鑽愮殑閮ㄧ讲宸ュ叿鏄痥ubectl銆侹ubernetes锛岀畝绉癒8s锛屾槸涓涓紑婧愮殑锛岀敤浜庣鐞嗕簯骞冲彴涓涓富鏈轰笂鐨勫鍣ㄥ寲鐨勫簲鐢ㄣ傚湪Kubernetes鐢熸佺郴缁熶腑锛宬ubectl鏄竴涓潪甯搁噸瑕佺殑鍛戒护琛屽伐鍏凤紝瀹冨厑璁哥敤鎴烽氳繃鍛戒护琛屼笌Kubernetes闆嗙兢杩涜浜や簰銆俴ubectl鐨勫姛鑳介潪甯稿己澶э紝鍑犱箮娑电洊浜咾ubernetes绠$悊鐨勫悇涓柟闈備緥濡傦紝鐢...
绛旓細member 8e9e05c52164694d is healthy: got healthy result from http://k8s_master:2379 cluster is healthy [root@k8s_master ~]# etcdctl -C http://k8s-master:2379 cluster-health member 8e9e05c52164694d is healthy: got healthy result from http://k8s_master:2379 cluster is healthy 5 瀹夎閮ㄧ讲d...
绛旓細楂樻晥闆嗘垚锛氭爣鍑嗗寲鐨閮ㄧ讲鍜岄厤缃紝澶уぇ缂╃煭椤圭洰寮鍙戝懆鏈燂紱楂樻晥杩愮淮锛K8s涓婄殑澶ф暟鎹粍浠剁鐞嗘娊璞″眰锛屾彁鍗囬儴缃插拰鍗囩骇鎿嶄綔鏁堢巼锛涜祫婧愪紭鍖栵細绮剧粏鍖栬祫婧愮鐞嗭紝KDP鍙皢璧勬簮鍒╃敤鐜囨彁鍗囪嚦60%浠ヤ笂銆傛垜浠杩庣ぞ鍖烘垚鍛樼殑鍙備笌鍜屽缓璁紝鏃犺鏄氳繃Github璁杩樻槸鐩存帴鑱旂郴鎴戜滑锛屾櫤棰嗕簯閮芥効鎰忎笌鎮ㄥ叡鍚屾帹鍔↘ubernetes澶ф暟鎹钩鍙扮殑鍙戝睍...
绛旓細鏈杩戜緷鐓х綉涓婁笉灏戞枃绔閮ㄧ讲K8s楂樺彲鐢ㄩ泦缇わ紝閬囧埌浜嗕竴浜涢夯鐑︼紝鍦ㄨ繖閲岃褰曚笅鏉ャ傛牴鎹甂8s瀹樻柟鏂囨。灏咹A鎷撴墤鍒嗕负涓ょ锛孲tacked etcd topology锛堝爢鍙燛TCD锛夊拰External etcd topology锛堝閮‥TCD锛夈 https://kubernetes.cn/docs/setup/production-environment/tools/kubeadm/ha-topology/#external-etcd-topology 鍫嗗彔ETCD ...
绛旓細鏌ョ湅 瀹夎 kubeadm-鍑嗗宸ヤ綔 瀵 k8s 瀹夎鐨勫熀鏈姹傦細锛 鏁翠釜閮ㄧ讲鐜鍏ㄥ湪virtualbox涓疄鐜 锛 閮ㄧ讲鏈灏忓寲 K8S 闆嗙兢锛歮aster + node1 + node2 3鍙颁富鏈篒P鍒嗗埆涓 192.168.36.213 銆 192.168.36.141 銆 192.168.36.188 銆侊紝灏嗚捣閰嶇疆鍒 鏂囦欢涓紝淇濊瘉浜掔浉鍚堜竴閫氾細纭繚 br_netfilter ...
绛旓細Kubernetes榛樿CRI锛堝鍣ㄨ繍琛屾椂锛変负Docker锛屽洜姝ゅ厛瀹夎Docker銆5.1 瀹夎Docker 5.2 娣诲姞闃块噷浜慪UM杞欢婧 5.3 瀹夎kubeadm锛宬ubelet鍜宬ubectl 鐢变簬鐗堟湰鏇存柊棰戠箒锛岃繖閲屾寚瀹氱増鏈彿閮ㄧ讲锛6.1 鍒涘缓kubeadm閰嶇疆鏂囦欢 鍦ㄥ叿鏈塿ip鐨刴aster涓婃搷浣滐紝杩欓噷涓簃aster1 6.2 鍦╩aster1鑺傜偣鎵ц 鎸夌収鎻愮ず淇濆瓨浠ヤ笅鍐呭锛屼竴浼氳...
绛旓細step1锛氬湪master涓瀹夎 yum install kubernetes-master etcd flannel -y step2锛氬湪node涓婂畨瑁 yum install kubernetes-node etcd flannel -y step3锛歟tcd闆嗙兢閰嶇疆 鍦╩aster鑺傜偣涓婄紪杈慹tcd閰嶇疆鏂囦欢 鍦╪ode1鑺傜偣涓婄紪杈慹tcd閰嶇疆鏂囦欢 鍦╪ode2鑺傜偣涓婄紪杈慹tcd閰嶇疆鏂囦欢 鍒版etcd闆嗙兢灏閮ㄧ讲瀹屼簡锛岀劧鍚庢瘡涓妭...
绛旓細CentOS7鐨瀹夎姣旇緝绠鍗曪紝鎴戜滑鐩存帴浣跨敤瀹樻柟鎻愪緵鐨 yum 婧愬嵆鍙傞渶瑕佹敞鎰忕殑鏄繖閲岄渶瑕佽缃 selinux 鐨勭姸鎬侊紝浣嗘槸鍓嶉潰鎴戜滑宸茬粡鍏抽棴浜唖elinux锛屽洜姝よ繖閲岀暐杩囪繖姝ャ傚湪闆嗙兢涓墍鏈夎妭鐐归兘鎵ц瀹屼笂闈㈢殑涓夌偣鎿嶄綔涔嬪悗锛屾垜浠氨鍙互寮濮嬪垱寤k8s闆嗙兢浜嗐傚洜涓烘垜浠繖娆′笉娑夊強楂樺彲鐢閮ㄧ讲锛屽洜姝ゅ垵濮嬪寲鐨勬椂鍊欑洿鎺ュ湪鎴戜滑鐨勭洰鏍噈aster...