ansible部署kubernetes(1.30)

Ubuntu 20.04下kubeasz 3.6.4一键部署K8s 1.30.1高可用集群(含Ansible配置详解) 本文详细介绍了在Ubuntu 20.04系统上,使用kubeasz 3.6.4工具一键自动化部署Kubernetes 1.30.1高可用集群的完整实战流程。内容涵盖Ansible配置详解、环境准备、核心配置文件定制、部署执行与验证,以及高可用访问配置和常见故障排查,旨在帮助运维人员快速构建稳定可靠的生产级K8s集群。 阅读详情

ansible部署kubernetes(1.30)

  • 操作系统使用的是ubuntu 24.04,ansible使用rocky9.2

1.规划

节点角色配置地址domain name备注
master-012c,2g10.10.50.11k8s.master01.example.com
node-012c,10g10.10.50.14k8s.node01.example.com
node-022c,10g10.10.50.15k8s.node02.example.com
node-032c,10g10.10.50.16k8s.node03.example.com

2.ssh免密配置

$ ssh-keygen -t ed25519
$ ssh-copy-id root@10.10.50.11
$ ssh-copy-id root@10.10.50.14
$ ssh-copy-id root@10.10.50.15
$ ssh-copy-id root@10.10.50.16

$ sudo sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/g' /etc/ssh/sshd_config \
&& sudo sed -i 's/#PubkeyAuthentication yes/PubkeyAuthentication yes/g' /etc/ssh/sshd_config \
&& sudo sed -i 's/#PasswordAuthentication yes/PasswordAuthentication no/g' /etc/ssh/sshd_config \
&& rm -rf /etc/ssh/sshd_config.d/50-cloud-init.conf \
&& sudo systemctl restart sshd

3.ansible部署

#下面环境使用的是rocky9.2的系统
# step1:安装
$ yum -y install ansible-core.x86_64

# step2:配置ansible配置文件
$ vim /etc/ansible/ansible.cfg 
[defaults]
inventory=/etc/ansible/hosts
roles_path=/etc/ansible/roles
host_key_checking=False

[privilege_escalation]
become=True
become_method=sudo
become_user=root
become_ask_pass=False

# step3:使用key认证,最好使用fqdn,因为这样后续部署别的集群只需要修改hosts解析记录即可
$ vim /etc/ansible/hosts
[master]
k8s-master01

[node]
k8s-node01
k8s-node02
k8s-node03

# step4:测试
$ ansible all -m ping					

4.系统配置

# step2:主机名配置
ansible master-01 -m hostname -a "name=k8s-master01.leepongmin.com"
ansible node-01 -m hostname -a "name=k8s-node01.leepongmin.com"
ansible node-02 -m hostname -a "name=k8s-node02.leepongmin.com"
ansible node-03 -m hostname -a "name=k8s-node03.leepongmin.com"

# step3:主机名解析配置
$ ansible all -m shell -a "cat <<eof>> /etc/hosts
10.10.50.11 k8s-master01.example.com master-01
10.10.50.14 k8s-node01.example.com node-01
10.10.50.15 k8s-node02.example.com node-02
10.10.50.16 k8s-node03.example.com node-03
eof"

# 4.系统仓库配置
$ ansible all -m shell -a 'cat <<eof> /etc/apt/sources.list
deb https://mirrors.aliyun.com/ubuntu/ noble main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ noble main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ noble-security main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ noble-security main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ noble-updates main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ noble-updates main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ noble-backports main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ noble-backports main restricted universe multiverse
eof'
$ ansible all -m shell -a 'apt clean all && apt update'

5.ntp配置

$ vim chrony-install.yaml
---
- name: Install and configure Chrony
  hosts: all
  tasks:
    - name: Install Chrony
      apt:
        name: chrony
        state: present
      when: ansible_os_family == "Debian"
    - name: Install Chrony
      yum:
        name: chrony
        state: present
      when: ansible_os_family == "RedHat"
    - name: Configure Chrony NTP servers
      copy:
        dest: /etc/chrony/chrony.conf
        content: |
          server ntp.aliyun.com iburst
    - name: Restart Chrony service
      systemd:
        name: chronyd
        state: restarted
        enabled: yes
    - name: Set the timezone using timedatectl
      command: timedatectl set-timezone Asia/Shanghai

$ ansible-ploybook chrony-install.yaml

6.禁用swap

$ ansible all -m shell -a "sed -ri 's/.*swap.*/#&/' /etc/fstab"
$ ansible all -m shell -a "swapoff -a"

