为了方便实验,先建一个装有docker和k8s基础组件的操作系统镜像。
我的系统环境:CentOS 7.7.1908
[root@K8s-Master1 opt]# cat /etc/redhat-release CentOS Linux release 7.7.1908 (Core)
卸载旧版本docker
yum remove -y docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-selinux docker-engine-selinux docker-engine
安装必要的系统工具
yum install -y yum-utils device-mapper-persistent-data lvm2
添加阿里云的更新源
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
更新yum缓存:
yum makecache fast
安装并启动Docker-ce
yum install -y docker-ce-18.09.7 docker-ce-cli-18.09.7 containerd.io systemctl enable docker systemctl start docker
配置镜像加速
/etc/docker/daemon.json
中写入如下内容(如果文件不存在请新建该文件)
{ "registry-mirrors": [ "https://dockerhub.azk8s.cn", "https://reg-mirror.qiniu.com" ] }
修改docker Cgroup Driver为systemd
vi /usr/lib/systemd/system/docker.service,添加 --exec-opt native.cgroupdriver=systemd
加载配置文件,重启docker
systemctl daemon-reload systemctl restart docker
配置K8S的yum源
cat <<EOF > /etc/yum.repos.d/kubernetes.repo [kubernetes] name=Kubernetes baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64 enabled=1 gpgcheck=0 repo_gpgcheck=0 gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg EOF
关闭 防火墙、SeLinux、swap
systemctl stop firewalld systemctl disable firewalld setenforce 0 sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config swapoff -a yes | cp /etc/fstab /etc/fstab_bak cat /etc/fstab_bak |grep -v swap > /etc/fstab
修改 /etc/sysctl.conf,添加如下内容
net.ipv4.ip_forward = 1 net.bridge.bridge-nf-call-ip6tables = 1 net.bridge.bridge-nf-call-iptables = 1
保存后执行sysctl -p
安装 kubelet、kubeadm、kubectl,并启动
yum install -y kubelet-1.16.0 kubeadm-1.16.0 kubectl-1.16.0 systemctl enable kubelet systemctl start kubelet
完成这些,可以去掉网络接口IP、hostname配置,转换为虚拟机模板了。