k8s多節(jié)點master部署過程
多節(jié)點master2節(jié)點部署
從master01節(jié)點上拷貝證書文件、配置文件和服務(wù)管理文件到master02
scp -r /opt/etcd/ root@192.168.80.16:/opt/ scp -r /opt/kubernetes/ root@192.168.80.16:/opt scp /usr/lib/systemd/system/{kube-apiserver,kube-controller-manager,kube-scheduler}.service root@192.168.80.16:/usr/lib/systemd/system/
修改配置文件kube-apiserver中的IP
vim /opt/kubernetes/cfg/kube-apiserver KUBE_APISERVER_OPTS="--logtostderr=true \ --v=4 \ --etcd-servers=https://192.168.80.11:2379,https://192.168.80.12:2379,https://192.168.80.13:2379 \ --bind-address=192.168.80.16 \ #修改master02的ip --secure-port=6443 \ --advertise-address=192.168.80.16 \ #修改master02的ip
在master02節(jié)點上啟動各服務(wù)并設(shè)置開機自啟
systemctl enable --now kube-apiserver.service systemctl enable --now kube-controller-manager.service systemctl enable --now kube-scheduler.service
查看node節(jié)點狀態(tài)
ln -s /opt/kubernetes/bin/* /usr/local/bin/ kubectl get nodes kubectl get nodes -o wide #-o=wide:輸出額外信息;對于Pod,將輸出Pod所在的Node名 //此時在master02節(jié)點查到的node節(jié)點狀態(tài)僅是從etcd查詢到的信息,而此時node節(jié)點實際上并未與master02節(jié)點建立通信連接,因此需要使用一個VIP把node節(jié)點與master節(jié)點都關(guān)聯(lián)起來
負載均衡部署+keepalived高可用(192.168.80.14/15)
配置nginx的官方在線yum源,配置本地nginx的yum源
cat > /etc/yum.repos.d/nginx.repo << 'EOF' [nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/7/$basearch/ gpgcheck=0 EOF yum install nginx -y
修改nginx配置文件,配置四層反向代理負載均衡
##指定k8s群集2臺master的節(jié)點ip和6443端口 vim /etc/nginx/nginx.conf events { worker_connections 1024; } #添加 stream { log_format main '$remote_addr $upstream_addr - [$time_local] $status $upstream_bytes_sent'; access_log /var/log/nginx/k8s-access.log main; upstream k8s-apiserver { server 192.168.80.11:6443; server 192.168.80.16:6443; } server { listen 6443; proxy_pass k8s-apiserver; } } http { ......
檢查配置文件語法并啟動nginx服務(wù)
1.檢查配置文件語法 nginx -t 2.啟動nginx服務(wù),查看已監(jiān)聽6443端口 systemctl enable --now nginx netstat -natp | grep nginx
部署keepalived服務(wù)
yum install keepalived -y
修改keepalived配置文件(額外編寫健康檢查腳本)
vim /etc/keepalived/keepalived.conf ! Configuration File for keepalived global_defs { # 接收郵件地址 notification_email { acassen@firewall.loc failover@firewall.loc sysadmin@firewall.loc } # 郵件發(fā)送地址 notification_email_from Alexandre.Cassen@firewall.loc smtp_server 127.0.0.1 smtp_connect_timeout 30 router_id NGINX_MASTER #lb01節(jié)點的為NGINX_MASTER,lb02節(jié)點的為 NGINX_BACKUP } #添加一個周期性執(zhí)行的腳本 vrrp_script check_nginx { script "/etc/nginx/check_nginx.sh" #指定檢查nginx存活的腳本路徑 } vrrp_instance VI_1 { state MASTER #lb01節(jié)點的為 MASTER,lb02節(jié)點的為 BACKUP interface ens33 #指定網(wǎng)卡名稱 ens33 virtual_router_id 51 #指定vrid,兩個節(jié)點要一致 priority 100 #lb01節(jié)點的為 100,lb02節(jié)點的為 90 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.80.100 #指定 VIP } track_script { check_nginx #指定vrrp_script配置的腳本 } } ========================================================== ##創(chuàng)建nginx狀態(tài)檢查腳本 vim /etc/nginx/check_nginx.sh #!/bin/bash #egrep -cv "grep|$$" 用于過濾掉包含grep 或者 $$ 表示的當前Shell進程ID count=$(ps -ef | grep nginx | egrep -cv "grep|$$") if [ "$count" -eq 0 ];then systemctl stop keepalived fi chmod +x /etc/nginx/check_nginx.sh
啟動keepalived服務(wù)(一定要先啟動了nginx服務(wù),再啟動keepalived服務(wù))
systemctl enable --now nginx systemctl enable --now keepalived ip a #查看VIP是否生成
修改node節(jié)點上的kubeconfig配置文件
//修改bootstrap.kubeconfig,kubelet.kubeconfig配置文件為VIP cd /opt/kubernetes/cfg/ vim bootstrap.kubeconfig server: https://192.168.80.100:6443 vim kubelet.kubeconfig server: https://192.168.80.100:6443 vim kube-proxy.kubeconfig server: https://192.168.80.100:6443 //重啟kubelet和kube-proxy服務(wù) systemctl restart kubelet.service systemctl restart kube-proxy.service
在master01節(jié)點上操作
1.測試創(chuàng)建pod kubectl create deployment nginx-test --image=nginx 2.查看Pod的狀態(tài)信息 kubectl get pod kubectl get pods -o wide 3.在對應網(wǎng)段的node節(jié)點上操作,可以直接使用瀏覽器或者curl命令訪問 curl 172.17.47.2 4.這時在master01節(jié)點上查看nginx日志,發(fā)現(xiàn)沒有權(quán)限查看 kubectl logs nginx-test-7d965f56df-q8qlp Error from server (Forbidden): Forbidden (user=system:anonymous, verb=get, resource=nodes, subresource=proxy) (nginx-test-7d965f56df-q8qlp) 5.在master01節(jié)點上,將cluster-admin角色授予用戶system:anonymous 命令:kubectl create clusterrolebinding cluster-system-anonymous --clusterrole=cluster-admin --user=system:anonymous clusterrolebinding.rbac.authorization.k8s.io/cluster-system-anonymous created 6.再次查看nginx日志 kubectl logs nginx-test-7d965f56df-q8qlp 7.在master01和master02上分別創(chuàng)建pod來測試負載均衡 master01:已創(chuàng)建上面的pod master02:kubectl create deployment nginx-test2222 --image=nginx
總結(jié)
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
Rainbond上部署API?Gateway?Kong及環(huán)境配置教程
這篇文章主要為大家介紹了Rainbond上部署API?Gateway?Kong及環(huán)境配置教程,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-04-04Kubekey安裝Kubernetes-1.24.8的詳細過程
這篇文章主要介紹了Kubekey安裝Kubernetes-1.24.8的詳細過程,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2023-05-05Rainbond使用Dockerfile構(gòu)建便捷應用運行流程
這篇文章主要為大家介紹了Rainbond使用Dockerfile構(gòu)建便捷應用運行流程,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-04-04Kubernetes k8s configmap 容器技術(shù)解析
這篇文章主要為大家介紹了k8s configmap 容器技術(shù)解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-08-08k8s?Ingress實現(xiàn)流量路由規(guī)則控制的定義格式類型
這篇文章主要為大家介紹了k8s?Ingress?實現(xiàn)流量路由規(guī)則控制的定義格式及類型詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-04-04