k8s 高可用集群1:前提条件
Kubernetes(k8s)高可用集群1:前提条件
每台机器均需要执行
命令自动补充
shellsudo yum -y install bash-completion source /etc/profile
安装所需工具
shellsudo yum -y install vim sudo yum -y install wget
安装并配置 ntpdate,同步时间
shellsudo yum -y install ntpdate sudo ntpdate ntp1.aliyun.com sudo systemctl status ntpdate sudo systemctl start ntpdate sudo systemctl status ntpdate sudo systemctl enable ntpdate
将主机名指向本机IP,主机名只能包含:字母、数字、-(横杠)、.(点)
获取主机名
shellhostname
临时设置主机名
shellhostname 主机名
永久设置主机名
shellsudo echo '主机名' > /etc/hostname
编辑 hosts
shellsudo vim /etc/hosts
控制面板:设置IP
shell192.168.*.* 主机名
关闭防火墙
shell# 关闭防火墙 systemctl stop firewalld.service systemctl disable firewalld.service
关闭 selinux
shellgetenforce cat /etc/selinux/config sudo setenforce 0 sudo sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config cat /etc/selinux/config
关闭交换空间
shellsudo swapoff -a sudo sed -i 's/.*swap.*/#&/' /etc/fstab
调整网络
shell# 设置所需的 sysctl 参数,参数在重新启动后保持不变 cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf net.bridge.bridge-nf-call-iptables = 1 net.bridge.bridge-nf-call-ip6tables = 1 net.ipv4.ip_forward = 1 EOF # 应用 sysctl 参数而不重新启动 sudo sysctl --system
全局变量、修改本机hosts,用于后期使用
shellecho "" >> /etc/profile # 全局变量,一般仅需要修改此处即可,其他均不需要改 echo "MASTER_1_IP=192.168.80.81" >> /etc/profile echo "MASTER_2_IP=192.168.80.82" >> /etc/profile echo "MASTER_3_IP=192.168.80.83" >> /etc/profile # VIP 负载均衡器IP echo "VIP_IP=192.168.80.100" >> /etc/profile # 网卡名称 echo "INTERFACE_NAME=ens33" >> /etc/profile source /etc/profile cat /etc/profile
安装 Docker
shell# https://docs.docker.com/engine/install/centos/ sudo yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine sudo yum install -y yum-utils device-mapper-persistent-data lvm2 sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo # yum --showduplicates list docker-ce sudo yum install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin sudo yum install -y containerd # 启动 docker 时,会启动 containerd # sudo systemctl status containerd.service --no-pager sudo systemctl stop containerd.service sudo cp /etc/containerd/config.toml /etc/containerd/config.toml.bak sudo containerd config default > $HOME/config.toml sudo cp $HOME/config.toml /etc/containerd/config.toml # 修改 /etc/containerd/config.toml 文件后,要将 docker、containerd 停止后,再启动 sudo sed -i "s#registry.k8s.io/pause#registry.cn-hangzhou.aliyuncs.com/google_containers/pause#g" /etc/containerd/config.toml # https://kubernetes.io/zh-cn/docs/setup/production-environment/container-runtimes/#containerd-systemd # 确保 /etc/containerd/config.toml 中的 disabled_plugins 内不存在 cri sudo sed -i "s#SystemdCgroup = false#SystemdCgroup = true#g" /etc/containerd/config.toml # containerd 忽略证书验证的配置 # [plugins."io.containerd.grpc.v1.cri".registry.configs] # [plugins."io.containerd.grpc.v1.cri".registry.configs."192.168.0.12:8001".tls] # insecure_skip_verify = true sudo systemctl enable --now containerd.service # sudo systemctl status containerd.service --no-pager # sudo systemctl status docker.service --no-pager sudo systemctl start docker.service # sudo systemctl status docker.service --no-pager sudo systemctl enable docker.service sudo systemctl enable docker.socket sudo systemctl list-unit-files | grep docker sudo mkdir -p /etc/docker sudo tee /etc/docker/daemon.json <<-'EOF' { "registry-mirrors": ["https://hnkfbj7x.mirror.aliyuncs.com"], "exec-opts": ["native.cgroupdriver=systemd"] } EOF sudo systemctl daemon-reload sudo systemctl restart docker sudo docker info sudo systemctl status docker.service --no-pager sudo systemctl status containerd.service --no-pager