k8s部署-1-环境要求

主机列表

master1 192.168.0.26
master2
master3
node1 192.168.0.134
node2 192.168.0.70
node3

环境要求

centos7.7版本
cpu 2核
内存 4G

一准备工作

systemctl stop firewalld
systemctl disable firewalld
setenforce 0

1 更新包 增加yum源

cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[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

yum clean all
yum -y makecache
yum install -y git vim lrzsz unzip lsof wget ntp ntpdate
ntpdate 0.asia.pool.ntp.org

2 修改主机名/查看修改结果/设置hostname 解析

hostnamectl set-hostname master1
more /etc/hostname
hostnamectl status
echo "127.0.0.1   $(hostname)" >> /etc/hosts

3 禁用swap

swapoff -a
sed -i.bak '/swap/s/^/#/' /etc/fstab

4 增加br_netfilter模块

cat > /etc/rc.sysinit << EOF
#!/bin/bash
for file in /etc/sysconfig/modules/*.modules ; do
[ -x $file ] && $file
done
EOF

cat > /etc/sysconfig/modules/br_netfilter.modules << EOF 
modprobe br_netfilter 
EOF
chmod 755 /etc/sysconfig/modules/br_netfilter.modules

5 内核参数永久修改

sysctl net.bridge.bridge-nf-call-iptables=1
net.bridge.bridge-nf-call-iptables = 1
sysctl net.bridge.bridge-nf-call-ip6tables=1
net.bridge.bridge-nf-call-ip6tables = 1
cat <<EOF >  /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl -p /etc/sysctl.d/k8s.conf

net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1

6 免密登陆ssh master1-3执行(手动操作)/把master1-3 id_rsa.pub 复制为一个里面 传输到所有的服务器

ssh-keygen -t rsa

7 node节点执行

ssh-keygen
cd /root/.ssh/
cat id_rsa.pub >> authorized_keys
scp authorized_keys root@node节点ip:~/.ssh/

kubectl config set-context dev --namespace=development --cluster=lkubernetes-admin@kubernetes --user=kubernetes-admin@kubernetes
kubectl config set-context prod --namespace=production --cluster=kubernetes-admin@kubernetes --user=kubernetes-admin@kubernetes