一、minikube部署单机k8s环境

注意:此处为方便测试,使用minikube部署单机k8s环境,生产环境请根据实际情况操作

1.安装docker-ce

依赖安装:
yum install -y yum-utils device-mapper-persistent-data lvm2 wget

添加docker软件源:
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:
systemctl start docker

2.安装kunectl

# 下载二进制包
# 默认root用户控制操作所以是/usr/bin【存放系统预装的可执行程序路径】,其他普通用户是/usr/local/bin

curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.23.1/bin/linux/amd64/kubectl

添加可执行权限,移动到bin目录
chmod +x ./kubectl && mv ./kubectl /usr/bin/kubectl

查看版本号,看是否部署成功
kubectl version --client
#正常返回为
Client Version: version.Info{Major:"1", Minor:"23", GitVersion:"v1.23.1", GitCommit:"86ec240af8cbd1b60bcc4c03c20da9b98005b92e", GitTreeState:"clean", BuildDate:"2021-12-16T11:41:01Z", GoVersion:"go1.17.5", Compiler:"gc", Platform:"linux/amd64"}

3.安装minikube

下载安装包#直接下载速度慢或者链接超时,建议下载到本地再上传服务器
wget -P /usr/bin https://github.com/kubernetes/minikube/releases/download/v1.25.2/minikube-linux-amd64

添加可执行权限
mv /usr/bin/minikube-linux-amd64 /usr/bin/minikube && chmod +x /usr/bin/minikube

4.优化配置

关闭iptables
#安装iptables管理工具,并清空规则
yum -y install iptables-services && systemctl start iptables && systemctl enable iptables && iptables -F && systemctl iptables save

关闭selinux
setenforce 0 && sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config

关闭swap
swapoff -a  # 临时 
sed -ri 's/.*swap.*/#&/' /etc/fstab    # 永久 

设置内核参数
cp -a /etc/sysctl.conf /etc/sysctl.conf.bak$(date +%F)
vim /etc/k8s.conf
---------------------------------------
net.ipv4.ip_forward = 1
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_recycle = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.neigh.default.gc_thresh3 = 4096
net.ipv4.conf.all.promote_secondaries = 1
net.ipv4.conf.default.accept_source_route = 0
net.ipv4.conf.default.promote_secondaries = 1

net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 0
net.ipv6.conf.default.disable_ipv6 = 0
net.ipv6.neigh.default.gc_thresh3 = 4096 

kernel.sysrq = 1
kernel.printk = 5
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.numa_balancing = 0
kernel.core_uses_pid = 1
kernel.shmmax = 68719476736
kernel.softlockup_panic = 1

# 将桥接的IPv4流量传递到iptables的链
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1

# 禁止使用 swap 空间,只有当系统 OOM 时才允许使用它
vm.swappiness = 0
# 不检查物理内存是否够用
vm.overcommit_memory = 1
# 开启 OOM
vm.panic_on_oom = 0

fs.nr_open = 52706963
fs.file-max = 52706963
fs.inotify.max_user_instances = 8192
fs.inotify.max_user_watches = 1048576
net.netfilter.nf_conntrack_max = 2310720
---------------------------------------

sysctl -p /etc/k8s.conf

# 在master节点执行命令,创建文件
# modprobe,用于向内核中加载模块或者从内核中移除模块,此处添加配置文件永久加载br_netfilter模块,即使重启也生效
vim  /etc/sysconfig/modules/br_netfiter.modules
-------------------------
modprobe br_netfilter
-------------------------

# 授可执行权限
chmod 755 /etc/sysconfig/modules/br_netfiter.modules

# 将新增配置载入系统生效
sysctl --system  

# 时间同步
yum install ntpdate -y && ntpdate pool.ntp.org

5.启动minikube

安装tools
yum -y install conntrack
 
启动minikube,此步骤较久,等待
minikube start --vm-driver=none --image-mirror-country=cn --registry-mirror='https://ckdhnbk9.mirror.aliyuncs.com' --image-repository='registry.cn-hangzhou.aliyuncs.com/google_containers' --cpus=2 --memory=2048

参数释义
--cpus=2      # 为虚拟机分配核数
--memory=2048 # 分配内存

6.添加腾讯云加速器

根据实际需求添加公有云加速器,此处以腾讯云为例子

cat > /etc/docker/daemon.json <<EOF
{
 "registry-mirrors": ["https://mirror.ccs.tencentyun.com"]
}
EOF

重启docker
systemctl daemon-reload && systemctl restart docker && systemctl enable docker && systemctl status docker


阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6
标签: k8s