【K8s】专题三(5):Kubernetes 安装方法之 KubeOne

以下内容均来自个人笔记并重新梳理,如有错误欢迎指正!如果对您有帮助,烦请点赞、关注、转发!欢迎扫码关注个人公众号!

公众号二维码


目录

一、KubeOne 简介

二、KubeOne 下载、安装

三、KubeOne 部署 Kubernetes 集群

四、KubeOne 常用命令


一、KubeOne 简介

Kubermatic KubeOne 可以在云、本地、 边缘和物联网等环境安装高可用集群以及单主集群。

KubeOne 借助 kubeadm 来处理配置和升级任务,大多数任务都是通过 SSH 运行命令来执行的。

默认情况下,KubeOne 会部署 Canal CNI 插件、metrics-server、NodeLocalDNS 和 Kubermatic 机器控制器。

KubeOne 项目地址:GitHub - kubermatic/kubeone

KubeOne 官网地址:Kubermatic


二、KubeOne 下载、安装
# AMD架构
wget https://github.com/kubermatic/kubeone/releases/download/v1.7.4/kubeone_1.7.4_linux_amd64.zip
unzip kubeone_1.7.4_linux_amd64.zip -d kubeone
cp kubeone/kubeone /usr/bin
 
# ARM架构
wget https://github.com/kubermatic/kubeone/releases/download/v1.7.4/kubeone_1.7.4_linux_arm64.zip
unzip kubeone_1.7.4_linux_arm64.zip -d kubeone
cp kubeone/kubeone /usr/bin
 
# 查看版本信息
kubeone version


三、KubeOne 部署 Kubernetes 集群

1、准备工作

# 关闭防火墙
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
 
# 配置主机间 SSH 免密(详细过程略)
 
# 安装 docker 或 containerd(详细过程略)

2、创建配置

# 指定集群配置、Kubernetes 版本等
cat > kubeone.yaml <<EOF
apiVersion: kubeone.k8c.io/v1beta2
kind: KubeOneCluster
name: my-cluster
versions:
  kubernetes: 'v1.27.13'
cloudProvider:
  none: {}
controlPlane:
  hosts:
    - publicAddress: ''
      privateAddress: '172.16.100.1'
      sshUsername: root
      sshPrivateKeyFile: '/root/.ssh/id_rsa'
staticWorkers:
  hosts:
    - publicAddress: ''
      privateAddress: '172.16.100.2'
      sshUsername: root
      sshPrivateKeyFile: '/root/.ssh/id_rsa'
# Provide the external address of your load balancer or the public addresses of the first control plane nodes
apiEndpoint:
  host: '172.16.100.1'
  port: 6443
machineController:
  deploy: false

# 指定镜像仓库(kubeadm、calico、flannel)
registryConfiguration:
  overwriteRegistry: 'm.daocloud.io/registry.k8s.io'
  insecureRegistry: false

EOF

3、部署集群

kubeone apply -m kubeone.yaml

# -m:--manifest,指定配置文件

---------------------------------------------------------
🔔 部分组件的镜像需要手动下载并修改 tag:
ctr -n k8s.io i pull docker.io/flannel/flannel:v0.21.3
ctr -n k8s.io i tag docker.io/flannel/flannel:v0.21.3 m.daocloud.io/registry.k8s.io/flannel/flannel:v0.21.3
ctr -n k8s.io i pull quay.io/calico/cni:v3.26.3
ctr -n k8s.io i tag quay.io/calico/cni:v3.26.3 m.daocloud.io/registry.k8s.io/calico/cni:v3.26.3
ctr -n k8s.io i pull quay.io/calico/kube-controllers:v3.26.3
ctr -n k8s.io i tag quay.io/calico/kube-controllers:v3.26.3 m.daocloud.io/registry.k8s.io/calico/kube-controllers:v3.26.3
ctr -n k8s.io i pull quay.io/calico/node:v3.26.3
ctr -n k8s.io i tag quay.io/calico/node:v3.26.3 m.daocloud.io/registry.k8s.io/calico/node:v3.26.3

