首页 > 其他分享 >kubspray使用,kubespary优化download过程

kubspray使用,kubespary优化download过程

时间:2024-11-10 17:58:45浏览次数:1  
标签:name image kubespary apt download kubspray kubeadm k8s

ubuntu安装k8s二进制文件

# 更新包列表并安装 HTTPS 支持
sudo apt-get update && sudo apt-get install -y apt-transport-https

# 创建 keyrings 目录(若已存在不会报错)
sudo mkdir -p /etc/apt/keyrings

# 下载并添加阿里云 Kubernetes 镜像的 GPG 密钥
curl -fsSL https://mirrors.aliyun.com/kubernetes-new/core/stable/v1.28/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg

# 添加 Kubernetes 阿里云镜像源
echo "deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://mirrors.aliyun.com/kubernetes-new/core/stable/v1.28/deb/ /" | sudo tee /etc/apt/sources.list.d/kubernetes.list

# 再次更新包列表以从新添加的 Kubernetes 源中获取信息
sudo apt-get update

# 安装 kubelet、kubeadm 和 kubectl
sudo apt-get install -y kubelet kubeadm kubectl

# 锁定版本,防止自动升级
sudo apt-mark hold kubelet kubeadm kubectl

镜像镜像转移到阿里云

image.sh

kubeadm config images list | grep k8s | while read image; do
  # 从 image 中提取镜像名称和标签
  image_name=$(echo $image | sed -E 's#(.*)/([^:]+):(.*)#\2:\3#')
  tag=$(echo $image | sed -E 's#(.*)/([^:]+):(.*)#\3#')
  
  # 拼接新的镜像地址
  new_image="registry.cn-hangzhou.aliyuncs.com/k8s-a/$image_name"
  
  # 检查该镜像是否已经存在本地
  if ! docker images | grep -q "$new_image"; then
    echo "Pushing image: $new_image"
    docker push "$new_image"
  else
    echo "Image $new_image already exists locally, skipping push."
  fi
done
sh image.sh

从阿里云同步镜像到harbor

  1. 点击仓库管理,点击新建目标,
  2. 提供者,选择Alibaba ACR,目标名,k8s-a(自己定义),目标URL,https://registry.cn-hangzhou.aliyuncs.com,访问ID,访问密码,对应阿里云的RAM访问的AccessKey
  3. 点击测试连接
  4. 点击复制管理,点击新建规则,
  5. 名称,k8s-a,复制模式,选择Pull-based,源仓库,k8s-a-https://registry.cn-hangzhou.aliyuncs.com,触发模式,手动,点击保存
  6. 选中k8s-a规则左侧圆点,点击复制,再次点击复制,任务开始执行
  7. 点击下方任务id,查看复制任务信息,查看成功失败信息,失败的可以查看失败日志

下载镜像和二进制文件

roles/download/tasks/main.yml

同步二进制文件到本地

cat roles/download/tasks/main.yml
---
- name: Download | Prepare working directories and variables
  import_tasks: prep_download.yml
  when:
    - not skip_downloads | default(false)
  tags:
    - download
    - upload

- name: Download | Get kubeadm binary and list of required images
  include_tasks: prep_kubeadm_images.yml
  when:
    - not skip_downloads | default(false)
    - inventory_hostname in groups['kube_control_plane']
  tags:
    - download
    - upload

- name: Print combined download variable
  debug:
    msg: |
      Combined Download: {{ downloads | combine(kubeadm_images) | dict2items }}
  vars:
    download: "{{ download_defaults | combine(item.value) }}"
  tags:
    - download
    - upload

- name: Print combined download variable
  debug:
    msg: "nerdctl pull {{ download.repo  }}: {{ download.tag }}"
  loop: "{{ downloads | combine(kubeadm_images) | dict2items }}"
  vars:
    download: "{{ download_defaults | combine(item.value) }}"
    include_file: "download_{% if download.container %}container{% else %}file{% endif %}.yml"
  tags:
    - download
    - upload


- name: Write combined download commands to a file
  blockinfile:
    path: /tmp/output_file.sh
    marker: "# {mark} ANSIBLE GENERATED BLOCK"
    block: |
      {% for item in downloads | combine(kubeadm_images) | dict2items %}
      {% set download = download_defaults | combine(item.value) %}
      nerdctl pull {{ download.repo }}:{{ download.tag }}
      {% endfor %}
  vars:
    download_defaults:  # 设置默认值
      repo: ""
      tag: ""
  tags:
    - download
    - upload



- name: Pause for manual intervention
  pause:
    prompt: "Press Enter to continue or Ctrl+C to stop the playbook"


