跳转到内容

使用KubeKey安装Kubernetes和KubeSphere

lyonmu

相关链接

下载操作系统

官网安装文档

资源配置

  • 本操作文档仅在Ubuntu 24.04.2下生效,其他操作系统不保证成功
  • 采用在线安装的方式,所以集群所有服务器都需要可以访问外网
序号主机IP配置信息角色OS
1192.168.100.204C8G 200GBmaster1Ubuntu 24.04.2 LTS
2192.168.100.214C8G 200GBmaster2Ubuntu 24.04.2 LTS
3192.168.100.224C8G 200GBmaster3Ubuntu 24.04.2 LTS
4192.168.100.2316C32G 500GBworker1Ubuntu 24.04.2 LTS
5192.168.100.2416C32G 500GBworker2Ubuntu 24.04.2 LTS

调整服务器配置

所有五台机器都要配置

配置root用户ssh登录

  1. 配置root密码

    sudo passwd root
  2. 开启root用户ssh远程登录

    sudo vi /etc/ssh/sshd_config
    • PermitRootLogin参数改为yes
    • PasswordAuthentication参数改为yes
  3. 重启ssh服务

    sudo service ssh restart

设置主机名、关闭swap

swapoff -a && sed -i '/[[:space:]]swap[[:space:]]/s/^/#/' /etc/fstab && swapon --show && hostnamectl set-hostname k8smaster1 && hostname

更新包、安装包

# 更新包索引,安装需要的包
apt-get update && apt-get upgrade && apt-get install -y vim socat conntrack ebtables ipset chrony locales language-pack-zh-hans && sudo sed -i '/^# *zh_CN.UTF-8 UTF-8/s/^# *//' /etc/locale.gen && locale-gen && source /etc/default/locale && apt-get autoremove -y

# 增加命令提示,修复环境
unminimize

配置时钟服务

vim /etc/chrony/chrony.conf

# 修改配置文件 sudo vim /etc/chrony/chrony.conf  ,添加如下行
server ntp.tencent.com minpoll 4 maxpoll 10 iburst
server ntp1.tencent.com minpoll 4 maxpoll 10 iburst
server ntp2.tencent.com minpoll 4 maxpoll 10 iburst
server ntp3.tencent.com minpoll 4 maxpoll 10 iburst
server ntp4.tencent.com minpoll 4 maxpoll 10 iburst
server ntp5.tencent.com minpoll 4 maxpoll 10 iburst
server ntp.aliyun.com minpoll 4 maxpoll 10 iburst
server ntp1.aliyun.com minpoll 4 maxpoll 10 iburst
server ntp2.aliyun.com minpoll 4 maxpoll 10 iburst
server ntp3.aliyun.com minpoll 4 maxpoll 10 iburst
server ntp4.aliyun.com minpoll 4 maxpoll 10 iburst
server ntp5.aliyun.com minpoll 4 maxpoll 10 iburst
server ntp6.aliyun.com minpoll 4 maxpoll 10 iburst
server ntp7.aliyun.com minpoll 4 maxpoll 10 iburst

# 重启服务刷新时间
systemctl restart chrony && chronyc makestep && chronyc tracking && systemctl status chrony.service
  • server ntp.tencent.com: 这是 NTP 服务器的域名。chrony将连接到这个服务器以获取时间同步。
  • minpoll: 这个参数指定了最小的轮询间隔(以 2 的幂为单位)。minpoll 4表示最小的轮询间隔为2^4=16秒。这意味着chrony至少每 16 秒就会与此服务器进行一次同步请求。
  • maxpoll: 这个参数指定了最大的轮询间隔。maxpoll 10表示最大的轮询间隔为2^10=1024秒。因此,chrony可能会将轮询间隔调整到 1024 秒,但不会低于 16 秒。
  • iburst: 这个选项是一个补充参数,用于加快初次同步过程。当chrony启动后,它会通过发送一组快速请求(通常是 8 个请求)来快速获取服务器的时间。在这个例子中,iburst会在启动后立即向ntp.cloud.aliyuncs.com发送多个请求,确保在短时间内迅速获得准确的时间

配置服务器DNS

所有五台机器都要配置

sudo mkdir -p /etc/systemd/resolved.conf.d

sudo tee /etc/systemd/resolved.conf.d/dns.conf > /dev/null <<'EOF'
[Resolve]
DNS=180.184.1.1 223.5.5.5  114.114.114.114
FallbackDNS=223.6.6.6 180.184.2.2
Domains=~.
EOF

sudo systemctl restart systemd-resolved

通过KubeKey安装kubernetes

在k8smaster1进行配置

安装KubeKey

export KKZONE=cn

curl -sfL https://get-kk.kubesphere.io | sh -

sudo chmod +x kk

生成和调整部署文件

在k8smaster1进行配置

# 查看KubeKey支持的kubernetes版本
./kk version --show-supported-k8s

# 根据版本生成部署文件,命令执行完毕后将生成安装配置文件 config-sample.yaml
./kk create config --with-kubernetes v1.33.1

安装helm

在k8smaster1进行配置

在kubernetes安装KubeSphere

在k8smaster1进行部署

helm upgrade --install -n kubesphere-system --create-namespace ks-core https://charts.kubesphere.com.cn/main/ks-core-1.1.4.tgz --debug --wait --set ksExtensionRepository.enabled=true --set global.imageRegistry=swr.cn-southwest-2.myhuaweicloud.com/ks --set extension.imageRegistry=swr.cn-southwest-2.myhuaweicloud.com/ks

# 提示以下信息代表安装成功
# NOTES:
# Thank you for choosing KubeSphere Helm Chart.
#
# Please be patient and wait for several seconds for the KubeSphere deployment to complete.
#
# 1. Wait for Deployment Completion
#
#     Confirm that all KubeSphere components are running by executing the following command:
#
#     kubectl get pods -n kubesphere-system
# 2. Access the KubeSphere Console
#
#     Once the deployment is complete, you can access the KubeSphere console using the following URL:
#
#     http://192.168.100.20:30880
#
# 3. Login to KubeSphere Console
#
#     Use the following credentials to log in:
#
#     Account: admin
#     Password: P@88w0rd

kubectl get pod -A

安装KubeSphere插件中心和监控服务

在k8smaster1进行部署

配置containerd镜像仓库和代理

所有五台机器都要配置

测试部署consul

在k8smaster1进行部署

Anterior
Ubuntu安装dpdk与vpp
Siguiente
Ubuntu编译envoy