---------------------------------------------------------
# 配置 kubeconfig 文件
## kubeone 会自动生成名为 my-cluster-kubeconfig 的 kubeconfig 文件
cp my-cluster-kubeconfig .kube/config

---------------------------------------------------------
# 去除污点
kubectl taint node --all node-role.kubernetes.io/control-plane-

4、实测结果

Kubernetes 集群组件均以容器方式运行。

# kubeone apply -m kubeone.yaml 输出
INFO[17:26:10 CST] Determine hostname...                        
INFO[17:26:14 CST] Determine operating system...                
INFO[17:26:16 CST] Running host probes...                       
The following actions will be taken: 
Run with --verbose flag for more information.
        + initialize control plane node "master01" (172.16.100.1) using 1.27.13

Do you want to proceed (yes/no): yes

INFO[17:26:59 CST] Determine hostname...                        
INFO[17:26:59 CST] Determine operating system...                
INFO[17:26:59 CST] Running host probes...                       
INFO[17:27:14 CST] Installing prerequisites...                  
INFO[17:27:14 CST] Creating environment file...                  node=172.16.100.1 os=centos
INFO[17:27:17 CST] Configuring proxy...                          node=172.16.100.1 os=centos
INFO[17:27:17 CST] Installing kubeadm...                         node=172.16.100.1 os=centos
INFO[17:27:59 CST] Generating kubeadm config file...            
INFO[17:27:59 CST] Determining Kubernetes pause image...        
INFO[17:28:06 CST] Uploading config files...                     node=172.16.100.1
INFO[17:28:24 CST] Running kubeadm preflight checks...          
INFO[17:28:24 CST]      preflight...                                 node=172.16.100.1
INFO[17:28:27 CST] Pre-pull images                               node=172.16.100.1
INFO[17:28:35 CST] Configuring certs and etcd on control plane node... 
INFO[17:28:35 CST] Ensuring Certificates...                      node=172.16.100.1
INFO[17:28:40 CST] Downloading PKI...                           
INFO[17:28:53 CST] Creating local backup...                      node=172.16.100.1
INFO[17:28:53 CST] Uploading PKI...                             
INFO[17:28:53 CST] Configuring certs and etcd on consecutive control plane node... 
INFO[17:28:53 CST] Initializing Kubernetes on leader...         
INFO[17:28:53 CST] Running kubeadm...                            node=172.16.100.1
INFO[17:29:01 CST] Building Kubernetes clientset...             
INFO[17:29:04 CST] Waiting 20s for CSRs to approve...            node=172.16.100.1
INFO[17:29:24 CST] Approve pending CSR "csr-nbzbr" for username "system:node:master01"  node=172.16.100.1
INFO[17:29:24 CST] Approve pending CSR "csr-rtqnk" for username "system:node:master01"  node=172.16.100.1
INFO[17:29:24 CST] Check if cluster needs any repairs...        
INFO[17:29:30 CST] Joining controlplane node...                 
INFO[17:29:30 CST] Restarting unhealthy API servers if needed... 
INFO[17:29:33 CST] Determining Kubernetes pause image...        
INFO[17:29:34 CST] Patching static pods...                      
INFO[17:29:49 CST] Downloading kubeconfig...                    
INFO[17:29:52 CST] Downloading PKI...                           
INFO[17:30:07 CST] Creating local backup...                      node=172.16.100.1
INFO[17:30:07 CST] Activating additional features...            
INFO[17:30:07 CST] Patching CoreDNS...                          
INFO[17:30:07 CST] Skipping creating credentials secret because cloud provider is none. 
INFO[17:30:07 CST] CSI driver for "none" not yet supported, skipping 
INFO[17:30:07 CST] CSI driver for "none" not yet supported, skipping 
INFO[17:30:07 CST] Applying addon coredns-pdb...                
INFO[17:30:12 CST] CSI driver for "none" not yet supported, skipping 
INFO[17:30:12 CST] Applying addon metrics-server...             
INFO[17:30:15 CST] CSI driver for "none" not yet supported, skipping 
INFO[17:30:15 CST] Applying addon cni-canal...                  
INFO[17:30:20 CST] CSI driver for "none" not yet supported, skipping 
INFO[17:30:20 CST] Applying addon nodelocaldns...