- name: Download | Download files / images
  include_tasks: "{{ include_file }}"
  loop: "{{ downloads | combine(kubeadm_images) | dict2items }}"
  vars:
    download: "{{ download_defaults | combine(item.value) }}"
    include_file: "download_{% if download.container %}container{% else %}file{% endif %}.yml"
  when:
    - not skip_downloads | default(false)
    - download.enabled
    - item.value.enabled
    - (not (item.value.container | default(false))) or (item.value.container and download_container)
    - (download_run_once and inventory_hostname == download_delegate) or (group_names | intersect(download.groups) | length)

初始化k8s


#没有配置好,想办法下载一个指定版本的git代码包
git clone --branch v1.29.0 --depth 1 https://github.com/kubernetes/kubernetes.git kubernetesv1.29.0

#安装ansible
pip install ansible-core==2.17 -i https://pypi.tuna.tsinghua.edu.cn/simple/

#安装开发包
yum install python3-pip python3-devel -y

#设置全局python版本
pyenv global 3.12.0

#安装k8s集群
ansible-playbook -i inventory/mycluster/inventory.ini --become cluster.yml

安装集群报错

标签:name,image,kubespary,apt,download,kubspray,kubeadm,k8s
From: https://www.cnblogs.com/anyux/p/18538265

相关文章

  • HDK Fileheader Download(2.0)
    HDKFileheaderLibraryDownload2.0Download1.13|1.13.1|1.13.2|1.13.3|1.13.4Download1.12|1.12.1|1.12.2Download1.11Download1.10|1.10.1Download1.9Download1.8|ForLinuxDownload1.7|1.7.1|1.7.2Download1.6Download1.5Downloa......
  • 面对addownload.dll无法打开,如何快速找到解决办法?
    在使用Windows操作系统时,我们可能会遇到各种DLL文件无法打开或加载的问题,其中addownload.dll就是一个例子。这个DLL文件可能与特定的应用程序或服务相关联,当它无法被正确加载或打开时,可能会导致应用程序崩溃、系统错误或性能下降。本文将为您提供一系列快速找到并解决addownloa......
  • save download pdf
    packagecn.didisos.sos.fams.controller;importorg.apache.http.HttpEntity;importorg.apache.http.HttpResponse;importorg.apache.http.HttpStatus;importorg.apache.http.client.methods.HttpPost;importorg.apache.http.impl.client.CloseableHttpClient;importorg......
  • 单月30k+ Downloads!一款头部Embedding开源模型
    在数字化转型的浪潮中,文本数据的处理和分析成为了各行各业关注的焦点。如何将人类阅读的文本转换为机器可理解的形式,并且能够准确地召回和提取这些转换结果,成为了提升我们工作效率和体验的关键。无论是从社交媒体中提取情感倾向,还是对大量文档进行内容相似性分析,或是在复杂的对话......
  • IDM下载器 (Internet Download Manager) v6.42.2 中文免激活绿色版
    InternetDownloadManager(IDM下载器)是一款先进的下载工具,可以提升您的下载速度高达5倍,支持续传,IDM可以让用户自动下载某些类型的文件,它可将文件划分为多个下载点以更快速度下载,并列出最近的下载,方便访问文件。相对于其它下载管理工具,它具有独特的动态档案分区技术。......
  • How to Download YouTube Videos for Free
     However,therearetimeswhenyoumaywanttodownloadYouTubevideosforofflineviewing,suchaswhenyou'retravelingwithoutareliableinternetconnectionorwanttosaveafavoritevideoforlater.Inthisarticle,wewillexploresomemethod......
  • 一条命令激活Internet Download Manager
     admin • 2023-09-12上午7:03 • 免费资源, 杂谈 • 阅读88使用InternetDownloadManager可以使用如下命令激活在科学联网情况下,复制这条命令irmhttps://massgrave.dev/ias|iexWin8.1/Win10/Win11系统下,在windows徽标上单击鼠标右键,在弹出的菜单中选择”windo......
  • Error: Failed to download metadata for repo ‘update‘
    安装Rsync时报错:通常原因为从openEuler的官方仓库更新元数据时遇到超时或连接失败的问题。更换镜像源#移除旧的镜像源[[email protected]]#mv/etc/yum.repos.d/openEuler.repo/etc/yum.repos.d/openEuler.repo.bak#替换国产openEuler镜像源[root@nginx1yum......
  • yt downloader website
     isanonlinewebsitethatoffersaconvenienttoolfordownloadingcontentfromYouTube. Whatisit?Itisknownasytdownloader,whichisafreeonlineYouTubedownloadtool.ItprovidesuserswithaneasywaytoobtainvarioustypesofmediafromYo......
  • 数学分解软件CNum2025下载download
    本软件可以算单个整数的因式分解。本软件可以算2个整数的最大公因数、最小公倍数。本软件可以判断输入的整数是否是素数或者合数。本软件支持中英文双语界面,可以打开、保存和清空工作数据。本软件是共享软件,支持软件,可以获得更好的未来的软件。Thissoftwarecancalculatet......