使用 Sealos 在 3 分鍾內快速部署一個生產級別的 Kubernetes 高可用集群


前提條件:

  • 安裝並啟動docker, 高版本離線包自帶docker,如沒安裝docker會自動安裝
  • 下載kubernetes 離線安裝包.
  • 下載最新版本sealos.
  • 務必同步服務器時間
  • 主機名不可重復
  • master節點CPU必須2C以上
  • 請使用sealos 3.2.0以上版本

1、下載並安裝sealos, sealos是個golang的二進制工具,直接下載拷貝到bin目錄即可, release頁面也可下載

wget -c https://sealyun.oss-cn-beijing.aliyuncs.com/latest/sealos && chmod +x sealos && mv sealos /usr/bin

2、下載離線資源包

wget -c https://sealyun.oss-cn-beijing.aliyuncs.com/7b6af025d4884fdd5cd51a674994359c-1.18.0/kube1.18.0.tar.gz

3、使用默認配置文件安裝高可用k8s集群:

sealos init --master 192.168.131.60 \
    --master 192.168.131.61 \
    --master 192.168.131.62 \
    --node 192.168.131.63 \
    --node 192.168.131.64 \
    --node 192.168.131.65 \
    --node 192.168.131.66 \
    --node 192.168.131.67 \
    --node 192.168.131.68 \
    --node 192.168.131.69 \
    --version v1.18.0 \
    --pkg-url /root/kube1.18.0.tar.gz 
參數名 含義 示例
passwd 服務器密碼 123456
master k8s master節點IP地址 192.168.0.2
node k8s node節點IP地址 192.168.0.3
pkg-url 離線資源包地址,支持下載到本地,或者一個遠程地址 /root/kube1.16.0.tar.gz
version 資源包對應的版本 v1.16.0

注意:因為服務器之間我做了ssh免登陸,所以不需要使用密碼參數,執行完sealos init命令幾分鍾一個高可用k8s集群就安裝完了。

使用自定義kubeadm配置文件(添加外部etcd集群):

先獲取配置文件模板:

sealos config -t kubeadm >>  kubeadm-config.yaml.tmpl

修改kubeadm-config.yaml.tmpl,文件即可, 編輯增加 sealyun.com, 注意其它部分不用動,sealos會自動填充模板里面的內容:

apiVersion: kubeadm.k8s.io/v1beta1
kind: ClusterConfiguration
kubernetesVersion: {{.Version}}
controlPlaneEndpoint: "{{.ApiServer}}:6443"
imageRepository: {{.Repo}}
networking:
  # dnsDomain: cluster.local
  podSubnet: {{.PodCIDR}}
  serviceSubnet: {{.SvcCIDR}}
etcd:
    external:
        caFile: /data/etcd/ssl/ca.pem
        certFile: /data/etcd/ssl/server.pem
        keyFile: /data/etcd/ssl/server-key.pem
        endpoints:
        - https://192.168.131.60:2379
        - https://192.168.131.61:2379
        - https://192.168.131.62:2379
apiServer:
  certSANs:
  - 127.0.0.1
  - {{.ApiServer}}
  {{range .Masters -}}
  - {{.}}
  {{end -}}
  {{range .CertSANS -}}
  - {{.}}
  {{end -}}
  - {{.VIP}}
  extraArgs:
    feature-gates: TTLAfterFinished=true
  extraVolumes:
  - name: localtime
    hostPath: /etc/localtime
    mountPath: /etc/localtime
    readOnly: true
    pathType: File
controllerManager:
  extraArgs:
    feature-gates: TTLAfterFinished=true
    experimental-cluster-signing-duration: 876000h
  extraVolumes:
  - hostPath: /etc/localtime
    mountPath: /etc/localtime
    name: localtime
    readOnly: true
    pathType: File
scheduler:
  extraArgs:
    feature-gates: TTLAfterFinished=true
  extraVolumes:
  - hostPath: /etc/localtime
    mountPath: /etc/localtime
    name: localtime
    readOnly: true
    pathType: File
---
apiVersion: kubeproxy.config.k8s.io/v1alpha1
kind: KubeProxyConfiguration
mode: "ipvs"
ipvs:
  excludeCIDRs: 
  - "{{.VIP}}/32"

使用自定義配置文件安裝高可用k8s集群:

sealos init --kubeadm-config /data/kubeadm-config.yaml.tmpl \
    --master 192.168.131.60 \
    --master 192.168.131.61 \
    --master 192.168.131.62 \
    --node 192.168.131.63 \
    --node 192.168.131.64 \
    --node 192.168.131.65 \
    --node 192.168.131.66 \
    --node 192.168.131.67 \
    --node 192.168.131.68 \
    --node 192.168.131.69 \
    --version v1.18.0 \
    --pkg-url /root/kube1.18.0.tar.gz 

官方文檔:https://sealyun.com/docs/

參考文章:https://www.cnblogs.com/hi-linux/archive/2019/10/14/11673002.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM