kubernetes,K8S升级
1、centos 7用kubeasz和ansible进行二进制部署k8s
kubeasz下载:kubeasz
kubeasz:kubeasz安装方式
网站上定义了kubeasz和kubernetes的版本对应,按照要求对应安装
部署需要3台设备以上,CPU最好双核以上
设备的内核要升级到4.0版本以上
内核升级文档:内核
角色 | IP |
---|---|
ansible | 192.168.116.130 |
k8s-master | 192.168.116.132 |
k8s-node | 192.168.116.133 |
1.1设备都初始化配置
cd /etc/yum.repos.d/
yum install -y wget
wget http://mirrors.aliyun.com/repo/Centos-7.repo
wget http://mirrors.aliyun.com/repo/epel-7.repo
mv CentOS-Base.repo CentOS-Base.repo.bak
yum clean all
yum makecache
systemctl stop firewalld
systemctl disable firewalld
sed -i 's/SELINUX=enforcing$/SELINUX=disabled/g' /etc/selinux/config
setenforce 0
1.2 ansible配置:
hostnamectl set-hostname ansible-130
vi /etc/hosts
192.168.116.130 ansible-130
192.168.116.132 k8s-master
192.168.116.133 k8s-node1
设置秘钥连接和复制host文件
ssh-keygen
ssh-copy-id root@192.168.116.132
ssh-copy-id root@192.168.116.133
scp /etc/hosts root@192.168.116.132:/etc/hosts
scp /etc/hosts root@192.168.116.133:/etc/hosts
下载脚本,自动下载k8s需要的安装包
yum install -y python git python-pip ansible python-netaddr -y
curl -C- -fLO --retry 3 https://github.com/easzlab/kubeasz/releases/download/2.2.0/easzup
在脚本定义了下载的安装包版本,可以自己手动修改,但是需要注意kubeasz和kubernetes的版本对应关系
vi easzup
export DOCKER_VER=19.03.5
export KUBEASZ_VER=2.2.0
export K8S_BIN_VER=v1.17.2
export EXT_BIN_VER=0.4.0
export SYS_PKG_VER=0.3.3
chmod +x ./easzup
./easzup -D
配置安装的版本
cd /etc/ansible/
cp example/hosts.multi-node ./hosts
设置master和node的IP和软件配置
vi hosts 修改配置
#设置etcd的IP
[etcd]
192.168.116.132 NODE_NAME=etcd1
# master node(s) #设置master节点的IP
[kube-master]
192.168.116.132
# work node(s) #设置node节点的IP
[kube-node]
192.168.116.133
# K8S Service CIDR, not overlap with node(host) networking #k8s集群管理IP段
SERVICE_CIDR="10.0.0.0/16"
# Cluster CIDR (Pod CIDR), not overlap with node(host) networking #k8s集群容器IP段
CLUSTER_CIDR="20.0.0.0/16"
# NodePort Rang #设置node对外开放端口
NODE_PORT_RANGE="20000-40000"
# Cluster DNS Domain #设置DNS域名
CLUSTER_DNS_DOMAIN="cluster.local."
ansible all -m ping 测试ansible到节点的网络是否正常
开始安装k8s
ansible-playbook 01.prepare.yml
ansible-playbook 02.etcd.yml
ansible-playbook 03.docker.yml
ansible-playbook 04.kube-master.yml
ansible-playbook 05.kube-node.yml
ansible-playbook 06.network.yml
1.3在master查看k8s状态
hostnamectl set-hostname k8s-master
kubectl get pod -A
kubectl get nodes
运行容器测试k8s能否正常工作
kubectl run net-test --image=alpine --replicas=1 sleep 360000
kubectl get pod -A
可以看到pod的的IP和node的IP
kubectl get pod -A -o wide
1.4 在master安装coredns,解析外部网站域名
wget https://storage.googleapis.com/kubernetes-release/release/v1.17.2/kubernetes.tar.gz
cd /root/kubernetes/cluster/addons/dns/coredns/
cp</