前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >【K8s】专题四:Kubernetes 安装方法之 Sealos

【K8s】专题四:Kubernetes 安装方法之 Sealos

作者头像
行者Sun
发布2024-09-02 12:32:48
1360
发布2024-09-02 12:32:48
举报
文章被收录于专栏:Kubernetes

以下内容均来自个人笔记并重新梳理,如有错误欢迎指正!

如果对您有帮助,烦请点赞、关注、转发!如果您有其他想要了解的,欢迎私信联系我~

Sealos 简介

Sealos 是一个基于 Kubernetes 的云操作系统发行版。它采用云原生的方式,抛弃传统的云计算架构,转向以 Kubernetes 为内核的新架构。

Sealos 秉承可以像 Linux 一样简单使用云的理念,在 Sealos 的架构中,公有云和私有云没有本质区别,都只需要安装云操作系统。

与 Sealer 类似,Sealos 可以打包整个 kubernetes 集群实现分布式应用的离线交付。本文将详细介绍通过 Sealos 在本地部署服务器上 kubernetes 集群的方法。

Sealos 下载、安装

代码语言:javascript
复制
# AMD架构
wget https://github.com/labring/sealos/releases/download/v4.3.7/sealos_4.3.7_linux_amd64.tar.gz
tar -xzf sealos_4.3.7_linux_amd64.tar.gz -C /usr/bin
chmod +x /usr/bin/sealos

# ARM架构
wget https://github.com/labring/sealos/releases/download/v4.3.7/sealos_4.3.7_linux_arm64.tar.gz
tar -xzf sealos_4.3.7_linux_arm64.tar.gz -C /usr/bin
chmod +x /usr/bin/sealos

# 查看版本信息
sealos version

Sealos 部署 Kubernetes 集群

1、准备工作

代码语言:javascript
复制
# 关闭防火墙
systemctl disable --now firewalld

# 关闭 selinxu
setenforce 0
sed -i ’s/SELINUX=enforcing/SELINUX=disabled/g’ /etc/selinux/config

# 清空 iptables 规则
iptables -F && iptables -t nat -F

# 禁用 swap 分区
swapoff -a
sed -i '/swap / s/^\(.*\)$/#\1/g' /etc/fstab

# /etc/hosts 文件添加条目(需要保证主机的 hostname 唯一)
172.16.200.166  master
172.16.200.167  node

# 配置主机间 SSH 免密(详细过程略)

2、部署集群

  • 方式一
代码语言:javascript
复制
sealos run labring/kubernetes:v1.26.0 labring/calico:v3.24.1 --masters 172.16.200.166 --nodes 172.16.200.167
 
🔔 提示一
# labring/kubernetes:v1.26.0:指定集群镜像名称,可以通过 https://explore.ggcr.dev 查询
# labring/calico:v3.24.1:指定 Calico 镜像名称
# --masters:指定集群 Master 节点的 IP 地址,多个 IP 通过 ,进行分隔
# --nodes:指定集群 Node 节点的 IP 地址,多个 IP 通过 ,进行分隔
 
🔔 提示二
# Nginx-Ingress-Controller 等组件需要自行安装
  • 方式二
代码语言:javascript
复制
sealos apply -f Clusterfile.yaml
 
🔔 提示
可以通过 clusterfile.yaml 自定义部署配置,如 kubeadm 配置、Docker 配置等

clusterfile.yaml 自定义配置示例

代码语言:javascript
复制
🔔 定义集群信息
---
apiVersion: apps.sealos.io/v1beta1
kind: Cluster
metadata:
  name: mycluster
spec:
  image:
    - labring/kubernetes:v1.26.0
    - labring/calico:v3.24.1
  ssh:
    user: root
    pk: /root/.ssh/id_rsa
    passwd: xxxx
    port: 22
  hosts:
    - ips:
        - 172.16.200.166:22
      roles:
        - master
        - amd64
    - ips:
        - 172.16.200.167:22
      roles:
        - node
        - amd64
 
🔔 定义 Calico 配置
---
apiVersion: apps.sealos.io/v1beta1
kind: Config
metadata:
  name: calico
spec:
  path: charts/calico/values.yaml
  strategy: merge
  data: |
    installation:
      enabled: true
      kubernetesProvider: ""
      calicoNetwork:
        ipPools:
        - blockSize: 26
          cidr: 10.160.0.0/12
          encapsulation: IPIP
          natOutgoing: Enabled
          nodeSelector: all()
        nodeAddressAutodetectionV4:
          interface: "eth.*|en.*"

3、实测结果

  • Sealos 部署 Kubernetes 集群同样高效
  • Sealos 支持的操作系统很广泛,并同时支持 AMD 64 架构和 ARM 64 架构

Sealos 常用命令

代码语言:javascript
复制
sealos --help
 
sealos is a Kubernetes distribution, a unified OS to manage cloud native applications.
 
Cluster Management Commands:
  apply         Run cloud images within a kubernetes cluster with Clusterfile
  cert          update Kubernetes API server's cert
  run           Run cloud native applications with ease, with or without a existing cluster
  reset         Reset all, everything in the cluster
  status        state of sealos
Node Management Commands:
  add           Add nodes into cluster
  delete        Remove nodes from cluster
Remote Operation Commands:
  exec          Execute shell command or script on specified nodes
  scp           Copy file to remote on specified nodes
Experimental Commands:
  registry      registry related
Container and Image Commands:
  build         Build an image using instructions in a Containerfile or Kubefile
  create        Create a cluster without running the CMD, for inspecting image
  diff          Inspect changes to the object's file systems
  inspect       Inspect the configuration of a container or image
  images        List images in local storage
  load          Load image(s) from archive file
  login         Login to a container registry
  logout        Logout of a container registry
  manifest      Manipulate manifest lists and image indexes
  merge         merge multiple images into one
  pull          Pull images from the specified location
  push          Push an image to a specified destination
  rmi           Remove one or more images from local storage
  save          Save image into archive file
  tag           Add an additional name to a local image
 
Other Commands:
  completion    Generate the autocompletion script for the specified shell
  docs          generate API reference
  env           prints out all the environment information in use by sealos
  gen           generate a Clusterfile with all default settings
  version       Print version info
 
Use "sealos <command> --help" for more information about a given command.
代码语言:javascript
复制
# 查看集群镜像
sealos images
 
# 添加 Master 节点
sealos add --masters 172.16.200.168
 
# 删除 Master 节点
sealos delete --masters 172.16.200.168
 
# 添加 Node 节点
sealos add --nodes 172.16.200.168
 
# 删除 Node 节点
sealos delete --nodes 172.16.200.168
 
# 在集群节点上批量执行 shell 命令
sealos exec "cat /etc/hosts"
 
# 查看集群统计信息
sealos status
 
# 删除集群
sealos reset --force

Sealos 构建集群镜像(ClusterImage)

1、编写 kubefile 文件

Kubefile 与 Dockerfile 极其相似,由连续列出的各种命令(指令)和参数组成,用于在基础 ClusterImage 上自动执行指令,构建新的 ClusterImage。

  • Docker 使用 Dockerfile 构建 Docker 镜像,并使用 Docker 镜像运行 Docker 容器,解决了单主机应用程序的几乎所有交付问题
  • Sealos 使用 Kubefile 构建 ClusterImage,并使用 ClusterImage 运行 Kubernetes 集群,将交付概念扩展到集群级别,并且主要关注分布式应用程序的视角
代码语言:javascript
复制
FROM labring/kubernetes:v1.26.0
 
COPY daemon.json etc/

2、构建集群镜像

代码语言:javascript
复制
sealos build -t labring/kubernetes:v1.26.0-fix -f kubefile .

Sealos 与 Sealer 对比

Sealos 和 Sealer 都是开源项目,旨在简化 Kubernetes 集群的部署和管理,使用方法和相关命令也极为相似,但是笔者在接触过后感觉 Sealer 在 Kubernetes 集群部署上明显更加高效易用。

Sealos 的主要特点包括:

开箱即用:提供预配置的 Kubernetes 环境,无需额外配置

易于管理:提供统一的管理工具和控制台

安全可靠:提供安全加固和增强功能

可扩展性:支持集群扩展和缩减

Sealer 的主要特点包括:

简单易用:无需编写复杂命令

快速部署:支持一键部署 Kubernetes 集群

高可用性:提供高可用集群部署方案

可扩展性:支持集群扩展和缩减

Sealos

Sealer

定位

Kubernetes 发行版

Kubernetes 部署工具

用户

企业、组织

运维人员、开发人员

特点

开箱即用、易于管理、安全可靠

简单易用、快速部署

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2024-05-16,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 实施运维知识交流 微信公众号,前往查看

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

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
容器服务
腾讯云容器服务(Tencent Kubernetes Engine, TKE)基于原生 kubernetes 提供以容器为核心的、高度可扩展的高性能容器管理服务,覆盖 Serverless、边缘计算、分布式云等多种业务部署场景,业内首创单个集群兼容多种计算节点的容器资源管理模式。同时产品作为云原生 Finops 领先布道者,主导开源项目Crane,全面助力客户实现资源优化、成本控制。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档