7.配置内核信息

# 1.加载模块
$ ansible all -m shell -a "cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
overlay
br_netfilter
EOF"
		
# 2.设置内核参数
$ ansible all -m shell -a "cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-iptables  = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.ipv4.ip_forward                 = 1
EOF"
$ ansible all -m shell -a "sysctl --system"
		
# 3.资源优化
$ ansible all -m shell -a "cat >>/etc/security/limits.conf <<EOF
* soft nofile 65536
* hard nofile 131072
* soft nproc 65535
* hard nproc 655350
* soft memlock unlimited
* hard memlock unlimited
EOF"

8.ipvs配置

$ ansible all -m shell -a "sudo apt install -y ipset ipvsadm"
		
# 1.加载模块
$ ansible all -m shell -a "sudo tee /etc/modules-load.d/ipvs.conf << EOF
overlay
br_netfilter
modprobe -- ip_vs
modprobe -- ip_vs_rr
modprobe -- ip_vs_wrr
modprobe -- ip_vs_sh
modprobe -- nf_conntrack
EOF"
$ ansible all -m shell -a "systemctl restart systemd-modules-load.service"

9.containerd

# step1:安装containerd
$ wget -P /opt https://github.com/containerd/containerd/releases/download/v1.7.17/containerd-1.7.17-linux-amd64.tar.gz
#这个在github下载很慢,因此将文件下载到ansible主机上之后拷贝到所有节点
$ vim copy-containerd.yaml
- hosts: all
  gather_facts: no
  tasks:
  - name: Synchronize files to remote host
    copy:
      src: /opt/containerd-1.7.17-linux-amd64.tar.gz
      dest: /opt/containerd-1.7.17-linux-amd64.tar.gz
$ ansible-playbook copy-containerd.yaml 

$ ansible all -m shell -a "tar xzf /opt/containerd-1.7.17-linux-amd64.tar.gz -C /usr/local/"
#$ ansible all -m shell -a "cp -r /opt/bin/* /usr/local/bin/
		
$ ansible all -m shell -a "cat > /lib/systemd/system/containerd.service << EOF
[Unit]
Description=containerd container runtime
Documentation=https://containerd.io
After=network.target local-fs.target
[Service]
ExecStartPre=-/sbin/modprobe overlay
ExecStart=/usr/local/bin/containerd
Type=notify
Delegate=yes
KillMode=process
Restart=always
RestartSec=5
LimitNPROC=infinity
LimitCORE=infinity
LimitNOFILE=infinity
TasksMax=infinity
OOMScoreAdjust=-999
[Install]
WantedBy=multi-user.target
EOF"

10.runc

$ wget -P /opt https://github.com/opencontainers/runc/releases/download/v1.1.12/runc.amd64
$ vim copy-runc.yaml
- hosts: all
  gather_facts: no
  tasks:
  - name: Synchronize files to remote host
    copy:
      src: /opt/runc.amd64
      dest: /usr/local/bin/runc
      mode: "0755"

# step3:创建配置文件
$ ansible all -m shell -a "mkdir -p /etc/containerd"
$ ansible all -m shell -a "containerd config default | tee /etc/containerd/config.toml"
		
# step4:修改底层容器地址,使用代理就不用修改
#$ vim modify-container.yaml
- hosts: all
  gather_facts: no
  tasks:
  - name: Execute bootstrapped shell command on remote host
    become: true
    shell: |
      sed -i 's|SystemdCgroup = false|SystemdCgroup = true|g' /etc/containerd/config.toml
      sed -ri -e 's@(.*sandbox_image = ).*@\1\"registry.aliyuncs.com/google_containers/pause:3.9\"@' /etc/containerd/config.toml
  - name: Reload the systemd daemon
    become: true
    command: systemctl daemon-reload
  - name: Restart the containerd service
    become: true
    systemd:
      name: containerd
      state: restarted

11.containerd proxy

$ vim containerd-proxy.yaml
- hosts: all
  gather_facts: no
  tasks:
  - name: http-proxy
    become: true
    shell: |
      sed -i '5a Environment=HTTP_PROXY="http://10.10.50.2:7890"' /lib/systemd/system/containerd.service
      sed -i '5a Environment=HTTPS_PROXY="http://10.10.50.2:7890"' /lib/systemd/system/containerd.service
      sed -i '5a Environment="NO_PROXY=localhost,127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,.svc,.cluster.local"' /lib/systemd/system/containerd.service
      
  - name: Reload the systemd daemon
    become: true
    command: systemctl daemon-reload
  - name: Restart the containerd service
    become: true
    systemd:
      name: containerd
      state: restarted
  - name: Reboot
    reboot:

12.kubeadm

$ ansible all -m shell -a "apt-get update && apt-get install -y apt-transport-https"
$ ansible all -m shell -a 'curl -fsSL https://mirrors.aliyun.com/kubernetes-new/core/stable/v1.30/deb/Release.key |
    gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
echo "deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://mirrors.aliyun.com/kubernetes-new/core/stable/v1.30/deb/ /" |
    tee /etc/apt/sources.list.d/kubernetes.list'
    
$ ansible all -m shell -a "apt-get update"
$ ansible all -m shell -a "apt-get install -y kubelet kubeadm kubectl"

13.init

$ kubeadm init --apiserver-advertise-address=10.10.50.11 --pod-network-cidr=10.100.0.0/16 --service-cidr=10.200.0.0/16 --token-ttl=0 --image-repository registry.aliyuncs.com/google_containers --upload-certs

14.calico deployment

$ wget https://raw.githubusercontent.com/projectcalico/calico/master/manifests/calico.yaml --no-check-certificate
$ vim calico.yaml
- name: CALICO_IPV4POOL_CIDR
  value: "10.100.0.0/16"
- name: CALICO_IPV4BLOCK_SIZE
  value: "24"
- name: CALICO_IPV4POOL_IPIP
  value: "Never"

15.test pod

apiVersion: v1
kind: Pod
metadata:
  name: mypod1
spec:
  nodeName: k8s-node01.example.com
  containers:
  - name: daemonapp1
    image: busybox
    command: ["sh","-c","sleep 3600"]
---
apiVersion: v1
kind: Pod
metadata:
  name: mypod2
spec:
  nodeName: k8s-node02.example.com
  containers:
  - name: daemonapp2
    image: busybox
    command: ["sh","-c","sleep 3600"]
---
apiVersion: v1
kind: Pod
metadata:
  name: mypod3
spec:
  nodeName: k8s-node03.example.com
  containers:
  - name: daemonapp3
    image: busybox
    command: ["sh","-c","sleep 3600"]

在这里插入图片描述

Ansible一键部署Kubernetes集群 修改主机名-->配置hosts解析-->配置秘钥互相通信(通过expect来发送指令)-->对时间进行同步-->关闭防火墙-->关闭swap分区-->关闭selinux-->iptables 检查桥接流量-->启用ipvs的所需模块。检查k8s是否安装安装好的话直接下一步,阿里云上找repo源然后进行安装,可以更改版本下面的版本,然后将准备好的镜像tar包进行导入就可以了。通过ssh命令获取主节点初始化后的node加入集群节点的命令在node节点上执行进行node节点加入集群。 阅读详情

相关推荐

Ansible AWX 部署于k8s集群

新版awx需要awx operator去搭建,官方建议使用minikube去部署awx operater,本人在公司测试环境机器中搭建,因为测试环境的网络代理问题,在搭建完minikube后,虚拟出的主机通过docker连接,若ssh后配置docker代理重启后会遇到集群损坏的问题,且minikube ssh后的主机配置很低,在外部也不好访问到内部的服务,诸多不易,最终选择用Kubeadm搭建一个单节点k8s集群,之后的节点扩容也比较方便。...

HiSiri的博客 6436

ansible-8.0在Rocky的安装和使用

Hosts:指定要在哪些主机上执行任务。可以是单个主机、一组主机或通过变量定义的动态主机列表。Tasks:包含一个或多个任务,每个任务定义了一个具体的操作,如安装软件包、复制文件、启动服务等。Variables:可以在 playbook 中定义变量,以便在任务中使用。变量可以通过多种方式定义,如在 playbook 中直接定义、从外部文件加载或通过命令行参数传递。Handlers:用于定义在特定条件下触发的任务。例如,当一个服务配置文件发生变化时,可以触发一个重新启动服务的 handler。

weixin_45251630的博客 1225

Kubernetes集群部署原理与实践:从零搭建生产级环境

本文从应用部署历史讲起,逐步深入到Kubernetes的架构精髓,并详细记录了一个基于私有镜像仓库、使用cri-dockerd的完整部署流程。通过手动操作,我们理解了各组件的关系;通过Ansible剧本,我们看到了工程化的可能性。Kubernetes的学习之路,既需要宏观的设计思维,也离不开扎实的动手实践。希望这篇博客能成为你探索云原生世界的一块坚实跳板。若你在部署中遇到问题,欢迎留言交流,我们共同进步。

