一、安装Docker-CE
安装包依赖:yum install -y yum-utils device-mapper-persistent-data lvm2 wget
添加原件源:yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
更新yum缓存:yum clean all && yum makecache fast
安装docker-ce:yum -y install docker-ce
docker启动:service docker start
二、安装kubectl
# 下载二进制包,添加可执行权限,移动到bin目录,
# 因为我是root登录的所以是/usr/bin,其他用户登录是/usr/local/bin
curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.18.0/bin/linux/amd64/kubectl &&\
chmod +x ./kubectl &&\
mv ./kubectl /usr/bin/kubectl
三、安装minikube
wget https://github.com/kubernetes/minikube/releases/download/v1.7.3/minikube-linux-amd64 &&\
mv minikube-linux-amd64 minikube &&\
chmod +x minikube &&\
mv minikube /usr/bin/
四、启动minikube
1. 设置虚拟机为双核4G内存
2. 设置防火墙为 Iptables 并设置空规则
关闭默认自带防火墙:systemctl stop firewalld && systemctl disable firewalld
安装iptables管理工具,并清空规则:yum -y install iptables-services && systemctl start iptables && systemctl enable iptables && iptables -F && service iptables save
3. 关闭SELinux
setenforce 0 && sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
4. 关闭SWap
swapoff -a && sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fsta
5. 调整内核参数
cat > kubernetes.conf <<EOF
net.bridge.bridge-nf-call-iptables=1
net.bridge.bridge-nf-call-ip6tables=1
net.ipv4.ip_forward=1
net.ipv4.tcp_tw_recycle=0
vm.swappiness=0 # 禁止使用 swap 空间,只有当系统 OOM 时才允许使用它
vm.overcommit_memory=1 # 不检查物理内存是否够用
vm.panic_on_oom=0 # 开启 OOM
fs.inotify.max_user_instances=8192
fs.inotify.max_user_watches=1048576
fs.file-max=52706963
fs.nr_open=52706963
net.ipv6.conf.all.disable_ipv6=1
net.netfilter.nf_conntrack_max=2310720
EOF
调用配置:cp kubernetes.conf /etc/sysctl.d/kubernetes.conf && sysctl -p /etc/sysctl.d/kubernetes.conf
6. 启动minikube
启动minikube下载所需镜像,不会用vbox所以用默认容器驱动启动的,切记要配置虚拟机DNS:minikube start --image-repository=registry.cn-hangzhou.aliyuncs.com/google_containers --cpus=2 --memory=4096 --vm-driver=none
五、添加阿里云加速器
cat > /etc/docker/daemon.json <<EOF
{
"registry-mirrors": [
"https://registry.docker-cn.com"
]
}
EOF
docker重启后台运行:service docker restart && systemctl enable docker