centos 7 环境配置:
1 关闭防火墙
systemctl stop firewalld
systemctl disable fiewalld 设置防火墙开机不启动
2 关闭selinux
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux
setenforce 0
3 网桥过滤
vi /etc/sysctl.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-arptables = 1
net.ipv4.ip_forward=1
net.ipv4.ip_forward_use_pmtu = 0
生效命令
sysctl --system
查看效果
sysctl -a|grep "ip_forward"
4 卡其ipvs
安装IPVS yum -y install ipset ipvsdm
编译ipvs.modules文件
vi /etc/sysconfig/modules/ipvs.modules
文件内容如下 #!/bin/bash modprobe -- ip_vs
modprobe -- ip_vs_rr modprobe -- ip_vs_wrr
modprobe -- ip_vs_sh
modprobe -- nf_conntrack_ipv4
赋予权限并执行
chmod 755 /etc/sysconfig/modules/ipvs.modules && bash /etc/sysconfig/modules/ipvs.modules &&lsmod | grep -e ip_vs -e nf_conntrack_ipv4
重启电脑,检查是否生效
reboot lsmod | grep ip_vs_rr
命令补全:
安装bash-completion
yum -y install bash-completion bash-completion-extras
使用bash-completion
source /etc/profile.d/bash_completion.sh
docker 安装参考阿里云:
Docker CE 镜像源站-阿里云开发者社区Docker CE 镜像源站https://developer.aliyun.com/article/110806
设置dockers开机启动:systemctl enable docker
修改Cgroup Driver
修改daemon.json,新增: "exec-opts": ["native.cgroupdriver=systemd"]
重启docker服务:
systemctl daemon-reload
systemctl restart docker
查看修改后状态: docker info | grep Cgroup
k8s 初始化
1 新建repo文件
vi /etc/yum.repos.d/kubernates.repo
cat>>/etc/yum.repos.d/kubrenetes.repo<
name=Kubernetes Repo
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
EOF
2 更新缓存
yum clean all
yum -y makecache
3 验证源是否可用
yum list | grep kubeadm
如果提示要验证yum-key.gpg是否可用,输入y。 查找到kubeadm。显示版本
4 查看k8s 版本
yum list kubelet --showduplicates | sort -r
5 安装k8s-1.17.5
yum install -y kubelet-1.17.5 kubeadm-1.17.5 kubectl-1.17.5
6 设置kubelet
增减配置信息
vi /etc/sysconfig/kubelet
KUBELET_EXTRA_ARGS="--cgroup-driver=systemd"
设置开机启动: systemctl enable kubelet
7 初始化镜像
1) 查看安装集群需要的镜像
kubeadm config images list
2) 编写脚本
mkdir -p /data cd data vi images.sh
images=( kube-apiserver:v1.17.5 kube-controller-manager:v1.17.5 kube-scheduler:v1.17.5 kube-proxy:v1.17.5 pause:3.1 etcd:3.4.3-0 coredns:1.6.5 )
for imageName in ${images[@]} ;
do docker pull registry.cnhangzhou.aliyuncs.com/google_containers/$imageName docker tag registry.cnhangzhou.aliyuncs.com/google_containers/$imageName k8s.gcr.io/$imageName docker rmi registry.cnhangzhou.aliyuncs.com/google_containers/$imageName
done
3) 执行脚本
chmod +x images.sh 执行脚本 ./images.sh
4) 保存镜像
docker save -o k8s.1.17.5.tar \ k8s.gcr.io/kube-proxy:v1.17.5 \ k8s.gcr.io/kube-apiserver:v1.17.5 \ k8s.gcr.io/kube-controller-manager:v1.17.5 \ k8s.gcr.io/kube-scheduler:v1.17.5 \ k8s.gcr.io/coredns:1.6.5 \ k8s.gcr.io/etcd:3.4.3-0 \ k8s.gcr.io/pause:3.1 \
8 初始化集群
1)配置集群网络
镜像下载:
docker pull calico/cni:v3.14.2
docker pull calico/pod2daemon-flexvol:v3.14.2
docker pull calico/node:v3.14.2
docker pull calico/kube-controllers:v3.14.
2) 配置hostname
hostnamectl set-hostname k8s-master01
3) 初始化集群信息
ubeadm init --apiserver-advertise-address=192.168.198.156 --kubernetesversion v1.17.5 --service-cidr=10.1.0.0/16 --pod-network-cidr=10.81.0.0/16
4) 执行配置命令
mkdir -p $HOME/.kube sudo
cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
5) node 节点加入
kubeadm join 192.168.198.186:6443 --token kksfgq.b9bhf82y35ufw4np \ --discovery-token-ca-cert-hash sha256:e1e347e6db1db5c13fcdc2c7d51a2f9029100a4cc13c2d89a2dbfa5077f5b07f
初始化master 节点网络
kubectl apply -f calico.yml
如果用的是公网ip
etcd 会报如下错误
请参考:记录一次etcd报错: listen tcp xxx.xxx.xxx.xxx:2380:bind: cannot assign requested address_雷蒙96的博客-CSDN博客