sryyd_02的博客 340

运维自动化工具 Ansible的安装部署和常用模块介绍

ansible的安装有很多种方式下载pip下载。

清瞳清的博客 1204

Rocky9.2基于http方式搭建局域网yum源

Rocky9.2基于http方式搭建局域网yum源。

二进制高可用k8s集群一键部署脚本

根据阿良的二进制部署文档编写的,安装步骤请看readme.txt,给想学习k8s的小伙伴节省更多的搭建集群的时间,不懂的可以直接给我留言,欢迎大家一起讨论

ansible基本应用一(rockylinux8.6 mini install)

ansible基本应用一

w975121565的博客 605

PySide6 vs PyQt6:新手如何根据Python版本选择GUI库?附版本兼容性测试

本文针对Python GUI开发新手,详细对比了PySide6与PyQt6的核心差异,并提供了基于Python 3.8至3.12等不同版本的兼容性实测数据与选择建议。文章重点分析了版本选择策略,帮助开发者根据自身Python环境、项目需求(如与matplotlib集成)及许可证考量,做出最合适的决策,并附有安装验证与避坑指南。

weixin_29094539的博客 716

Rocky-epel源下载ansible包

1.配置本地源挂载 /dev/sr0 10464680 10464680 0 100% /media/Rocky 2.设置dns使其能够上网 [root@cs4 yum.repos.d]# ping www.baidu.com PING www.a.shifen.com (39.156.66.18) 56(84) bytes of data. 64 bytes from 39.156.66.18 (39.156.66.18): icmp_seq=1 ttl=

Jakobus的博客 1698

华为eNSP与VMware虚拟机联动实战:从零搭建仿真网络环境

本文详细介绍了如何从零开始搭建华为eNSP与VMware虚拟机的联动仿真网络环境。通过环境准备、网络适配器配置、eNSP与VMware网络集成、安全策略与NAT配置等步骤,帮助读者掌握构建企业级网络实验场景的关键技术。这种组合特别适合网络工程师进阶训练和华为认证考试准备,实现低成本、高灵活性的网络仿真实验。

weixin_30415113的博客 509

TESSY创建单元测试或集成测试工程

我们以tessy5.1为例,给大家展示单元测试和集成测试工程的创建过程。

空气中的告白专栏 1697

kubeasz 部署k8s1.30.1集群

实验环境 系统: ubuntu24.04 cat /etc/hosts 192.168.0.71 jichao71 192.168.0.72 jichao72 192.168.0.73 jichao73 192.168.0.74 jichao74 192.168.0.75 jichao75 主节点安装ansible #...

cnzzs的博客 1151

WPS占用C盘空间解决方案与优化技巧

办公软件在长期使用过程中会产生大量缓存和历史文件,这些文件往往隐藏在系统目录中,导致磁盘空间被无声占用。以WPS为例,其版本历史备份、云同步缓存和模板库是主要空间占用源。通过分析文件存储机制,可以定位到具体的缓存路径,如AppData目录下的Kingsoft文件夹。针对这一问题,有效的解决方案包括手动清理、自动化脚本和注册表优化。对于需要持续监控的场景,可以结合PowerShell脚本和任务计划实现自动化管理。在实际应用中,这些技术不仅适用于WPS,也可迁移到其他办公软件的空间优化中,是每位IT运维人员和高

weixin_30788239的博客 468

【ansible/K8s】K8s的自动化部署源码分享

采用 ​​Ubuntu 作为我们的操作系统。

sweetsounding的博客 680

【深度学习】肺结节分割项目实战二:分割肺实质

在后续训练模型的时候如果直接使用原始的肺部CT图像,其中的非肺区域会对训练造成干扰,因此我们需要提取分割肺实质。这一部分参考了kaggle上的教程。 从这张CT图像中可以看出扫描器以外的部分为黑色,背景和肺内部颜色较深,非肺组织和骨头颜色较浅。我们的目的是将肺部分割出来。由于肺部区域和其他部分对比明显,我们可以设置一个合适的阈值对图像中的区域进行隔离。 import argparse import os import numpy as np from medpy.filter.smoothing imp

weixin_42182906的博客 7248

Node-RED教程(一):Node-RED的介绍与安装

最新最全的Node-RED,node-red教程都在这里。 本篇介绍node-red的安装。使用docker 安装node-red

知无涯 3万+

Kubeasz快速部署高可用k8s集群入门到实战

Kubeasz快速部署高可用k8s集群入门到实战