四、KubeOne 常用命令
kubeone -h
Provision and maintain Kubernetes High-Availability clusters with ease

Usage:
  kubeone [flags]
  kubeone [command]

Available Commands:
  addons      Manage addons
  apply       Reconcile the cluster
  completion  Generates completion scripts for bash and zsh
  config      Commands for working with the KubeOneCluster configuration manifests
  document    Generates documentation
  help        Help about any command
  init        init new kubeone cluster configuration
  kubeconfig  Download the kubeconfig file from master
  local       Reconcile the local one-node-all-in-one cluster
  migrate     Commands for running different migrations
  proxy       Proxy to the kube-apiserver using SSH tunnel
  reset       Revert changes
  status      Status of the cluster
  version     Display KubeOne version

Flags:
  -c, --credentials string              File to source credentials and secrets from
  -d, --debug                           debug output with stacktrace
  -h, --help                            help for kubeone
  -l, --log-format string               format for logging (default "text")
  -m, --manifest string                 Path to the KubeOne config (default "./kubeone.yaml")
  -t, --tfjson terraform output -json   Source for terraform output in JSON - to read from stdin. If path is a file, contents will be used. If path is a dictionary, terraform output -json is executed in this path
  -v, --verbose                         verbose output

Use "kubeone [command] --help" for more information about a command.
# 查看集群状态
kubeone status

# 清理集群
kubeone reset -m kubeone.yaml
🔔 添加 --remove-binaries 选项时移除 kubeadm、kubelet、kubectl

# 升级集群版本
kubeone upgrade -m kubeone.yaml --force
或
kubeone apply -m kubeone.yaml --force-upgrade

  • 9
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
安装 KubernetesK8S)需要多个步骤,以下是一些基本步骤: 1. 准备好至少两台服务器,其中一台将用作主节点(Master Node),其余的将用作工作节点(Worker Nodes)。 2. 在每台服务器上安装 Docker。这可以通过命令行运行以下命令来完成: ``` $ curl -sSL get.docker.com | sh && \ sudo usermod -aG docker $USER ``` 3. 安装 Kubernetes 工具。Kubernetes 有很多不同的工具,但最常用的是 kubeadm、kubectl 和 kubelet。这些可以通过以下命令来安装: ``` $ sudo apt-get update && \ sudo apt-get install -y apt-transport-https curl && \ curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add - && \ echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list && \ sudo apt-get update && \ sudo apt-get install -y kubelet kubeadm kubectl ``` 4. 在主节点上初始化 Kubernetes。这可以通过以下命令来完成: ``` $ sudo kubeadm init --pod-network-cidr=10.244.0.0/16 ``` 5. 安装网络插件。这将使您的工作节点可以与其他节点通信。我们建议使用 Flannel 网络插件,可以通过以下命令安装: ``` $ kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml ``` 6. 加入工作节点。在主节点上运行 `kubeadm init` 命令时,会生成一个命令,您可以将其复制到工作节点上运行,以加入 Kubernetes 集群。 ``` $ sudo kubeadm join <master-node-ip>:<master-node-port> --token <token> --discovery-token-ca-cert-hash <hash> ``` 以上是安装 Kubernetes 的基本步骤。请注意,这只是一个大致的指南,具体的步骤可能因您的环境而异。更详细的指南可以在 Kubernetes 官方文档中找到。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值