<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>k8s &#8211; 菜鸟小站-钱锅锅【BD4RPX】</title>
	<atom:link href="https://www.cnzid.com/tag/k8s/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.cnzid.com</link>
	<description>我是钱锅锅，我无所畏惧，我一生渴望被收藏好，妥善安放，细心保存。免我惊，免我苦，免我四下流离，免我无枝可依。</description>
	<lastBuildDate>Fri, 26 Jul 2024 07:33:10 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://www.cnzid.com/wp-content/uploads/2026/01/微信图片_20260113222921_117_461-150x150.jpg</url>
	<title>k8s &#8211; 菜鸟小站-钱锅锅【BD4RPX】</title>
	<link>https://www.cnzid.com</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">249684443</site>	<item>
		<title>再也不踩坑的Kubernetes实战指南</title>
		<link>https://www.cnzid.com/2024/07/26/%e5%86%8d%e4%b9%9f%e4%b8%8d%e8%b8%a9%e5%9d%91%e7%9a%84kubernetes%e5%ae%9e%e6%88%98%e6%8c%87%e5%8d%97/</link>
		
		<dc:creator><![CDATA[]]></dc:creator>
		<pubDate>Fri, 26 Jul 2024 07:33:10 +0000</pubDate>
				<category><![CDATA[云计算]]></category>
		<category><![CDATA[docker]]></category>
		<category><![CDATA[k8s]]></category>
		<guid isPermaLink="false">https://www.cnzid.com/?p=1846</guid>

					<description><![CDATA[一、安装前必读 1、请不要使用带中文的操作系统服务器和虚拟机。 2、生产环境建议使用二进制安装方式。 3、文档 &#8230; <a href="https://www.cnzid.com/2024/07/26/%e5%86%8d%e4%b9%9f%e4%b8%8d%e8%b8%a9%e5%9d%91%e7%9a%84kubernetes%e5%ae%9e%e6%88%98%e6%8c%87%e5%8d%97/" class="more-link">继续阅读<span class="screen-reader-text">“再也不踩坑的Kubernetes实战指南”</span></a>]]></description>
										<content:encoded><![CDATA[
<p class="has-large-font-size">一、安装前必读</p>



<p class="has-bright-red-color has-text-color has-link-color has-medium-font-size wp-elements-b4dbcc0b84351886ccf7cd8c3388fbab">1、请不要使用带中文的操作系统服务器和虚拟机。</p>



<p class="has-bright-red-color has-text-color has-link-color has-medium-font-size wp-elements-08c0d22288b1fff87e9545868f3563c0">2、生产环境建议使用二进制安装方式。</p>



<p class="has-bright-red-color has-text-color has-link-color has-medium-font-size wp-elements-03df5ab65f11a7df700b5487d5c950ae">3、文档中的IP地址请统一替换，不要一个一个替换！！！</p>



<p class="has-bright-red-color has-text-color has-link-color has-medium-font-size wp-elements-0fa665e2c84aea3d9295ceb2ef904e50">4、如果是一个一个替换的，请不要找我排查故障！！！！！！！</p>



<p class="has-large-font-size">二、kubeadm高可用安装k8s集群</p>



<p>1、基本环境安装</p>



<p>Kubeadm安装方式自1.14版本以后，安装方法几乎没有任何变化，此文档可以尝试安装最新的k8s集群，centos采用的是7.x版本。</p>



<p>PS:</p>



<p>K8S官网：<a href="https://kubernetes.io/docs/setup/"><u>https://kubernetes.io/docs/setup/</u></a></p>



<p>最新版高可用安装：<a href="https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/high-availability/"><u>https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/high-availability/</u></a></p>



<figure class="wp-block-table"><table class="has-fixed-layout"><tbody><tr><td>主机名<strong></strong></td><td>IP地址<strong></strong></td><td>说明<strong></strong></td></tr><tr><td>k8s-master01 ~ 03<strong></strong></td><td>192.168.0.107 ~ 203<strong></strong></td><td>master节点&nbsp;* 3<strong></strong></td></tr><tr><td>k8s-master-lb<strong></strong></td><td>192.168.0.236<strong></strong></td><td>keepalived虚拟IP<strong></strong></td></tr><tr><td>k8s-node01 ~ 02<strong></strong></td><td>192.168.0.110 ~ 205<strong></strong></td><td>worker节点&nbsp;* 2<strong></strong></td></tr></tbody></table><figcaption class="wp-element-caption">表1-1  高可用Kubernetes集群规划</figcaption></figure>



<figure class="wp-block-table"><table class="has-fixed-layout"><tbody><tr><td><strong>配置信息</strong><strong></strong></td><td>备注<strong></strong></td></tr><tr><td>系统版本<strong></strong></td><td>CentOS&nbsp;7.9<strong></strong></td></tr><tr><td>Docker版本 <strong></strong></td><td>19.03.x<strong></strong></td></tr><tr><td>Pod网段 <strong></strong></td><td>172.168.0.0/12<strong></strong></td></tr><tr><td>Service网段</td><td>10.96.0.0/12</td></tr></tbody></table><figcaption class="wp-element-caption">表1-2安装环境信息</figcaption></figure>



<p class="has-bright-red-color has-text-color has-link-color wp-elements-97d7026d72ada5ebc288a6a3430c89c8">注意：VIP（虚拟IP）不要和内网IP重复，首先去ping一下，不通才可用。VIP需要和主机在同一个局域网内！公有云上搭建VIP是公有云的负载均衡的IP，比如阿里云的内网SLB的地址，腾讯云内网ELB的地址。</p>



<p>2、修改hosts</p>



<p>所有节点配置hosts，修改/etc/hosts如下：</p>



<pre class="wp-block-code"><code>&#91;root@k8s-master01 ~]# cat /etc/hosts
192.168.0.107 k8s-master01
192.168.0.108 k8s-master02
192.168.0.109 k8s-master03
192.168.0.236 k8s-master-lb # 如果不是高可用集群，该IP为Master01的IP
192.168.0.110 k8s-node01
192.168.0.111 k8s-node02</code></pre>



<p>3、CentOS7安装yum源如下：</p>



<pre class="wp-block-code"><code>curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

yum install -y yum-utils device-mapper-persistent-data lvm2

yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

cat &lt;&lt;EOF > /etc/yum.repos.d/kubernetes.repo
&#91;kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo</code></pre>



<p>4、必备工具安装</p>



<pre class="wp-block-code"><code>yum install wget jq psmisc vim net-tools telnet yum-utils device-mapper-persistent-data lvm2 git -y</code></pre>



<p>5、所有节点关闭防火墙、selinux、dnsmasq、swap。服务器配置如下：</p>



<pre class="wp-block-code"><code>systemctl disable --now firewalld 
systemctl disable --now dnsmasq
systemctl disable --now NetworkManager

setenforce 0
sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/sysconfig/selinux
sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config</code></pre>



<p>6、关闭SWAP分区</p>



<pre class="wp-block-code"><code>swapoff -a &amp;&amp; sysctl -w vm.swappiness=0
sed -ri '/^&#91;^#]*swap/s@^@#@' /etc/fstab</code></pre>



<p>7、安装ntpdate</p>



<pre class="wp-block-code"><code>rpm -ivh http://mirrors.wlnmp.com/centos/wlnmp-release-centos.noarch.rpm
yum install ntpdate -y</code></pre>



<p>8、所有节点同步时间。时间同步配置如下：</p>



<pre class="wp-block-code"><code>ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
echo 'Asia/Shanghai' >/etc/timezone
ntpdate time2.aliyun.com
# 加入到crontab
*/5 * * * * /usr/sbin/ntpdate time2.aliyun.com</code></pre>



<p>9、所有节点配置limit</p>



<pre class="wp-block-code"><code>ulimit -SHn 65535

vim /etc/security/limits.conf
# 末尾添加如下内容
* soft nofile 655360
* hard nofile 131072
* soft nproc 655350
* hard nproc 655350
* soft memlock unlimited
* hard memlock unlimited</code></pre>



<p>10、Master01节点免密钥登录其他节点，安装过程中生成配置文件和证书均在Master01上操作，集群管理也在Master01上操作，阿里云或者AWS上需要单独一台kubectl服务器。密钥配置如下：</p>



<pre class="wp-block-code"><code>ssh-keygen -t rsa
for i in k8s-master01 k8s-master02 k8s-master03 k8s-node01 k8s-node02;do ssh-copy-id -i .ssh/id_rsa.pub $i;done</code></pre>



<p>11、下载安装所有的源码文件：</p>



<pre class="wp-block-code"><code>cd /root/ ; git clone https://github.com/dotbalo/k8s-ha-install.git</code></pre>



<p>12、所有节点升级系统并重启，此处升级没有升级内核，下节会单独升级内核：</p>



<pre class="wp-block-code has-dark-gray-color has-text-color has-link-color wp-elements-cb7cf1ab9f153ed12d1cf9fdfb08df20"><code>yum update -y --exclude=kernel* &amp;&amp; reboot #CentOS7需要升级，CentOS8可以按需升级系统</code></pre>



<p>13、内核配置</p>



<p>CentOS7 需要升级内核至4.18+，本地升级的版本为4.19</p>



<p>13.1、在master01节点下载内核：</p>



<pre class="wp-block-code"><code>cd /root
wget http://193.49.22.109/elrepo/kernel/el7/x86_64/RPMS/kernel-ml-devel-4.19.12-1.el7.elrepo.x86_64.rpm
wget http://193.49.22.109/elrepo/kernel/el7/x86_64/RPMS/kernel-ml-4.19.12-1.el7.elrepo.x86_64.rpm</code></pre>



<p>13.2、从master01节点传到其他节点：</p>



<pre class="wp-block-code"><code>for i in k8s-master02 k8s-master03 k8s-node01 k8s-node02;do scp kernel-ml-4.19.12-1.el7.elrepo.x86_64.rpm kernel-ml-devel-4.19.12-1.el7.elrepo.x86_64.rpm $i:/root/ ; done</code></pre>



<p>13.3、所有节点安装内核：</p>



<pre class="wp-block-code"><code>cd /root &amp;&amp; yum localinstall -y kernel-ml*</code></pre>



<p>13.4、所有节点更改内核启动顺序：</p>



<pre class="wp-block-code"><code>grub2-set-default  0 &amp;&amp; grub2-mkconfig -o /etc/grub2.cfg

grubby --args="user_namespace.enable=1" --update-kernel="$(grubby --default-kernel)"</code></pre>



<p>13.5、检查默认内核是不是4.19</p>



<pre class="wp-block-code"><code>&#91;root@k8s-master02 ~]# grubby --default-kernel
/boot/vmlinuz-4.19.12-1.el7.elrepo.x86_64</code></pre>



<p>13.6、所有节点重启，然后检查内核是不是4.19</p>



<pre class="wp-block-code"><code>&#91;root@k8s-master02 ~]# uname -a
Linux k8s-master02 4.19.12-1.el7.elrepo.x86_64 #1 SMP Fri Dec 21 11:06:36 EST 2018 x86_64 x86_64 x86_64 GNU/Linux</code></pre>



<p>13.7、所有节点安装ipvsadm</p>



<pre class="wp-block-code"><code>yum install ipvsadm ipset sysstat conntrack libseccomp -y</code></pre>



<p>13.8、所有节点配置ipvs模块，在内核4.19+版本nf_conntrack_ipv4已经改为nf_conntrack， 4.18以下使用nf_conntrack_ipv4即可：</p>



<pre class="wp-block-code"><code>modprobe -- ip_vs
modprobe -- ip_vs_rr
modprobe -- ip_vs_wrr
modprobe -- ip_vs_sh
modprobe -- nf_conntrack
vim /etc/modules-load.d/ipvs.conf 
	# 加入以下内容
ip_vs
ip_vs_lc
ip_vs_wlc
ip_vs_rr
ip_vs_wrr
ip_vs_lblc
ip_vs_lblcr
ip_vs_dh
ip_vs_sh
ip_vs_fo
ip_vs_nq
ip_vs_sed
ip_vs_ftp
ip_vs_sh
nf_conntrack
ip_tables
ip_set
xt_set
ipt_set
ipt_rpfilter
ipt_REJECT
ipip</code></pre>



<p>13.9、然后执行即可：</p>



<pre class="wp-block-code"><code>systemctl enable --now systemd-modules-load.service</code></pre>



<p>14、开启一些k8s集群中必须的内核参数，所有节点配置k8s内核：</p>



<pre class="wp-block-code"><code>cat &lt;&lt;EOF > /etc/sysctl.d/k8s.conf
net.ipv4.ip_forward = 1
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
fs.may_detach_mounts = 1
vm.overcommit_memory=1
vm.panic_on_oom=0
fs.inotify.max_user_watches=89100
fs.file-max=52706963
fs.nr_open=52706963
net.netfilter.nf_conntrack_max=2310720

net.ipv4.tcp_keepalive_time = 600
net.ipv4.tcp_keepalive_probes = 3
net.ipv4.tcp_keepalive_intvl =15
net.ipv4.tcp_max_tw_buckets = 36000
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_max_orphans = 327680
net.ipv4.tcp_orphan_retries = 3
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_max_syn_backlog = 16384
net.ipv4.ip_conntrack_max = 65536
net.ipv4.tcp_max_syn_backlog = 16384
net.ipv4.tcp_timestamps = 0
net.core.somaxconn = 16384
EOF
sysctl --system</code></pre>



<p>15、所有节点配置完内核后，重启服务器，保证重启后内核依旧加载</p>



<pre class="wp-block-code"><code>reboot
lsmod | grep --color=auto -e ip_vs -e nf_conntrack</code></pre>



<p>16、基本组件安装</p>



<p>本节主要安装的是集群中用到的各种组件，比如Docker-ce、Kubernetes各组件等。</p>



<p>16.1、所有节点安装Docker-ce 19.03</p>



<pre class="wp-block-code"><code>yum install docker-ce-19.03.* docker-cli-19.03.* -y</code></pre>



<p>16.2、由于新版kubelet建议使用systemd，所以可以把docker的CgroupDriver改成systemd</p>



<pre class="wp-block-code"><code>mkdir /etc/docker
cat > /etc/docker/daemon.json &lt;&lt;EOF
{
  "exec-opts": &#91;"native.cgroupdriver=systemd"]
}
EOF</code></pre>



<p>16.3、所有节点设置开机自启动Docker：</p>



<pre class="wp-block-code"><code>systemctl daemon-reload &amp;&amp; systemctl enable --now docker</code></pre>



<p>16.4、安装k8s组件：</p>



<pre class="wp-block-code"><code>yum list kubeadm.x86_64 --showduplicates | sort -r</code></pre>



<p>16.5、所有节点安装最新版本kubeadm：</p>



<pre class="wp-block-code"><code>yum install kubeadm-1.20* kubelet-1.20* kubectl-1.20* -y</code></pre>



<p>16.6、默认配置的pause镜像使用gcr.io仓库，国内可能无法访问，所以这里配置<br>Kubelet使用阿里云的pause镜像：</p>



<pre class="wp-block-code"><code>cat >/etc/sysconfig/kubelet&lt;&lt;EOF
KUBELET_EXTRA_ARGS="--cgroup-driver=systemd --pod-infra-container-image=registry.cn-hangzhou.aliyuncs.com/google_containers/pause-amd64:3.2"
EOF</code></pre>



<p>16.7、设置Kubelet开机自启动：</p>



<pre class="wp-block-code"><code>systemctl daemon-reload
systemctl enable --now kubelet</code></pre>



<p>17、高可用组件安装</p>



<p>公有云要用公有云自带的负载均衡，比如阿里云的SLB，腾讯云的ELB，用来替代haproxy<br>和keepalived，因为公有云大部分都是不支持keepalived的，另外如果用阿里云的话，kubectl控制端不能放在master节点，推荐使用腾讯云，因为阿里云的slb有回环的问题，也就是slb代理的服务器不能反向访问SLB，但是腾讯云修复了这个问题。</p>



<p>注意：如果不是高可用集群，haproxy和keepalived无需安装。</p>



<p>17.1、所有Master节点通过yum安装HAProxy和KeepAlived：</p>



<pre class="wp-block-code"><code>yum install keepalived haproxy -y</code></pre>



<p>17.2、所有Master节点配置HAProxy（详细配置参考HAProxy文档，所有Master节点的HAProxy配置相同）：</p>



<pre class="wp-block-code"><code>&#91;root@k8s-master01 etc]# mkdir /etc/haproxy
&#91;root@k8s-master01 etc]# vim /etc/haproxy/haproxy.cfg 
global
  maxconn  2000
  ulimit-n  16384
  log  127.0.0.1 local0 err
  stats timeout 30s

defaults
  log global
  mode  http
  option  httplog
  timeout connect 5000
  timeout client  50000
  timeout server  50000
  timeout http-request 15s
  timeout http-keep-alive 15s

frontend monitor-in
  bind *:33305
  mode http
  option httplog
  monitor-uri /monitor

frontend k8s-master
  bind 0.0.0.0:16443
  bind 127.0.0.1:16443
  mode tcp
  option tcplog
  tcp-request inspect-delay 5s
  default_backend k8s-master

backend k8s-master
  mode tcp
  option tcplog
  option tcp-check
  balance roundrobin
  default-server inter 10s downinter 5s rise 2 fall 2 slowstart 60s maxconn 250 maxqueue 256 weight 100
  server k8s-master01	192.168.0.107:6443  check
  server k8s-master02	192.168.0.108:6443  check
  server k8s-master03	192.168.0.109:6443  check</code></pre>



<p>17.3、所有Master节点配置KeepAlived，配置不一样，注意区分&nbsp;[root@k8s-master01 pki]# vim /etc/keepalived/keepalived.conf ，注意每个节点的IP和网卡（interface参数）</p>



<p>Master01节点的配置：</p>



<pre class="wp-block-code"><code>&#91;root@k8s-master01 etc]# mkdir /etc/keepalived

&#91;root@k8s-master01 ~]# vim /etc/keepalived/keepalived.conf 
! Configuration File for keepalived
global_defs {
    router_id LVS_DEVEL
script_user root
    enable_script_security
}
vrrp_script chk_apiserver {
    script "/etc/keepalived/check_apiserver.sh"
    interval 5
    weight -5
    fall 2  
rise 1
}
vrrp_instance VI_1 {
    state MASTER
    interface ens33
    mcast_src_ip 192.168.0.107
    virtual_router_id 51
    priority 101
    advert_int 2
    authentication {
        auth_type PASS
        auth_pass K8SHA_KA_AUTH
    }
    virtual_ipaddress {
        192.168.0.236
    }
    track_script {
       chk_apiserver
    }
}</code></pre>



<p>Master02节点的配置：</p>



<pre class="wp-block-code"><code>! Configuration File for keepalived
global_defs {
    router_id LVS_DEVEL
script_user root
    enable_script_security
}
vrrp_script chk_apiserver {
    script "/etc/keepalived/check_apiserver.sh"
   interval 5
    weight -5
    fall 2  
rise 1
}
vrrp_instance VI_1 {
    state BACKUP
    interface ens33
    mcast_src_ip 192.168.0.108
    virtual_router_id 51
    priority 100
    advert_int 2
    authentication {
        auth_type PASS
        auth_pass K8SHA_KA_AUTH
    }
    virtual_ipaddress {
        192.168.0.236
    }
    track_script {
       chk_apiserver
    }
}</code></pre>



<p>Master03节点的配置：</p>



<pre class="wp-block-code"><code>! Configuration File for keepalived
global_defs {
    router_id LVS_DEVEL
script_user root
    enable_script_security
}
vrrp_script chk_apiserver {
    script "/etc/keepalived/check_apiserver.sh"
 interval 5
    weight -5
    fall 2  
rise 1
}
vrrp_instance VI_1 {
    state BACKUP
    interface ens33
    mcast_src_ip 192.168.0.109
    virtual_router_id 51
    priority 100
    advert_int 2
    authentication {
        auth_type PASS
        auth_pass K8SHA_KA_AUTH
    }
    virtual_ipaddress {
        192.168.0.236
    }
    track_script {
       chk_apiserver
    }
}</code></pre>



<p>所有master节点配置KeepAlived健康检查文件：</p>



<pre class="wp-block-code"><code>&#91;root@k8s-master01 keepalived]# cat /etc/keepalived/check_apiserver.sh 
#!/bin/bash

err=0
for k in $(seq 1 3)
do
    check_code=$(pgrep haproxy)
    if &#91;&#91; $check_code == "" ]]; then
        err=$(expr $err + 1)
        sleep 1
        continue
    else
        err=0
        break
    fi
done

if &#91;&#91; $err != "0" ]]; then
    echo "systemctl stop keepalived"
    /usr/bin/systemctl stop keepalived
    exit 1
else
    exit 0
fi</code></pre>



<pre class="wp-block-code"><code>chmod +x /etc/keepalived/check_apiserver.sh</code></pre>



<p>启动haproxy和keepalived</p>



<pre class="wp-block-code"><code>&#91;root@k8s-master01 keepalived]# systemctl daemon-reload
&#91;root@k8s-master01 keepalived]# systemctl enable --now haproxy
&#91;root@k8s-master01 keepalived]# systemctl enable --now keepalived</code></pre>



<p class="has-bright-red-color has-text-color has-link-color wp-elements-b45cc8e63472fa90983ac728cfa8bb18">重要：如果安装了keepalived和haproxy，需要测试keepalived是否是正常的</p>



<pre class="wp-block-code"><code>测试VIP
&#91;root@k8s-master01 ~]# ping 192.168.0.236 -c 4
PING 192.168.0.236 (192.168.0.236) 56(84) bytes of data.
64 bytes from 192.168.0.236: icmp_seq=1 ttl=64 time=0.464 ms
64 bytes from 192.168.0.236: icmp_seq=2 ttl=64 time=0.063 ms
64 bytes from 192.168.0.236: icmp_seq=3 ttl=64 time=0.062 ms
64 bytes from 192.168.0.236: icmp_seq=4 ttl=64 time=0.063 ms

--- 192.168.0.236 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3106ms
rtt min/avg/max/mdev = 0.062/0.163/0.464/0.173 ms
&#91;root@k8s-master01 ~]# telnet 192.168.0.236 16443
Trying 192.168.0.236...
Connected to 192.168.0.236.
Escape character is '^]'.
Connection closed by foreign host.</code></pre>



<p>如果ping不通且telnet没有出现 ] ，则认为VIP不可以，不可在继续往下执行，需要排查keepalived的问题，比如防火墙和selinux，haproxy和keepalived的状态，监听端口等</p>



<p>所有节点查看防火墙状态必须为disable和inactive：systemctl status firewalld</p>



<p>所有节点查看selinux状态，必须为disable：getenforce </p>



<p>master节点查看haproxy和keepalived状态：systemctl status keepalived haproxy</p>



<p>master节点查看监听端口：netstat&nbsp;-lntp</p>



<p>18、集群初始化</p>



<p>官方初始化文档：<a href="https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/high-availability">https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/high-availability</a></p>



<p>Master01节点创建kubeadm-config.yaml配置文件如下：</p>



<p>Master01：（# 注意，如果不是高可用集群，192.168.0.236:16443改为master01的地址，16443改为apiserver的端口，默认是6443，注意更改v1.18.5自己服务器kubeadm的版本：kubeadm version）</p>



<p class="has-bright-red-color has-text-color has-link-color wp-elements-46844dcb5ce1ecec142a76cacd826734">注意：以下文件内容，宿主机网段、podSubnet网段、serviceSubnet网段不能重复，具体安装前需要对集群安装网段划分。</p>



<pre class="wp-block-code"><code>apiVersion: kubeadm.k8s.io/v1beta2
bootstrapTokens:
- groups:
  - system:bootstrappers:kubeadm:default-node-token
  token: 7t2weq.bjbawausm0jaxury
  ttl: 24h0m0s
  usages:
  - signing
  - authentication
kind: InitConfiguration
localAPIEndpoint:
  advertiseAddress: 192.168.0.107
  bindPort: 6443
nodeRegistration:
  criSocket: /var/run/dockershim.sock
  name: k8s-master01
  taints:
  - effect: NoSchedule
    key: node-role.kubernetes.io/master
---
apiServer:
  certSANs:
  - 192.168.0.236
  timeoutForControlPlane: 4m0s
apiVersion: kubeadm.k8s.io/v1beta2
certificatesDir: /etc/kubernetes/pki
clusterName: kubernetes
controlPlaneEndpoint: 192.168.0.236:16443
controllerManager: {}
dns:
  type: CoreDNS
etcd:
  local:
    dataDir: /var/lib/etcd
imageRepository: registry.cn-hangzhou.aliyuncs.com/google_containers
kind: ClusterConfiguration
kubernetesVersion: v1.20.0
networking:
  dnsDomain: cluster.local
  podSubnet: 172.168.0.0/12
  serviceSubnet: 10.96.0.0/12
scheduler: {}</code></pre>



<p>更新kubeadm文件</p>



<pre class="wp-block-code"><code>kubeadm config migrate --old-config kubeadm-config.yaml --new-config new.yaml</code></pre>



<p>将new.yaml文件复制到其他master节点，之后所有Master节点提前下载镜像，可以节省初始化时间：</p>



<pre class="wp-block-code"><code>kubeadm config images pull --config /root/new.yaml</code></pre>



<p>所有节点设置开机自启动kubelet</p>



<pre class="wp-block-code"><code>systemctl enable --now kubelet  #（如果启动失败无需管理，初始化成功以后即可启动）</code></pre>



<p>Master01节点初始化，初始化以后会在/etc/kubernetes目录下生成对应的证书和配置文件，之后其他Master节点加入Master01即可：</p>



<pre class="wp-block-code"><code>kubeadm init --config /root/new.yaml  --upload-certs</code></pre>



<p>如果初始化失败，重置后再次初始化，命令如下：</p>



<pre class="wp-block-code"><code>kubeadm reset -f ; ipvsadm --clear  ; rm -rf ~/.kube</code></pre>



<p>初始化成功以后，会产生Token值，用于其他节点加入时使用，因此要记录下初始化成功生成的token值（令牌值）：</p>



<pre class="wp-block-code"><code>Your Kubernetes control-plane has initialized successfully!

To start using your cluster, you need to run the following as a regular user:

  mkdir -p $HOME/.kube
  sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
  sudo chown $(id -u):$(id -g) $HOME/.kube/config

Alternatively, if you are the root user, you can run:

  export KUBECONFIG=/etc/kubernetes/admin.conf

You should now deploy a pod network to the cluster.
Run "kubectl apply -f &#91;podnetwork].yaml" with one of the options listed at:
  https:&#47;&#47;kubernetes.io/docs/concepts/cluster-administration/addons/

You can now join any number of the control-plane node running the following command on each as root:

  kubeadm join 192.168.0.236:16443 --token 7t2weq.bjbawausm0jaxury \
    --discovery-token-ca-cert-hash sha256:8c92ecb336be2b9372851a9af2c7ca1f7f60c12c68f6ffe1eb513791a1b8a908 \
    --control-plane --certificate-key ac2854de93aaabdf6dc440322d4846fc230b290c818c32d6ea2e500fc930b0aa

Please note that the certificate-key gives access to cluster sensitive data, keep it secret!
As a safeguard, uploaded-certs will be deleted in two hours; If necessary, you can use
"kubeadm init phase upload-certs --upload-certs" to reload certs afterward.

Then you can join any number of worker nodes by running the following on each as root:

kubeadm join 192.168.0.236:16443 --token 7t2weq.bjbawausm0jaxury \
    --discovery-token-ca-cert-hash sha256:8c92ecb336be2b9372851a9af2c7ca1f7f60c12c68f6ffe1eb513791a1b8a908</code></pre>



<p>Master01节点配置环境变量，用于访问Kubernetes集群：</p>



<pre class="wp-block-code"><code>cat &lt;&lt;EOF >> /root/.bashrc
export KUBECONFIG=/etc/kubernetes/admin.conf
EOF
source /root/.bashrc</code></pre>



<p>查看节点状态：</p>



<pre class="wp-block-code"><code>&#91;root@k8s-master01 ~]# kubectl get nodes
NAME           STATUS     ROLES                  AGE   VERSION
k8s-master01   NotReady   control-plane,master   74s   v1.20.0</code></pre>



<p>采用初始化安装方式，所有的系统组件均以容器的方式运行并且在kube-system命名空间内，此时可以查看Pod状态：</p>



<pre class="wp-block-code"><code>&#91;root@k8s-master01 ~]# kubectl get pods -n kube-system -o wide
NAME                                   READY     STATUS    RESTARTS   AGE       IP              NODE
coredns-777d78ff6f-kstsz               0/1       Pending   0          14m       &lt;none>          &lt;none>
coredns-777d78ff6f-rlfr5               0/1       Pending   0          14m       &lt;none>          &lt;none>
etcd-k8s-master01                      1/1       Running   0          14m       192.168.0.107   k8s-master01
kube-apiserver-k8s-master01            1/1       Running   0          13m       192.168.0.107   k8s-master01
kube-controller-manager-k8s-master01   1/1       Running   0          13m       192.168.0.107   k8s-master01
kube-proxy-8d4qc                       1/1       Running   0          14m       192.168.0.107   k8s-master01
kube-scheduler-k8s-master01            1/1       Running   0          13m       192.168.0.107   k8s-master01</code></pre>



<p>19、高可用Master</p>



<p class="has-bright-red-color has-text-color has-link-color wp-elements-a3a7ebb6be2830d3df7124663d66af0e">注意：以下步骤是上述init命令产生的Token过期了才需要执行以下步骤，如果没有过期不需要执行</p>



<p><strong><em>Token</em></strong><strong><em>过期后生成新的</em></strong><strong><em>token</em></strong><strong><em>：</em></strong><strong><em></em></strong></p>



<p><strong><em>kubeadm token create &#8211;print-join-command</em></strong><strong><em></em></strong></p>



<p><strong><em>Master</em></strong><strong><em>需要生成</em></strong><strong><em>&#8211;certificate-key</em></strong><strong><em></em></strong></p>



<p><strong><em>kubeadm init phase upload-certs &nbsp;&#8211;upload-certs</em></strong><strong><em></em></strong></p>



<p>Token没有过期直接执行Join就行了</p>



<p>初始化其他master加入集群</p>



<pre class="wp-block-code"><code>kubeadm join 192.168.0.236:16443 --token fgtxr1.bz6dw1tci1kbj977     --discovery-token-ca-cert-hash sha256:06ebf46458a41922ff1f5b3bc49365cf3dd938f1a7e3e4a8c8049b5ec5a3aaa5 \
    --control-plane --certificate-key 03f99fb57e8d5906e4b18ce4b737ce1a055de1d144ab94d3cdcf351dfcd72a8b</code></pre>



<p>19、Node节点配置</p>



<p>Node节点上主要部署公司的一些业务应用，生产环境中不建议Master节点部署系统组件之外的其他Pod，测试环境可以允许Master节点部署Pod以节省系统资源。</p>



<pre class="wp-block-code"><code>kubeadm join 192.168.0.236:16443 --token 7t2weq.bjbawausm0jaxury \
    --discovery-token-ca-cert-hash sha256:8c92ecb336be2b9372851a9af2c7ca1f7f60c12c68f6ffe1eb513791a1b8a908</code></pre>



<p>所有节点初始化完成后，查看集群状态</p>



<pre class="wp-block-code"><code>&#91;root@k8s-master01]# kubectl  get node
NAME           STATUS     ROLES                  AGE     VERSION
k8s-master01   NotReady   control-plane,master   8m53s   v1.20.0
k8s-master02   NotReady   control-plane,master   2m25s   v1.20.0
k8s-master03   NotReady   control-plane,master   31s     v1.20.0
k8s-node01     NotReady   &lt;none>                 32s     v1.20.0
k8s-node02     NotReady   &lt;none>                 88s     v1.20.0</code></pre>



<p>20、Calico组件的安装</p>



<p>以下步骤只在master01执行</p>



<pre class="wp-block-code"><code>cd /root/k8s-ha-install &amp;&amp; git checkout manual-installation-v1.20.x &amp;&amp; cd calico/</code></pre>



<p>修改calico-etcd.yaml的以下位置</p>



<pre class="wp-block-code"><code>sed -i 's#etcd_endpoints: "http://&lt;ETCD_IP>:&lt;ETCD_PORT>"#etcd_endpoints: "https://192.168.0.107:2379,https://192.168.0.108:2379,https://192.168.0.109:2379"#g' calico-etcd.yaml


ETCD_CA=`cat /etc/kubernetes/pki/etcd/ca.crt | base64 | tr -d '\n'`
ETCD_CERT=`cat /etc/kubernetes/pki/etcd/server.crt | base64 | tr -d '\n'`
ETCD_KEY=`cat /etc/kubernetes/pki/etcd/server.key | base64 | tr -d '\n'`
sed -i "s@# etcd-key: null@etcd-key: ${ETCD_KEY}@g; s@# etcd-cert: null@etcd-cert: ${ETCD_CERT}@g; s@# etcd-ca: null@etcd-ca: ${ETCD_CA}@g" calico-etcd.yaml


sed -i 's#etcd_ca: ""#etcd_ca: "/calico-secrets/etcd-ca"#g; s#etcd_cert: ""#etcd_cert: "/calico-secrets/etcd-cert"#g; s#etcd_key: "" #etcd_key: "/calico-secrets/etcd-key" #g' calico-etcd.yaml

POD_SUBNET=`cat /etc/kubernetes/manifests/kube-controller-manager.yaml | grep cluster-cidr= | awk -F= '{print $NF}'`</code></pre>



<p class="has-bright-red-color has-text-color has-link-color wp-elements-224c0ceef975c191fec6141dba906680"># 注意下面的这个步骤是把calico-etcd.yaml文件里面的CALICO_IPV4POOL_CIDR下的网段改成自己的Pod网段，也就是把192.168.x.x/16改成自己的集群网段，并打开注释。</p>



<p>所以更改的时候请确保这个步骤的这个网段没有被统一替换掉，如果被替换掉了，还请改回来：</p>



<pre class="wp-block-code"><code>sed -i 's@# - name: CALICO_IPV4POOL_CIDR@- name: CALICO_IPV4POOL_CIDR@g; s@#   value: "192.168.0.0/16"@  value: '"${POD_SUBNET}"'@g' calico-etcd.yaml</code></pre>



<pre class="wp-block-code"><code>kubectl apply -f calico-etcd.yaml</code></pre>



<p>查看容器状态</p>



<pre class="wp-block-code"><code>&#91;root@k8s-master01 calico]# kubectl  get po -n kube-system
NAME                                       READY   STATUS    RESTARTS   AGE
calico-kube-controllers-5f6d4b864b-pwvnb   1/1     Running   0          3m29s
calico-node-5lz9m                          1/1     Running   0          3m29s
calico-node-8z4bg                          1/1     Running   0          3m29s
calico-node-lmzvf                          1/1     Running   0          3m29s
calico-node-mpngv                          1/1     Running   0          3m29s
calico-node-vmqsl                          1/1     Running   0          3m29s
coredns-54d67798b7-8525g                   1/1     Running   0          39m
coredns-54d67798b7-fxs72                   1/1     Running   0          39m
etcd-k8s-master01                          1/1     Running   0          39m
etcd-k8s-master02                          1/1     Running   0          33m
etcd-k8s-master03                          1/1     Running   0          31m
kube-apiserver-k8s-master01                1/1     Running   0          39m
kube-apiserver-k8s-master02                1/1     Running   0          33m
kube-apiserver-k8s-master03                1/1     Running   0          30m
kube-controller-manager-k8s-master01       1/1     Running   1          39m
kube-controller-manager-k8s-master02       1/1     Running   0          33m
kube-controller-manager-k8s-master03       1/1     Running   0          31m
kube-proxy-hnkmj                           1/1     Running   0          39m
kube-proxy-jk4dm                           1/1     Running   0          32m
kube-proxy-nbcg2                           1/1     Running   0          32m
kube-proxy-qv9k7                           1/1     Running   0          32m
kube-proxy-x6xdc                           1/1     Running   0          33m
kube-scheduler-k8s-master01                1/1     Running   1          39m
kube-scheduler-k8s-master02                1/1     Running   0          33m
kube-scheduler-k8s-master03                1/1     Running   0          30m</code></pre>



<p>21、Metrics部署</p>



<p>在新版的Kubernetes中系统资源的采集均使用Metrics-server，可以通过Metrics采集节点和Pod的内存、磁盘、CPU和网络的使用率。</p>



<p>将Master01节点的front-proxy-ca.crt复制到所有Node节点</p>



<pre class="wp-block-code"><code>scp /etc/kubernetes/pki/front-proxy-ca.crt k8s-node01:/etc/kubernetes/pki/front-proxy-ca.crt
scp /etc/kubernetes/pki/front-proxy-ca.crt k8s-node(其他节点自行拷贝):/etc/kubernetes/pki/front-proxy-ca.crt</code></pre>



<p>安装metrics server</p>



<pre class="wp-block-code"><code>cd /root/k8s-ha-install/metrics-server-0.4.x-kubeadm/

&#91;root@k8s-master01 metrics-server-0.4.x-kubeadm]# kubectl  create -f comp.yaml 
serviceaccount/metrics-server created
clusterrole.rbac.authorization.k8s.io/system:aggregated-metrics-reader created
clusterrole.rbac.authorization.k8s.io/system:metrics-server created
rolebinding.rbac.authorization.k8s.io/metrics-server-auth-reader created
clusterrolebinding.rbac.authorization.k8s.io/metrics-server:system:auth-delegator created
clusterrolebinding.rbac.authorization.k8s.io/system:metrics-server created
service/metrics-server created
deployment.apps/metrics-server created
apiservice.apiregistration.k8s.io/v1beta1.metrics.k8s.io created</code></pre>



<p>查看状态</p>



<pre class="wp-block-code"><code>&#91;root@k8s-master01 metrics-server-0.4.x-kubeadm]# kubectl  top node
NAME           CPU(cores)   CPU%   MEMORY(bytes)   MEMORY%   
k8s-master01   109m         2%     1296Mi          33%       
k8s-master02   99m          2%     1124Mi          29%       
k8s-master03   104m         2%     1082Mi          28%       
k8s-node01     55m          1%     761Mi           19%       
k8s-node02     53m          1%     663Mi           17%</code></pre>



<p>22、Dashboard部署</p>



<p>Dashboard用于展示集群中的各类资源，同时也可以通过Dashboard实时查看Pod的日志和在容器中执行一些命令等。</p>



<p>22.1、<strong>安装指定版本dashboard</strong></p>



<pre class="wp-block-code"><code>cd /root/k8s-ha-install/dashboard/

&#91;root@k8s-master01 dashboard]# kubectl  create -f .
serviceaccount/admin-user created
clusterrolebinding.rbac.authorization.k8s.io/admin-user created
namespace/kubernetes-dashboard created
serviceaccount/kubernetes-dashboard created
service/kubernetes-dashboard created
secret/kubernetes-dashboard-certs created
secret/kubernetes-dashboard-csrf created
secret/kubernetes-dashboard-key-holder created
configmap/kubernetes-dashboard-settings created
role.rbac.authorization.k8s.io/kubernetes-dashboard created
clusterrole.rbac.authorization.k8s.io/kubernetes-dashboard created
rolebinding.rbac.authorization.k8s.io/kubernetes-dashboard created
clusterrolebinding.rbac.authorization.k8s.io/kubernetes-dashboard created
deployment.apps/kubernetes-dashboard created
service/dashboard-metrics-scraper created
deployment.apps/dashboard-metrics-scraper created</code></pre>



<p>22.2、安装最新版本</p>



<p>官方GitHub地址：<a href="https://github.com/kubernetes/dashboard"><u>https://github.com/kubernetes/dashboard</u></a></p>



<p>可以在官方dashboard查看到最新版dashboard</p>



<p>kubectl apply -f <a href="https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.3/aio/deploy/recommended.yaml"><u>https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.3/aio/deploy/recommended.yaml</u></a></p>



<p>22.3、创建管理员用户<br>vim admin.yaml</p>



<pre class="wp-block-code"><code>apiVersion: v1
kind: ServiceAccount
metadata:
  name: admin-user
  namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding 
metadata: 
  name: admin-user
  annotations:
    rbac.authorization.kubernetes.io/autoupdate: "true"
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-admin
subjects:
- kind: ServiceAccount
  name: admin-user
  namespace: kube-system</code></pre>



<pre class="wp-block-code"><code>kubectl apply -f admin.yaml -n kube-system</code></pre>



<p>22.4、登录Dashboard</p>



<p>在谷歌浏览器（Chrome）启动文件中加入启动参数，用于解决无法访问Dashboard的问题，参考图1-1：</p>



<pre class="wp-block-code"><code>--test-type --ignore-certificate-errors</code></pre>



<figure class="wp-block-image size-full"><img fetchpriority="high" decoding="async" width="403" height="362" src="https://www.cnzid.com/wp-content/uploads/2024/07/图片1.png" alt="" class="wp-image-1857" srcset="https://www.cnzid.com/wp-content/uploads/2024/07/图片1.png 403w, https://www.cnzid.com/wp-content/uploads/2024/07/图片1-300x269.png 300w" sizes="(max-width: 403px) 85vw, 403px" /></figure>



<p></p>



<p>更改dashboard的svc为NodePort：</p>



<pre class="wp-block-code"><code>kubectl edit svc kubernetes-dashboard -n kubernetes-dashboard</code></pre>



<figure class="wp-block-image size-full"><img decoding="async" width="645" height="270" src="https://www.cnzid.com/wp-content/uploads/2024/07/图片2.png" alt="" class="wp-image-1859" srcset="https://www.cnzid.com/wp-content/uploads/2024/07/图片2.png 645w, https://www.cnzid.com/wp-content/uploads/2024/07/图片2-300x126.png 300w" sizes="(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px" /></figure>



<p>将ClusterIP更改为NodePort（如果已经为NodePort忽略此步骤）：</p>



<p>查看端口号：</p>



<pre class="wp-block-code"><code>kubectl get svc kubernetes-dashboard -n kubernetes-dashboard</code></pre>



<figure class="wp-block-image size-full"><img decoding="async" width="1014" height="105" src="https://www.cnzid.com/wp-content/uploads/2024/07/图片3.png" alt="" class="wp-image-1860" srcset="https://www.cnzid.com/wp-content/uploads/2024/07/图片3.png 1014w, https://www.cnzid.com/wp-content/uploads/2024/07/图片3-300x31.png 300w, https://www.cnzid.com/wp-content/uploads/2024/07/图片3-768x80.png 768w" sizes="(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px" /></figure>



<p>根据自己的实例端口号，通过任意安装了kube-proxy的宿主机或者VIP的IP+端口即可访问到dashboard：</p>



<p>访问Dashboard：<a href="https://192.168.0.200:18282（请更改18282为自己的端口）"><u>https://192.168.0.236:18282（请更改18282为自己的端口）</u></a>，选择登录方式为令牌（即token方式），参考图1-2</p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="674" height="409" src="https://www.cnzid.com/wp-content/uploads/2024/07/图片4.png" alt="" class="wp-image-1861" srcset="https://www.cnzid.com/wp-content/uploads/2024/07/图片4.png 674w, https://www.cnzid.com/wp-content/uploads/2024/07/图片4-300x182.png 300w" sizes="auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px" /></figure>



<p>查看token值：</p>



<pre class="wp-block-code"><code>&#91;root@k8s-master01 1.1.1]# kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep admin-user | awk '{print $1}')
Name:         admin-user-token-r4vcp
Namespace:    kube-system
Labels:       &lt;none>
Annotations:  kubernetes.io/service-account.name: admin-user
              kubernetes.io/service-account.uid: 2112796c-1c9e-11e9-91ab-000c298bf023

Type:  kubernetes.io/service-account-token

Data
====
ca.crt:     1025 bytes
namespace:  11 bytes
token:      eyJhbGciOiJSUzI1NiIsImtpZCI6IiJ9.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJhZG1pbi11c2VyLXRva2VuLXI0dmNwIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQubmFtZSI6ImFkbWluLXVzZXIiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC51aWQiOiIyMTEyNzk2Yy0xYzllLTExZTktOTFhYi0wMDBjMjk4YmYwMjMiLCJzdWIiOiJzeXN0ZW06c2VydmljZWFjY291bnQ6a3ViZS1zeXN0ZW06YWRtaW4tdXNlciJ9.bWYmwgRb-90ydQmyjkbjJjFt8CdO8u6zxVZh-19rdlL_T-n35nKyQIN7hCtNAt46u6gfJ5XXefC9HsGNBHtvo_Ve6oF7EXhU772aLAbXWkU1xOwQTQynixaypbRIas_kiO2MHHxXfeeL_yYZRrgtatsDBxcBRg-nUQv4TahzaGSyK42E_4YGpLa3X3Jc4t1z0SQXge7lrwlj8ysmqgO4ndlFjwPfvg0eoYqu9Qsc5Q7tazzFf9mVKMmcS1ppPutdyqNYWL62P1prw_wclP0TezW1CsypjWSVT4AuJU8YmH8nTNR1EXn8mJURLSjINv6YbZpnhBIPgUGk1JYVLcn47w</code></pre>



<p>将token值输入到令牌后，单击登录即可访问<br>Dashboard，参考图1-3：</p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="850" height="610" src="https://www.cnzid.com/wp-content/uploads/2024/07/图片5.png" alt="" class="wp-image-1862" srcset="https://www.cnzid.com/wp-content/uploads/2024/07/图片5.png 850w, https://www.cnzid.com/wp-content/uploads/2024/07/图片5-300x215.png 300w, https://www.cnzid.com/wp-content/uploads/2024/07/图片5-768x551.png 768w" sizes="auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px" /></figure>



<p>23、一些必须的配置更改</p>



<p>将Kube-proxy改为ipvs模式，因为在初始化集群的时候注释了ipvs配置，所以需要自行修改一下：</p>



<p>在master01节点执行</p>



<pre class="wp-block-code"><code>kubectl edit cm kube-proxy -n kube-system
mode: “ipvs”</code></pre>



<p>更新Kube-Proxy的Pod：</p>



<pre class="wp-block-code"><code>kubectl patch daemonset kube-proxy -p "{\"spec\":{\"template\":{\"metadata\":{\"annotations\":{\"date\":\"`date +'%s'`\"}}}}}" -n kube-system</code></pre>



<p>验证Kube-Proxy模式</p>



<pre class="wp-block-code"><code>&#91;root@k8s-master01 1.1.1]# curl 127.0.0.1:10249/proxyMode
ipvs</code></pre>



<p class="has-large-font-size">三、注意事项</p>



<p>注意：kubeadm安装的集群，证书有效期默认是一年。master节点的kube-apiserver、kube-scheduler、kube-controller-manager、etcd都是以容器运行的。可以通过kubectl get po -n kube-system查看。</p>



<p>启动和二进制不同的是：</p>



<p>kubelet的配置文件在/etc/sysconfig/kubelet和/var/lib/kubelet/config.yaml</p>



<p>其他组件的配置文件在/etc/Kubernetes/manifests目录下，比如kube-apiserver.yaml，该yaml文件更改后，kubelet会自动刷新配置，也就是会重启pod。不能再次创建该文件</p>



<p>Kubeadm安装后，master节点默认不允许部署pod，可以通过以下方式打开：</p>



<p>查看Taints：</p>



<pre class="wp-block-code"><code>&#91;root@k8s-master01 ~]# kubectl  describe node -l node-role.kubernetes.io/master=  | grep Taints
Taints:             node-role.kubernetes.io/master:NoSchedule
Taints:             node-role.kubernetes.io/master:NoSchedule
Taints:             node-role.kubernetes.io/master:NoSchedule

####删除Taint：#########
&#91;root@k8s-master01 ~]# kubectl  taint node  -l node-role.kubernetes.io/master node-role.kubernetes.io/master:NoSchedule-
node/k8s-master01 untainted
node/k8s-master02 untainted
node/k8s-master03 untainted
&#91;root@k8s-master01 ~]# kubectl  describe node -l node-role.kubernetes.io/master=  | grep Taints
Taints:             &lt;none>
Taints:             &lt;none>
Taints:             &lt;none></code></pre>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1846</post-id>	</item>
	</channel>
</rss>