虽非技冠群英首,愿与同道共长歌; 大鹏一日同风起,扶摇直上九万里; 1234

连接参数详解:Connection Interval, Slave Latency, Supervision Timeout 的协同与调优实战

在低功耗蓝牙(BLE)开发与调试中,Connection Interval(连接间隔)、Slave Latency(从机延迟) 和 Supervision Timeout(监督超时) 是三个核心参数。它们不仅直接影响设备的通信性能、功耗表现和连接稳定性,更是各类技术面试与认证考试的高频考点。本文将从基础概念出发,深入剖析三者的协同机制,结合历年真题解析考点与解题思路,并通过实战案例演示调优方法,快速掌握这一核心知识点。

byte轻骑兵的技术小窝 2768

K8s 高可用集群部署

在家没事重新学习一下k8s操作,从安装开始,部署一套自己开发的运维系统,涉及k8s、redis、mysql、mongodb、argoCD、jenkins、go语言、containerd、gitlab、harbor等(找工作太难了好多东西都忘了没法面,有问题的可以联系大家一起沟通进步)

weixin_50848244的博客 250

最全教程cadence建立个人CIS数据库

此时如果你删除office365,再装Access数据库,可以安装上,然后你再装office365,系统又会把Access软件给你删除掉,因为冲突了。可以在自己的电脑上新建CIS库,主要包含下面几个内容:数据库文件,原理图封装,PCB封装,数据手册,另外建议做一个器件命名的说明。allegro在调用封装的时候,是看的.psm文件,而不是.dra文件,因此只要是c0402.psm,那么所有的内容都要保持一致。(1)文件夹不要有中文,不要有空格,否则无法识别,可以参考博主的方式,全部使用英文输入法下划线。

D_Katter的博客 267

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

使用ansible脚本30分钟部署一套生产可用kubernetes集群(最新版 1.28.3 集群二进制部署)

本项目采用ansible进行kubernetes的二进制部署,帮助需要的伙伴快速部署一套生产可以用的 k8s 集群。

CodingDemo 2957

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

K8s 1.30.10离线部署全攻略

在 Ansible 主控机上创建以下目录结构,并将所有文件放入对应位置。

xiaoxiangsiyan的博客 473

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

企业级边缘K8s落地实战:VMware Workstation + k3s 1.30 LTS一键离线部署方案(限免配置模板)

企业级边缘K8s落地难题一招解决:基于VMware搭建k3s轻量K8s,适配离线环境与资源受限边缘节点;采用Workstation虚拟化+ k3s 1.30 LTS一键部署,支持限免配置模板复用。部署快、开销低、运维简,值得收藏。

simcode的专栏 173

ansible一键部署k8s(自动化)

ANSIBLE(自动化)一键部署k8s 主要使用ansible工具来批量管理我们需要的主机,这些主机通过接收我们编写的playbook文件来部署k8s集群,以此来实现我们的自动化部署。 ansible是新出现的自动化运维工具,基于Python开发,集合了众多运维工具(puppet、cfengine、chef、func、fabric)的优点,实现了批量系统配置、批量程序部署、批量运行命令等功能。ansible是基于模块工作的,本身没有批量部署的能力。真正具有批量部署的是ansible所运行的模块,ansib

weixin_48753359的博客 8184

k8s 一键部署(ansible)

前面我写了关于k8s环境部署的几篇文章,k8s部署还是比较麻烦的,所以是有必要考虑一键部署的方案,这里借助ansible playbook来实现k8s环境的一键部署,实现快速部署的目的。Kubernetes(k8s)安装以及搭建k8s-Dashboard详解Kubernetes(k8s)最新版最完整版环境部署+master高可用实现(k8sV1.24.1+dashboard+harbor)Ansible 介绍与实战操作演示Ansible playbook 讲解与实战操作节点信息主机名IP角色操作系统。

m0_71079519的博客 3284

Ansible for Kubernetes实战:5个核心示例详解Kubernetes自动化部署

Ansible for Kubernetes是一个专注于提供Ansible与Kubernetes集成示例的项目,源自《Ansible for Kubernetes》一书,通过实战案例帮助用户掌握使用Ansible实现Kubernetes自动化部署的核心技能。本文将详细介绍5个精选示例,展示如何利用Ansible简化Kubernetes集群管理、应用部署和容器生命周期管理。 ## 1. 本地多节点

gitblog_00870的博客 1077
上一篇: Harbor部署
下一篇: istio部署1.22.0
leepongmin
博客等级 码龄7年 439粉丝 10原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值