k8s-v1.19.1 的Centos7.x下搭建
基于centos7所有主机设置/etc/hosts#关闭swapoffswapoff -a #临时sed -ri 's/.*swap.*/#&/' /etc/fstab #永久#关闭防火墙systemctl stop firewalld systemctl disable firewalld#时间同步systemctl start chronyd.servicesystemctl enab
基于centos7
所有主机
设置/etc/hosts
#关闭swapoff
swapoff -a #临时
sed -ri 's/.*swap.*/#&/' /etc/fstab #永久
#关闭防火墙
systemctl stop firewalld systemctl disable firewalld
#时间同步
systemctl start chronyd.service
systemctl enable chronyd.service
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
#关闭SELINUX
setenforce 0
sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config
通过yum安装Docker
# step 1: 安装必要的一些系统工具
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
# Step 2: 添加软件源信息
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
## 安装指定版本的Docker-CE:
## Step 3.1: 查找Docker-CE的版本:
## yum list docker-ce.x86_64 --showduplicates | sort -r
## Step 3.2 : 安装指定版本的Docker-CE
## yum -y --setopt=obsoletes=0 install docker-ce-[VERSION] docker-ce-selinux-[VERSION]
# Step 3: 更新并安装 Docker-CE
yum -y install docker-ce-19.03 docker-ce-selinux
# Step 4: 开启Docker服务 #可以创建/etc/docker/daemon.json文件
systemctl enable docker && systemctl start docker
配置阿里云镜像docker加速器
cat << EOF > /etc/docker/daemon.json
{
"exec-opts": ["native.cgroupdriver=systemd"],
"registry-mirrors": ["https://0bb06s1q.mirror.aliyuncs.com"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"storage-driver": "overlay2",
"storage-opts": ["overlay2.override_kernel_check=true"]
}
EOF
# 重启docker
systemctl daemon-reload && systemctl restart docker && systemctl enable docker.service
#安装kubeadm,kubectl,kubelet
添加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 install -y kubelet-1.19.1 kubeadm-1.19.1 kubectl-1.19.1
# 设置kubelet开机启动
systemctl enable kubelet && systemctl start kubelet
修改k8s.conf文件
cat <<EOF > /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl --system
echo "1" > /proc/sys/net/ipv4/ip_forward
所有机器初始化完毕
Master安装部署
导出kubeadm集群部署自定义文件
kubeadm config print init-defaults > init.default.yaml
#修改自定义配置文件
修改如下问题
- 主节点IP——advertiseAddress
- 国内阿里镜像地址imageRepository——registry.aliyuncs.com/google_containers
- pod网段配置——不同网络插件网段不一样详细见
#拉取阿里云kubernetes容器镜像
kubeadm config images list --config init.default.yaml kubeadm config images pull --config init.default.yaml
imageRepository: registry.aliyuncs.com/google_containers
#初始化
kubeadm init --config=init.default.yaml
#配置用户证书 (会在上面初始化后输出)
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
#查看集群状态 notready原因是没有安装pod网络。
kubectl get node
安装pod网络——Calico
不同pod网络对pod网段要求不一样见官网。我这边安装的是Calico。
kubectl apply -f https://docs.projectcalico.org/v3.11/manifests/calico.yaml
master 完成安装
node安装
在master执行查看节点加入命令
kubeadm token create --print-join-command
根据输出信息在node节点执行加入命令即可
#重置
kubeadm reset
rm -rf /etc/cni/net.d/
rm -rf /etc/kubernetes/
rm -rf ~/.kube/
do Master安装部署
本次安装版本
docker version
Client: Docker Engine - Community
Version: 19.03.12
kubectl version
Client Version: version.Info{Major:"1", Minor:"19", GitVersion:"v1.19.1", GitCommit:"206bcadf021e76c27513500ca24182692aabd17e", GitTreeState:"clean", BuildDate:"2020-09-09T11:26:42Z", GoVersion:"go1.15", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"19", GitVersion:"v1.19.0", GitCommit:"e19964183377d0ec2052d1f1fa930c4d7575bd50", GitTreeState:"clean", BuildDate:"2020-08-26T14:23:04Z", GoVersion:"go1.15", Compiler:"gc", Platform:"linux/amd64"}
更多推荐
所有评论(0)