2 Star 4 Fork 2

徐晓伟 / k8s.sh

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
Clone or Download
contribute
Sync branch
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README
Apache-2.0

k8s.sh

Kubernetes(k8s)自动安装配置脚本

License-Anti Link-996 QQ群

为简化开发工作、提高生产率、解决常见问题而生

  1. 支持 CentOS 7/8、Anolis 7/8/23 系统主流版本,点击查看详情
    1. CentOS 7.3 流水线示例 - 需要升级内核 kernel 并重启系统使其生效
    2. CentOS 7.4 流水线示例 - 需要升级内核 kernel 并重启系统使其生效
    3. CentOS 7.5 流水线示例 - 需要升级内核 kernel 并重启系统使其生效
    4. CentOS 7.6 流水线示例
    5. CentOS 7.7 流水线示例
    6. CentOS 7.8 流水线示例
    7. CentOS 7.9 流水线示例
    8. CentOS 8.1 流水线示例
    9. CentOS 8.2 流水线示例
    10. CentOS 8.3 流水线示例
    11. CentOS 8.4 流水线示例
    12. CentOS 8.5 流水线示例
    13. Anolis 7.7 流水线示例
    14. Anolis 7.9 流水线示例
    15. Anolis 8.2 流水线示例
    16. Anolis 8.4 流水线示例
    17. Anolis 8.6 流水线示例
    18. Anolis 8.8 流水线示例
    19. Anolis 23 流水线示例
  2. 支持 UOS 统信 系统主流版本,详情见:https://framagit.org/xuxiaowei-com-cn/k8s.sh/-/issues/26
    1. UOS 20-1060e 流水线示例
  3. 支持 openEuler 欧拉 系统主流版本,详情见:https://framagit.org/xuxiaowei-com-cn/k8s.sh/-/issues/24
    1. openEuler 23.03
  4. 支持 Ubuntu 乌班图 系统主流版本,详情见:https://framagit.org/xuxiaowei-com-cn/k8s.sh/-/issues/21
    1. Ubuntu 20.04 Focal Fossa
    2. Ubuntu 22.10 Kinetic Kudu
    3. Ubuntu 23.04 Lunar Lobster 流水线示例
  5. 支持 openKylin 开放麒麟 系统主流版本,详情见:https://framagit.org/xuxiaowei-com-cn/k8s.sh/-/issues/25
    1. openKylin 1.0 流水线示例
  6. 一键支持 自定义 Kubernetes(k8s)、Calico 版本
  7. 一键支持 单机集群
  8. 一键支持 一主多从
  9. 一键支持 高可用
  10. 自动安装、配置 Docker、Containerd
  11. 自动安装、配置 Kubernetes(k8s)
  12. 自动安装、配置 Calico 网络插件
  13. 自动安装、配置 kubectl 命令自动补充
  14. 自动安装、配置 VIP(Virtual IP Address,虚拟 IP 地址)

个人服务器配置

参数说明

