前往小程序,Get更优阅读体验!
立即前往
发布
社区首页 >专栏 >CentOS 7.9 上安装 Kubernetes 和 KubeSphere

CentOS 7.9 上安装 Kubernetes 和 KubeSphere

原创
作者头像
全栈研发知识库
修改2025-03-05 11:23:24
修改2025-03-05 11:23:24
1590
举报

在 Linux 上安装 Kubernetes 和 KubeSphere

在 Linux 上安装 Kubernetes 和 KubeSphere,安装过程中将用到开源工具 KubeKey,有关 KubeKey 的更多信息,请访问 GitHub KubeKey 仓库

1 Linux 准备

1.1 Linux 配置

准备3台最低配置为4核16G的Linux服务器 ( 本文使用 CentOS 7.9 ),

1.2 Linux 网络

确保所有服务器属于同一子网、关闭所有服务器防火墙

本文三台服务器IP地址:192.168.80.201、192.168.80.202、192.168.80.203

代码语言:shell
复制
sudo systemctl stop firewalld
sudo systemctl disable firewalld

1.3 Linux 时间同步

确保所有服务器时间同步:参考 CentOS7.9使用chrony同步时间

1.4 Linux 安装依赖项

需要为所有集群节点安装 socat、conntrack、ebtables 和 ipset

代码语言:shell
复制
yum install socat conntrack ebtables ipset -y

参数说明:-y 自动确认无需手动确认安装或卸载过程

1.5 Linux 安装Docker并配置镜像加速

参考:https://cloud.tencent.com/developer/article/2475828

2. 创建 Kubernetes 集群

登录任意集群节点,本文登录的是:192.168.80.201 节点机器,执行下面的命令,注意使用KubeKey创建 Kubernetes 集群,只需在一台节点执行下列操作。

2.1 设置 KubeKey 下载区域

代码语言:shell
复制
export KKZONE=cn

2.2 下载 KubeKey 最新版本

代码语言:shell
复制
curl -sfL https://get-kk.kubesphere.io | sh -

2.3 为 KubeKey 二进制文件 kk 添加执行权限

代码语言:shell
复制
sudo chmod +x kk

2.4 创建安装配置文件 config-sample.yaml

查看三台机器的主机名:本文是 kube-01、kube-02、kube-03,分别对应IP 192.168.80.201、192.168.80.202、192.168.80.203

代码语言:shell
复制
# 查看主机名
uname -n

创建安装配置文件 config-sample.yaml

代码语言:shell
复制
./kk create config --with-kubernetes v1.28.12

KubeSphere 默认支持 Kubernetes v1.21~1.28, 此处安装最新版本:v1.28.12 ,命令执行完毕后将生成安装配置文件 config-sample.yaml

2.5 编辑安装配置文件 config-sample.yaml

代码语言:shell
复制
vi config-sample.yaml

编辑hosts,本文用户名使用root,密码是 123qwe,设置kube-01作为etcd和控制节点,kube-02、kube-03作为工作节点。设置:containerManager 为 docker 。

代码语言:yml
复制
apiVersion: kubekey.kubesphere.io/v1alpha2
kind: Cluster
metadata:
  name: sample
spec:
  hosts:
  - {name: kube-01, address: 192.168.80.201, internalAddress: 192.168.80.201, user: root, password: "123qwe"}
  - {name: kube-02, address: 192.168.80.202, internalAddress: 192.168.80.202, user: root, password: "123qwe"}
  - {name: kube-03, address: 192.168.80.203, internalAddress: 192.168.80.203, user: root, password: "123qwe"}
  roleGroups:
    etcd:
    - kube-01
    control-plane:
    - kube-01
    worker:
    - kube-02
    - kube-03
  controlPlaneEndpoint:
    ## Internal loadbalancer for apiservers
    # internalLoadbalancer: haproxy

    domain: lb.kubesphere.local
    address: ""
    port: 6443
  kubernetes:
    version: v1.28
    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: []

2.6 创建 Kubernetes 集群

代码语言:shell
复制
./kk create cluster -f config-sample.yaml

2.7 创建成功标志

如果显示如下信息,则表明 Kubernetes 集群创建成功

代码语言:txt
复制
Pipeline[CreateclusterPipeline] execute successfully

3.安装 KubeSphere

KubeSphere Core (ks-core) 是 KubeSphere 的核心组件,为扩展组件提供基础的运行环境。KubeSphere Core 安装完成后,即可访问 KubeSphere Web 控制台。

在集群任意控制节点执行以下命令:

3.1 安装 Helm

代码语言:shell
复制
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash

3.2 安装 KubeSphere Core

代码语言:shell
复制
helm upgrade --install -n kubesphere-system --create-namespace ks-core https://charts.kubesphere.io/main/ks-core-1.1.3.tgz --debug --wait --set global.imageRegistry=swr.cn-southwest-2.myhuaweicloud.com/ks

3.3 安装成功提示

如果显示如下信息,则表明 ks-core 安装成功

代码语言:txt
复制
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.80.201:30880

3. Login to KubeSphere Console

    Use the following credentials to log in:

    Account: admin
    Password: P@88w0rd

NOTE: It is highly recommended to change the default password immediately after the first login.

For additional information and details, please visit https://kubesphere.io.

从成功信息中的 Console、Account 和 Password 参数分别获取 KubeSphere Web 控制台的 IP 地址、管理员用户名和管理员密码,并使用网页浏览器登录 KubeSphere Web 控制台

参考文档:

KubeSphere - 官网 - 环境要求

KubeSphere - 官网 - 在 Linux 上安装 Kubernetes 和 KubeSphere

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 在 Linux 上安装 Kubernetes 和 KubeSphere
    • 1 Linux 准备
      • 1.1 Linux 配置
      • 1.2 Linux 网络
      • 1.3 Linux 时间同步
      • 1.4 Linux 安装依赖项
      • 1.5 Linux 安装Docker并配置镜像加速
    • 2. 创建 Kubernetes 集群
      • 2.1 设置 KubeKey 下载区域
      • 2.2 下载 KubeKey 最新版本
      • 2.3 为 KubeKey 二进制文件 kk 添加执行权限
      • 2.4 创建安装配置文件 config-sample.yaml
      • 2.5 编辑安装配置文件 config-sample.yaml
      • 2.6 创建 Kubernetes 集群
      • 2.7 创建成功标志
    • 3.安装 KubeSphere
      • 3.1 安装 Helm
      • 3.2 安装 KubeSphere Core
      • 3.3 安装成功提示
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档