教程参考
环境配置
- 关闭防火墙
- 关闭selinux
- 关闭swap分区
- 时间同步
- hosts解析
- 内核参数设置
- 检查DNS
- 安装ipvs
- 安装依赖组件
- 安装、设置docker
每台机器都需要操作
shell
#安装工具
yum -y install net-tools
# 如果下载不行,设置一个repo
# sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
# sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
##关闭防火墙
systemctl stop firewalld.service
systemctl disable firewalld.service
##时间同步
yum install ntpdate -y
ntpdate pool.ntp.org
timedatectl set-timezone Asia/Shanghai
# 将 SELinux 设置为 permissive 模式(相当于将其禁用)
sudo setenforce 0
sudo sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config
#关闭swap
swapoff -a
sed -ri 's/.*swap.*/#&/' /etc/fstab
#允许 iptables 检查桥接流量
cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
br_netfilter
EOF
cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sudo sysctl --system
安装Docker
shell
sudo yum remove docker*
sudo yum install -y yum-utils
#配置docker的yum地址
sudo yum-config-manager \
--add-repo \
http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
#安装指定版本
sudo yum install -y docker-ce-20.10.7 docker-ce-cli-20.10.7 containerd.io-1.4.6
#安装
sudo yum install -y socat conntrack nfs-utils
# 启动&开机启动docker
systemctl enable docker --now
# docker加速配置
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://m7qysq7c.mirror.aliyuncs.com"],
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"storage-driver": "overlay2"
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
完成后可以制作镜像
安装实例选择 k8s_base_image_2,已经完成部分设置
首次安装-选取一台master
shell
export KKZONE=cn
curl -sfL https://get-kk.kubesphere.io | VERSION=v3.0.7 sh -
chmod +x kk
./kk create config --with-kubesphere v3.3.2 --with-kubernetes v1.22.12 -f config-sample.yaml
修改部分配置
config.yaml
yaml
apiVersion: kubekey.kubesphere.io/v1alpha2
kind: Cluster
metadata:
name: sample
spec:
hosts:
- {name: master1, address: 172.31.0.239, internalAddress: 172.31.0.239, user: root, password: "Hailiao$123"}
- {name: master2, address: 172.31.0.237, internalAddress: 172.31.0.237, user: root, password: "Hailiao$123"}
- {name: master3, address: 172.31.0.238, internalAddress: 172.31.0.238, user: root, password: "Hailiao$123"}
- {name: node1, address: 172.31.0.243, internalAddress: 172.31.0.243, user: root, password: "Hailiao$123"}
roleGroups:
etcd:
- master1
- master2
- master3
control-plane:
- master1
- master2
- master3
worker:
- node1
controlPlaneEndpoint:
## Internal loadbalancer for apiservers
## internalLoadbalancer: haproxy
# 阿里云的负载均衡
domain: lb.kubesphere.local
address: "1xx.xx.xx.xx"
port: 6443
kubernetes:
version: v1.22.12
clusterName: cluster.local
autoRenewCerts: true
containerManager: docker
etcd:
type: kubekey
network:
plugin: calico
kubePodsCIDR: 10.233.64.0/18
kubeServiceCIDR: 10.233.0.0/18
## multus support. https://github.com/k8snetworkplumbingwg/multus-cni
multusCNI:
enabled: false
registry:
privateRegistry: ""
namespaceOverride: ""
registryMirrors: []
insecureRegistries: []
addons:
- name: nfs-client
namespace: kube-system
sources:
chart:
name: nfs-client-provisioner
repo: https://charts.kubesphere.io/main
valuesFile: /root/nfs-client.yaml
没有全部复制,主要是完成了nfs初始化使用nas
nfs-client.yaml
yaml
nfs:
server: "xxx.nas.aliyuncs.com" # 阿里云Nas地址.
path: "/new_ks_data" # Replace the exported directory with your own.
storageClass:
defaultClass: true
运行安装
./kk create cluster -f config.yaml
选择这个镜像后,只需要设置hostname和hosts
每台机器使用内网ip互通
每台机器配置自己的hostname 每个机器分别执行 hostnamectl set-hostname xxx (node1~6)
shell
hostnamectl set-hostname node1 # node1 就是对应的主机名称
vim /etc/hosts
# 添加hosts信息
172.31.0.239 master1
172.31.0.237 master2
172.31.0.238 master3
172.31.0.243 node1
# 对应添加更多node主机名称