镜像参数 说明 原始镜像 加速镜像使用示例 作者个人镜像
calico-mirrors calico 网络组件加速镜像(注意此处有 s,控制多个镜像,不控制镜像名称、不控制版本号),自定义版本见 calico-version 包含 docker.io/calico/cni、docker.io/calico/kube-controllers、docker.io/calico/kube-controllers calico-mirrors=hub-mirror.c.163.com calico-mirrors=registry.jihulab.com/xuxiaowei-jihu/xuxiaowei-cloud/spring-cloud-xuxiaowei
keepalived-mirror keepalived 镜像,只控制镜像名称、不控制版本号 lettore/keepalived keepalived-mirror=hub-mirror.c.163.com/lettore/keepalived keepalived-mirror=registry.jihulab.com/xuxiaowei-jihu/xuxiaowei-cloud/spring-cloud-xuxiaowei/lettore/keepalived
haproxy-mirror haproxy 镜像,只控制镜像名称、不控制版本号 haproxytech/haproxy-debian haproxy-mirror=hub-mirror.c.163.com/haproxytech/haproxy-debian haproxy-mirror=registry.jihulab.com/xuxiaowei-jihu/xuxiaowei-cloud/spring-cloud-xuxiaowei/haproxytech/haproxy-debian
metrics-server-mirror metrics-server 镜像,只控制镜像名称、不控制版本号,默认使用阿里云镜像 registry.k8s.io/metrics-server/metrics-server metrics-server-mirror=registry.aliyuncs.com/google_containers/metrics-server metrics-server-mirror=registry.jihulab.com/xuxiaowei-jihu/xuxiaowei-cloud/spring-cloud-xuxiaowei/metrics-server/metrics-server
安装/配置参数 说明 默认值 使用示例
ntp-install-skip 跳过 NTP 安装 false ntp-install-skip
ca-certificates-install-skip 跳过 ca-certificates 安装 false ca-certificates-install-skip
bash-completion-install-skip 跳过 bash-completion 安装 false bash-completion-install-skip
selinux-permissive-skip 跳过 关闭 selinux false selinux-permissive-skip
firewalld-stop-skip 跳过 关闭 防火墙 firewalld false firewalld-stop-skip
swap-off-skip 跳过 关闭 交换空间 swap false swap-off-skip
docker-repo-type docker 仓库类型,可使用:空(官方,默认)、aliyun(阿里云)、tencent(腾讯云) docker-repo-type=aliyun
docker-repo-skip 跳过 添加 docker 仓库 false docker-repo-skip
docker-ce-install-skip 跳过 docker-ce 安装 false docker-ce-install-skip
containerd-install-skip 跳过 containerd 安装 false containerd-install-skip
kernel-required-skip 跳过 内核 kernel 需求检查 false kernel-required-skip
kubernetes-repo-skip 跳过 添加 kubernetes 仓库 false kubernetes-repo-skip
kubernetes-conf-skip 跳过 kubernetes 配置 false kubernetes-conf-skip
kubernetes-install-skip 跳过 kubernetes 安装 false kubernetes-install-skip
kubernetes-init-skip 跳过 kubernetes 初始化 false kubernetes-init-skip
kubernetes-taint 指定 kubernetes 全部去污 false kubernetes-taint
kubernetes-version 指定 kubernetes 固定版本:包含:主版本号、次版本号、修正版本号,如:1.30.0,请与 kubernetes-repo-new-version 保持在同一个 主版本包 和 次版本号 下 最新版 kubernetes-version=1.30.0
kubernetes-repo-new-version 指定 kubernetes 新版仓库版本,仅包含:主版本号、次版本号,例如:1.24、1.25、1.26、1.27、1.28、1.29、1.30,默认值:1.30 kubernetes-repo-new-version=1.30
kubernetes-images-pull 拉取 kubernetes 镜像(在初始化前提前拉取) false kubernetes-images-pull
kubernetes-init-v 查看 kubernetes 堆栈跟踪,设置日志等级,同 kubeadm init --v= kubernetes-init-v=5
apiserver-advertise-address API 服务器所公布的其正在监听的 IP 地址。如果未设置,则使用默认网络接口。 如果未设置,则使用默认网络接口 apiserver-advertise-address=192.168.61.147
apiserver-bind-port API 服务器绑定的端口。默认值:6443 6443 apiserver-bind-port=6443
node-name 指定节点的名称 服务器主机名 node-name=k8s-1
service-cidr 为服务(Service)的虚拟 IP 地址另外指定 IP 地址段。注意:请勿与现实网络存在冲突 10.96.0.0/12(即:10.96.0.0-10.111.255.255,共 1048576 个IP) service-cidr=10.96.0.0/12
pod-network-cidr 指明 Pod 网络可以使用的 IP 地址段。如果设置了这个参数,控制平面将会为每一个节点自动分配 CIDR。注意:请勿与现实网络存在冲突 192.168.0.0/16(calico 默认配置) pod-network-cidr=10.128.0.0/12 (即:10.128.0.0-10.143.255.255,共 1048576 个IP)
calico-init-skip 跳过 calico 初始化 false calico-init-skip
calico-version 指定 calico 版本 3.27.3 calico-version=3.27.3
calico-manifests-mirror 自定义 calico 配置文件,优先级高于 calico-version 从 官网 中获取 calico-manifests-mirror=https://jihulab.com/xuxiaowei-jihu/mirrors-github/projectcalico/calico/-/raw/v3.27.3/manifests/calico.yaml
interface-name 指定 网卡 名称 自动获取 interface-name=ens33
metrics-server-install 启用 Metrics Server 安装 false metrics-server-install
metrics-server-version 指定 Metrics Server 版本 0.6.3 metrics-server-version=0.7.1
metrics-server-availability 指定 Metrics Server 使用高可用 false metrics-server-availability
metrics-server-manifests-mirror 自定义 Metrics Server 配置文件,优先级高于 metrics-server-version、metrics-server-availability 从 GitHub 中获取 metrics-server-manifests-mirror=https://jihulab.com/xuxiaowei-jihu/xuxiaowei-com-cn/k8s.sh/-/raw/main/mirrors/kubernetes-sigs/metrics-server/v0.7.1/components.yaml
ingress-nginx-install 启用 Ingress Nginx 安装 false ingress-nginx-install
ingress-nginx-version 指定 Ingress Nginx 版本 1.10.0 ingress-nginx-version=1.10.0
ingress-nginx-controller-mirror 自定义镜像,用于替换国内不可访问的 registry.k8s.io/ingress-nginx/controller 镜像,支持 Ingress Nginx 1.8.0/1.8.1/1.8.2/1.8.4/1.8.5/1.9.0/1.9.1/1.9.3/1.9.4/1.9.5/1.9.6/1.10.0 版本的镜像加速下载 xuxiaoweicomcn/ingress-nginx-controller ingress-nginx-controller-mirror=registry.jihulab.com/xuxiaowei-jihu/xuxiaowei-cloud/spring-cloud-xuxiaowei/ingress-nginx/controller
ingress-nginx-kube-webhook-certgen-mirror 自定义镜像,用于替换国内不可访问的 registry.k8s.io/ingress-nginx/kube-webhook-certgen 镜像,支持 Ingress Nginx 1.8.0/1.8.1/1.8.2/1.8.4/1.8.5/1.9.0/1.9.1/1.9.3/1.9.4/1.9.5/1.9.6/1.10.0 版本的镜像加速下载 xuxiaoweicomcn/ingress-nginx-kube-webhook-certgen ingress-nginx-kube-webhook-certgen-mirror=registry.jihulab.com/xuxiaowei-jihu/xuxiaowei-cloud/spring-cloud-xuxiaowei/ingress-nginx/kube-webhook-certgen
ingress-nginx-host-network 配置 Ingress Nginx 为 hostNetwork false ingress-nginx-host-network
availability-vip-install 开启高可用 VIP 安装 false availability-vip-install
availability-vip 高可用 VIP 地址(Virtual IP Address,虚拟 IP 地址) availability-vip=192.168.80.100
availability-vip-no 高可用 VIP 编号,整数数字类型,其中 1 代表主,其余为备用,不可重复,创建 VIP 时必填,VIP 节点中必须存在一个 1 availability-vip-no=1
availability-master 高可用 主节点配置,包含主节点名称(仅在VIP管理时使用)、主节点IP、主节点端口,创建 VIP 时必填,格式:名称@ip:端口,使用多次指定设置多个值 availability-master=k8s-master1@192.168.80.81:6443 availability-master=k8s-master2@192.168.80.82:6443 availability-master=k8s-master3@192.168.80.83:6443
uos-slirp4netns-mirror UOS 统信 安装 slirp4netns 的镜像链接(UOS 统信 默认仓库不存在 slirp4netns 软件。如果默认链接不存在了,请访问 https://mirrors.aliyun.com/centos/8.5.2111/AppStream/x86_64/os/Packages/ 搜索 slirp4netns 即可) https://mirrors.aliyun.com/centos/8.5.2111/AppStream/x86_64/os/Packages/slirp4netns-0.4.2-3.git21fdece.module_el8.5.0+1004+c00a74f5.x86_64.rpm uos-slirp4netns-mirror=https://mirrors.aliyun.com/centos/8.5.2111/AppStream/x86_64/os/Packages/slirp4netns-0.4.2-3.git21fdece.module_el8.5.0+1004+c00a74f5.x86_64.rpm
uos-fuse-overlayfs-mirror UOS 统信 安装 fuse-overlayfs 的镜像链接(UOS 统信 默认仓库不存在 fuse-overlayfs 软件。如果默认链接不存在了,请访问 https://mirrors.aliyun.com/centos/8.5.2111/AppStream/x86_64/os/Packages/ 搜索 fuse-overlayfs 即可) https://mirrors.aliyun.com/centos/8.5.2111/AppStream/x86_64/os/Packages/fuse-overlayfs-0.7.8-1.module_el8.5.0+1004+c00a74f5.x86_64.rpm uos-fuse-overlayfs-mirror=https://mirrors.aliyun.com/centos/8.5.2111/AppStream/x86_64/os/Packages/fuse-overlayfs-0.7.8-1.module_el8.5.0+1004+c00a74f5.x86_64.rpm

使用前说明

  1. 请务必使用独立系统执行脚本。
  2. 请务必使用独立系统执行脚本。
  3. 请务必使用独立系统执行脚本。
  4. k8s 各节点主机名唯一,不能存在相同的。推荐主节点使用 k8s-xx 或者 control-plane-xx,工作节点 node-xx
  5. k8s 主机名:必须符合小写的 RFC 1123 子域,必须由小写字母数字字符“-”或“.”组成,并且必须以字母数字字符开头和结尾
  6. 由于某些软件基于主机名才能正常运行,为了避免风险,脚本不支持修改主机名,请自行修改
  7. 命令 hostname 为临时修改主机名,配置文件 /etc/hostname 为配置文件中的主机名,服务器重启后,会 hostname 配置的主机名会消失,恢复成 /etc/hostname 中的主机名
  8. 集群主节点初始化错误、集群工作节点加入集群错误,请使用 kubeadm reset 重置节点的配置,并根据提示手动删除 $HOME/.kube/config/etc/cni/net.d 文件(夹)等
  9. 安装配置过程将关闭防火墙,推荐使用独立机器部署 k8s
  10. 如果 k8s 宿主机有多个网卡,请自行指定网卡名称
  11. 安装时,会卸载 老版 Docker(非 旧版 Docker),安装最新版 Docker、Containerd,修改 Docker、Containerd 配置文件,重启 Docker、Containerd
    1. 卸载软件如下
      1. docker
      2. docker-client
      3. docker-client-latest
      4. docker-common
      5. docker-latest
      6. docker-latest-logrotate
      7. docker-logrotate
      8. docker-engine
    2. 安装软件如下
      1. docker-ce
      2. docker-ce-cli
      3. containerd.io
      4. docker-buildx-plugin
      5. docker-compose-plugin
    3. 修改配置如下
      1. /etc/docker/daemon.json
      2. /etc/containerd/config.toml

使用说明

  1. k8s 单节点安装(只有一个主节点,无高可用,仅用于学习、测试)

    # 下载脚本,下载后的文件名为 k8s.sh
    curl -o k8s.sh https://gitee.com/xuxiaowei-com-cn/k8s.sh/raw/SNAPSHOT/0.4.0/k8s.sh
    # 授权
    chmod +x k8s.sh
    # 执行安装命令
    sudo ./k8s.sh kubernetes-taint
    
    # 安装 ingress nginx
    # sudo ./k8s.sh kubernetes-taint ingress-nginx-install ingress-nginx-host-network
  2. k8s 单节点安装(只有一个主节点,无高可用,仅用于学习、测试),使用 k8s 指定版本

    # 下载脚本,下载后的文件名为 k8s.sh
    curl -o k8s.sh https://gitee.com/xuxiaowei-com-cn/k8s.sh/raw/SNAPSHOT/0.4.0/k8s.sh
    # 授权
    chmod +x k8s.sh
    # 执行安装命令
    # 指定 k8s 版本号(版本号不带字母)
    # 在 GitHub 查看 k8s 发布的版本:https://github.com/kubernetes/kubernetes/tags
    # 在 JiHuLab 查看 k8s 发布的版本(作者个人镜像):https://framagit.org/mirrors-github/kubernetes/kubernetes/-/tags
    sudo ./k8s.sh kubernetes-taint kubernetes-version=
    
    # 安装 ingress nginx
    # sudo ./k8s.sh kubernetes-taint kubernetes-version= ingress-nginx-install ingress-nginx-host-network
  3. k8s 单节点安装(只有一个主节点,无高可用,仅用于学习、测试),不安装 docker-ce(k8s 使用 containerd)

    # 下载脚本,下载后的文件名为 k8s.sh
    curl -o k8s.sh https://gitee.com/xuxiaowei-com-cn/k8s.sh/raw/SNAPSHOT/0.4.0/k8s.sh
    # 授权
    chmod +x k8s.sh
    # 执行安装命令
    sudo ./k8s.sh kubernetes-taint docker-ce-install-skip
    
    # 安装 ingress nginx
    # sudo ./k8s.sh kubernetes-taint docker-ce-install-skip ingress-nginx-install ingress-nginx-host-network
  4. k8s 单节点安装(只有一个主节点,无高可用,仅用于学习、测试),仅安装,不进行初始化

    # 下载脚本,下载后的文件名为 k8s.sh
    curl -o k8s.sh https://gitee.com/xuxiaowei-com-cn/k8s.sh/raw/SNAPSHOT/0.4.0/k8s.sh
    # 授权
    chmod +x k8s.sh
    # 执行安装命令,仅安装,不进行初始化
    sudo ./k8s.sh kubernetes-taint kubernetes-init-skip calico-init-skip
  5. k8s 单节点安装(只有一个主节点,无高可用,仅用于学习、测试),仅安装、拉取镜像,不进行初始化

    # 下载脚本,下载后的文件名为 k8s.sh
    curl -o k8s.sh https://gitee.com/xuxiaowei-com-cn/k8s.sh/raw/SNAPSHOT/0.4.0/k8s.sh
    # 授权
    chmod +x k8s.sh
    # 执行安装命令,仅安装、拉取镜像,不进行初始化
    sudo ./k8s.sh kubernetes-taint kubernetes-init-skip calico-init-skip kubernetes-images-pull
  6. k8s 单节点安装(只有一个主节点,无高可用,仅用于学习、测试),使用 calico 指定版本

    # 下载脚本,下载后的文件名为 k8s.sh
    curl -o k8s.sh https://gitee.com/xuxiaowei-com-cn/k8s.sh/raw/SNAPSHOT/0.4.0/k8s.sh
    # 授权
    chmod +x k8s.sh
    # 执行安装命令
    # 指定 calico 版本号(版本号不带字母)
    # 查看 calico 发布的版本:https://docs.tigera.io/archive/
    # 查看 calico 发布的版本(作者 JiHuLab 镜像):https://jihulab.com/xuxiaowei-jihu/mirrors-github/projectcalico/calico/-/tags
    sudo ./k8s.sh kubernetes-taint calico-version=3.27.3 
  7. k8s 单节点安装(只有一个主节点,无高可用,仅用于学习、测试),使用 calico 网络组件的加速镜像

    # calico 网络组件:使用网易云 calico-mirrors=hub-mirror.c.163.com
    # 如果自己有镜像,也可使用自己的镜像
    # 作者个人镜像仓库:calico-mirrors=registry.jihulab.com/xuxiaowei-jihu/xuxiaowei-cloud/spring-cloud-xuxiaowei
    
    # 下载脚本,下载后的文件名为 k8s.sh
    curl -o k8s.sh https://gitee.com/xuxiaowei-com-cn/k8s.sh/raw/SNAPSHOT/0.4.0/k8s.sh
    # 授权
    chmod +x k8s.sh
    # 执行安装命令
    sudo ./k8s.sh kubernetes-taint calico-mirrors=hub-mirror.c.163.com
  8. k8s 单节点安装(只有一个主节点,无高可用,仅用于学习、测试),安装 Metrics Server 插件

    # 下载脚本,下载后的文件名为 k8s.sh
    curl -o k8s.sh https://gitee.com/xuxiaowei-com-cn/k8s.sh/raw/SNAPSHOT/0.4.0/k8s.sh
    # 授权
    chmod +x k8s.sh
    # 执行安装命令
    sudo ./k8s.sh kubernetes-taint metrics-server-install
    
    # 执行安装命令:自定义版本
    # sudo ./k8s.sh kubernetes-taint metrics-server-install metrics-server-version=0.7.1
    
    # 执行安装命令:使用高可用
    # sudo ./k8s.sh kubernetes-taint metrics-server-install metrics-server-availability
    
    # 执行安装命令:自定义版本、使用高可用
    # sudo ./k8s.sh kubernetes-taint metrics-server-install metrics-server-version=0.7.1 metrics-server-availability
    
    # 执行安装命令:自定义下载配置文件(优先级高于 metrics-server-version、metrics-server-availability,可指定高可用)
    # sudo ./k8s.sh kubernetes-taint metrics-server-install metrics-server-manifests-mirror=https://jihulab.com/xuxiaowei-jihu/xuxiaowei-com-cn/k8s.sh/-/raw/main/mirrors/kubernetes-sigs/metrics-server/v0.6.3/components.yaml
  9. k8s 集群(一主多从,无高可用,仅用于学习、测试)

    1. 主节点:安装软件、初始化集群

      # 下载脚本,下载后的文件名为 k8s.sh
      curl -o k8s.sh https://gitee.com/xuxiaowei-com-cn/k8s.sh/raw/SNAPSHOT/0.4.0/k8s.sh
      # 授权
      chmod +x k8s.sh
      # 执行安装命令
      sudo ./k8s.sh
      
      # 安装 ingress nginx
      # sudo ./k8s.sh ingress-nginx-install ingress-nginx-host-network
      
      # 暂存初始化完成后控制台打印的工作节点加入集群的命令,例如:
      # kubeadm join 192.168.61.147:6443 --token ykrnfh.i4qwth17fopc0gtx \
      # --discovery-token-ca-cert-hash sha256:9e81fa0b04a57517feb1c9e34edc0aa6563b64db54887fc072a08d7d1235861d
      
      
      # 也可使用命令在主节点生成工作节点加入集群的命令:kubeadm token create --print-join-command
      
      
    2. 工作节点:安装软件、加入集群

      # 下载脚本,下载后的文件名为 k8s.sh
      curl -o k8s.sh https://gitee.com/xuxiaowei-com-cn/k8s.sh/raw/SNAPSHOT/0.4.0/k8s.sh
      # 授权
      chmod +x k8s.sh
      # 执行安装命令,仅安装、拉取镜像,不进行初始化
      sudo ./k8s.sh kubernetes-init-skip calico-init-skip
      
      
      # 执行在主节点得到的工作加入集群的命令,例如:
      # kubeadm join 192.168.61.147:6443 --token ykrnfh.i4qwth17fopc0gtx --discovery-token-ca-cert-hash sha256:9e81fa0b04a57517feb1c9e34edc0aa6563b64db54887fc072a08d7d1235861d
      
      # 可使用 kubeadm token create --print-join-command 创建工作节点加入集群的命令
      
  10. k8s 集群(三主多从,高可用,生产就绪)

    1. VIP(Virtual IP Address,虚拟 IP 地址)

      VIP 至少需要部署3台机器,可与主节点使用相同的机器

      # 下载脚本,下载后的文件名为 k8s.sh
      curl -o k8s.sh https://gitee.com/xuxiaowei-com-cn/k8s.sh/raw/SNAPSHOT/0.4.0/k8s.sh
      # 授权
      chmod +x k8s.sh
      
      # 第 1 个 VIP 宿主机:执行安装命令(与其他 VIP 命令中的 availability-vip-no 不同,必须存在一个值为 1)
      sudo ./k8s.sh availability-vip-install \
        availability-vip=192.168.80.100 \
        interface-name=ens33 \
        availability-master=k8s-master1@192.168.80.81:6443 \
        availability-master=k8s-master2@192.168.80.82:6443 \
        availability-master=k8s-master3@192.168.80.83:6443 \
        availability-vip-no=1
      
      # 第 2 个 VIP 宿主机:执行安装命令(与其他 VIP 命令中的 availability-vip-no 不同,必须存在一个值为 1)
      sudo ./k8s.sh availability-vip-install \
        availability-vip=192.168.80.100 \
        interface-name=ens33 \
        availability-master=k8s-master1@192.168.80.81:6443 \
        availability-master=k8s-master2@192.168.80.82:6443 \
        availability-master=k8s-master3@192.168.80.83:6443 \
        availability-vip-no=2
      
      # 第 3 个 VIP 宿主机:执行安装命令(与其他 VIP 命令中的 availability-vip-no 不同,必须存在一个值为 1)
      sudo ./k8s.sh availability-vip-install \
        availability-vip=192.168.80.100 \
        interface-name=ens33 \
        availability-master=k8s-master1@192.168.80.81:6443 \
        availability-master=k8s-master2@192.168.80.82:6443 \
        availability-master=k8s-master3@192.168.80.83:6443 \
        availability-vip-no=3
    2. 主节点:第一台机器:安装软件、初始化集群

      # 下载脚本,下载后的文件名为 k8s.sh
      curl -o k8s.sh https://gitee.com/xuxiaowei-com-cn/k8s.sh/raw/SNAPSHOT/0.4.0/k8s.sh
      # 授权
      chmod +x k8s.sh
      
      # 安装 ingress nginx
      # sudo ./k8s.sh ingress-nginx-install ingress-nginx-host-network
      
      # 指定 VIP 进行 k8s 集群 第一个主节点 初始化
      sudo ./k8s.sh availability-vip=192.168.80.100
      
      # 安装 Metrics Server 插件(仅第一个主节点执行即可)
      # sudo ./k8s.sh availability-vip=192.168.80.100 metrics-server-install metrics-server-availability
    3. 主节点:其余机器:安装软件、使用主节点角色加入集群

      # 下载脚本,下载后的文件名为 k8s.sh
      curl -o k8s.sh https://gitee.com/xuxiaowei-com-cn/k8s.sh/raw/SNAPSHOT/0.4.0/k8s.sh
      # 授权
      chmod +x k8s.sh
      
      # 执行安装命令,仅安装,不进行初始化
      sudo ./k8s.sh kubernetes-init-skip calico-init-skip
      
      # 运行 k8s 集群 第一个主节点 初始化完成后 使用主节点角色加入集群的命令,例如:
      # kubeadm join 192.168.80.100:9443 --token ykrnfh.i4qwth17fopc0gtx \
      #   --discovery-token-ca-cert-hash sha256:9e81fa0b04a57517feb1c9e34edc0aa6563b64db54887fc072a08d7d1235861d \
      #   --control-plane --certificate-key 7c3cb3aaedcadfc636b7d476e3fb564a0985eadffe68e9e74c21bab38f007479
      
      # 也可以在已正常运行的主节点运行下列命令后,将结果拼接成上方示例
      # kubeadm token create --print-join-command
      # kubeadm init phase upload-certs --upload-certs
      
      # 添加环境变量
      sudo bash -c "echo 'export KUBECONFIG=/etc/kubernetes/admin.conf' >> /etc/profile"
      # 刷新环境变量
      source /etc/profile
      
      # 命令自动补充
      kubectl completion bash | sudo tee /etc/bash_completion.d/kubectl >/dev/null
      sudo chmod a+r /etc/bash_completion.d/kubectl
      source ~/.bashrc
      
      # 等待 pod 就绪
      kubectl wait --for=condition=Ready --all pods --all-namespaces --timeout=600s
      
    4. 工作节点:安装软件、使用工作节点角色加入集群

      工作节点 至少需要部署2台机器(请保证单个工作节点的资源可以负载所有任务,否则请增加工作节点)

      每个工作节点执行的命令相同

      # 下载脚本,下载后的文件名为 k8s.sh
      curl -o k8s.sh https://gitee.com/xuxiaowei-com-cn/k8s.sh/raw/SNAPSHOT/0.4.0/k8s.sh
      # 授权
      chmod +x k8s.sh
      
      # 执行安装命令,仅安装,不进行初始化
      sudo ./k8s.sh kubernetes-init-skip calico-init-skip
      
      # 执行在主节点得到的工作加入集群的命令,例如:
      # kubeadm join 192.168.80.100:9443 --token ykrnfh.i4qwth17fopc0gtx --discovery-token-ca-cert-hash sha256:9e81fa0b04a57517feb1c9e34edc0aa6563b64db54887fc072a08d7d1235861d
      
      # 可使用 kubeadm token create --print-join-command 创建工作节点加入集群的命令
      

常见问题

  1. ImagePullBackOff:Docker 镜像拉取失败,解决办法如下:

    1. 等待 k8s 自己重试(时间较久)
    2. 删除 pod,删除后,k8s 会根据需求,选择性创建 Pod(不懂时慎用)
      1. kube-system 命名空间的,都会自动创建

      2. 属于 Deployment 的 pod,都会自动创建

      3. 命令

        kubectl -n 命名空间 delete pod Pod的名称
    3. 如果根据上方尝试很多次,都拉取不下来,请自行拉取镜像并导入到 k8s 中,代码可参考
      1. Docker Images 迁移
  2. 高可用主节点总数量与可用数量

    1. 主节点总数量推荐奇数个
    2. 主节点可用数量需要大于总数量的一半,集群才能正常运行
      1. 假设1:存在三个主节点,宕机一个主节点后可正常运行,宕机两个主节点后不可正常运行
      2. 假设2:存在四个主节点,宕机一个主节点后可正常运行,宕机两个主节点后不可正常运行
      3. 假设3:存在五个主节点,宕机一个主节点后可正常运行,宕机两个主节点后可正常运行,宕机三个主节点后不可正常运行
  3. 如果考虑使用高可用,但是当前机器数量不满足要求,如何进行配置?

  • 假设现在只有一台机器,现在需要安装和使用 k8s,一台机器不满足高可用的配置要求。三个月后,才能新增几台机器,三个月后后能满足高可用的要求,现在怎么安装?

    • 方案1(不推荐):先在现有机器上安装单节点版。新增机器后,将原有机器中的 k8s 重置(k8s 数据会丢失),重新安装 k8s 高可用集群。

    • 方案2(不推荐):新增机器后,在新机器中安装 k8s 高可用集群,原有机器中的 k8s 单节点版保留,同时保留两个 k8s(管理困难,数据孤岛,资源孤岛)。

    • 方案3(推荐):先在现有机器上,安装 伪高可用 k8s 集群,实际上是单节点安装。新增机器后,无缝拓展为真正的高可用。

      1. 只有一台机器时
        1. 在这台机器上创建 VIP
        2. 使用 VIP 创建 k8s 主节点
        3. 主节点去污后,正常使用单机资源
      2. 新增机器后
        1. 修改以前机器上的 VIP 配置,增加主节点配置
        2. 在新机器上创建 VIP(增加主节点后的配置)
        3. 新增的主节点 使用 VIP 和 主节点角色 加入到集群中
        4. 新增的工作节点 使用 VIP 和 工作节点角色 加入到集群中

各分支的作用

  • main
    1. 主分支,安装脚本以此分支为准
  • SNAPSHOT/*.*.*
    1. 快照分支
  • images-mirrors/*.*.*-0
    1. docker 镜像加速计划,镜像地址:https://jihulab.com/xuxiaowei-cloud/xuxiaowei-cloud/container_registry
    2. docker 镜像离线安装计划:可在 流水线 产物中,下载所需 Docker 镜像文件
    3. 有效期默认 30 天,可重试 流水线 重新生成
    4. 可自行 fork 本项目,修改配置,生成自己所需 Docker 镜像文件
    5. 可创建议题、PR,生成所需 Docker 镜像文件
  • yum/*.*.*-0
    1. yum 离线安装计划:可在 流水线 产物中,下载所需安装 k8s、docker 等相关软件的 yum 离线安装包
    2. 有效期默认 30 天,可重试 流水线 重新生成
    3. 可自行 fork 本项目,修改配置,生成自己所需安装 k8s、docker 等相关软件的 yum 离线安装包
    4. 可创建议题、PR,生成所需 yum 离线安装包
  • xuxiaowei/*
    1. 个人分支
  • test/machine/centos-*/*
    1. 在实体机器测试的分支
    2. centos:代表测试 CentOS 系统
    3. 第一个 *:代表 CentOS 版本
    4. 第二个 *:代表 k8s 的版本,latest 代表最新版
  • test/*.*.*
    1. 测试固定版本分支
Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

About

Kubernetes(k8s)自动安装配置脚本 expand collapse
Shell
Apache-2.0
Cancel

Releases

No release

Contributors

All

Activities

Load More
can not load any more
Shell
1
https://gitee.com/xuxiaowei-com-cn/k8s.sh.git
git@gitee.com:xuxiaowei-com-cn/k8s.sh.git
xuxiaowei-com-cn
k8s.sh
k8s.sh
SNAPSHOT/0.4.0

Search

53164aa7 5694891 3bd8fe86 5694891