K8S基于containerd做容器从harbor拉取镜

实现创建pod时,通过指定harbor仓库里的镜像来运行pod

检查:K8S是不是用containerd做容器运行时,以及containerd的版本是不是小于1.6.22

kubectl get nodes -owide

在这里插入图片描述
1、如果containerd小于 1.6.22,需要先升级containerd

先卸载旧的,再下载1.6.22版本的containerd(每个节点都执行)

yum remove containerd.io -y
 yum install containerd.io-1.6.22*  -y

2、更换配置文件(每个节点都执行)

 cd /etc/containerd/
rm -rf *

把config.toml文件传到 /etc/containerd/目录下

config.toml文件:

disabled_plugins = []
imports = []
oom_score = 0
plugin_dir = ""
required_plugins = []
root = "/var/lib/containerd"
state = "/run/containerd"
temp = ""
version = 2[cgroup]path = ""[debug]address = ""format = ""gid = 0level = ""uid = 0[grpc]address = "/run/containerd/containerd.sock"gid = 0max_recv_message_size = 16777216max_send_message_size = 16777216tcp_address = ""tcp_tls_ca = ""tcp_tls_cert = ""tcp_tls_key = ""uid = 0[metrics]address = ""grpc_histogram = false[plugins][plugins."io.containerd.gc.v1.scheduler"]deletion_threshold = 0mutation_threshold = 100pause_threshold = 0.02schedule_delay = "0s"startup_delay = "100ms"[plugins."io.containerd.grpc.v1.cri"]device_ownership_from_security_context = falsedisable_apparmor = falsedisable_cgroup = falsedisable_hugetlb_controller = truedisable_proc_mount = falsedisable_tcp_service = trueenable_selinux = falseenable_tls_streaming = falseenable_unprivileged_icmp = falseenable_unprivileged_ports = falseignore_image_defined_volumes = falsemax_concurrent_downloads = 3max_container_log_line_size = 16384netns_mounts_under_state_dir = falserestrict_oom_score_adj = falsesandbox_image = "registry.aliyuncs.com/google_containers/pause:3.7"selinux_category_range = 1024stats_collect_period = 10stream_idle_timeout = "4h0m0s"stream_server_address = "127.0.0.1"stream_server_port = "0"systemd_cgroup = falsetolerate_missing_hugetlb_controller = trueunset_seccomp_profile = ""[plugins."io.containerd.grpc.v1.cri".cni]bin_dir = "/opt/cni/bin"conf_dir = "/etc/cni/net.d"conf_template = ""ip_pref = ""max_conf_num = 1[plugins."io.containerd.grpc.v1.cri".containerd]default_runtime_name = "runc"disable_snapshot_annotations = truediscard_unpacked_layers = falseignore_rdt_not_enabled_errors = falseno_pivot = falsesnapshotter = "overlayfs"[plugins."io.containerd.grpc.v1.cri".containerd.default_runtime]base_runtime_spec = ""cni_conf_dir = ""cni_max_conf_num = 0container_annotations = []pod_annotations = []privileged_without_host_devices = falseruntime_engine = ""runtime_path = ""runtime_root = ""runtime_type = ""[plugins."io.containerd.grpc.v1.cri".containerd.default_runtime.options][plugins."io.containerd.grpc.v1.cri".containerd.runtimes][plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc]base_runtime_spec = ""cni_conf_dir = ""cni_max_conf_num = 0container_annotations = []pod_annotations = []privileged_without_host_devices = falseruntime_engine = ""runtime_path = ""runtime_root = ""runtime_type = "io.containerd.runc.v2"[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc.options]BinaryName = ""CriuImagePath = ""CriuPath = ""CriuWorkPath = ""IoGid = 0IoUid = 0NoNewKeyring = falseNoPivotRoot = falseRoot = ""ShimCgroup = ""SystemdCgroup = true[plugins."io.containerd.grpc.v1.cri".containerd.untrusted_workload_runtime]base_runtime_spec = ""cni_conf_dir = ""cni_max_conf_num = 0container_annotations = []pod_annotations = []privileged_without_host_devices = falseruntime_engine = ""runtime_path = ""runtime_root = ""runtime_type = ""[plugins."io.containerd.grpc.v1.cri".containerd.untrusted_workload_runtime.options][plugins."io.containerd.grpc.v1.cri".image_decryption]key_model = "node"[plugins."io.containerd.grpc.v1.cri".registry]config_path = ""[plugins."io.containerd.grpc.v1.cri".registry.auths][plugins."io.containerd.grpc.v1.cri".registry.configs][plugins."io.containerd.grpc.v1.cri".registry.configs."192.168.40.184".tls]insecure_skip_verify = true[plugins."io.containerd.grpc.v1.cri".registry.configs."192.168.40.184".auth]username = "admin"password = "Harbor12345"[plugins."io.containerd.grpc.v1.cri".registry.headers][plugins."io.containerd.grpc.v1.cri".registry.mirrors][plugins."io.containerd.grpc.v1.cri".registry.mirrors."192.168.40.184"]endpoint = ["https://192.168.40.184:443"][plugins."io.containerd.grpc.v1.cri".registry.mirrors."docker.io"]endpoint = ["https://vh3bm52y.mirror.aliyuncs.com","https://registry.docker-cn.com"][plugins."io.containerd.grpc.v1.cri".x509_key_pair_streaming]tls_cert_file = ""tls_key_file = ""[plugins."io.containerd.internal.v1.opt"]path = "/opt/containerd"[plugins."io.containerd.internal.v1.restart"]interval = "10s"[plugins."io.containerd.internal.v1.tracing"]sampling_ratio = 1.0service_name = "containerd"[plugins."io.containerd.metadata.v1.bolt"]content_sharing_policy = "shared"[plugins."io.containerd.monitor.v1.cgroups"]no_prometheus = false[plugins."io.containerd.runtime.v1.linux"]no_shim = falseruntime = "runc"runtime_root = ""shim = "containerd-shim"shim_debug = false[plugins."io.containerd.runtime.v2.task"]platforms = ["linux/amd64"]sched_core = false[plugins."io.containerd.service.v1.diff-service"]default = ["walking"][plugins."io.containerd.service.v1.tasks-service"]rdt_config_file = ""[plugins."io.containerd.snapshotter.v1.aufs"]root_path = ""[plugins."io.containerd.snapshotter.v1.btrfs"]root_path = ""[plugins."io.containerd.snapshotter.v1.devmapper"]async_remove = falsebase_image_size = ""discard_blocks = falsefs_options = ""fs_type = ""pool_name = ""root_path = ""[plugins."io.containerd.snapshotter.v1.native"]root_path = ""[plugins."io.containerd.snapshotter.v1.overlayfs"]root_path = ""upperdir_label = false[plugins."io.containerd.snapshotter.v1.zfs"]root_path = ""[plugins."io.containerd.tracing.processor.v1.otlp"]endpoint = ""insecure = falseprotocol = ""[proxy_plugins][stream_processors][stream_processors."io.containerd.ocicrypt.decoder.v1.tar"]accepts = ["application/vnd.oci.image.layer.v1.tar+encrypted"]args = ["--decryption-keys-path", "/etc/containerd/ocicrypt/keys"]env = ["OCICRYPT_KEYPROVIDER_CONFIG=/etc/containerd/ocicrypt/ocicrypt_keyprovider.conf"]path = "ctd-decoder"returns = "application/vnd.oci.image.layer.v1.tar"[stream_processors."io.containerd.ocicrypt.decoder.v1.tar.gzip"]accepts = ["application/vnd.oci.image.layer.v1.tar+gzip+encrypted"]args = ["--decryption-keys-path", "/etc/containerd/ocicrypt/keys"]env = ["OCICRYPT_KEYPROVIDER_CONFIG=/etc/containerd/ocicrypt/ocicrypt_keyprovider.conf"]path = "ctd-decoder"returns = "application/vnd.oci.image.layer.v1.tar+gzip"[timeouts]"io.containerd.timeout.bolt.open" = "0s""io.containerd.timeout.shim.cleanup" = "5s""io.containerd.timeout.shim.load" = "5s""io.containerd.timeout.shim.shutdown" = "3s""io.containerd.timeout.task.state" = "2s"[ttrpc]address = ""gid = 0uid = 0

修改config.toml配置文件里的信息:
1、harbor的ip地址,变成自己真实环境的harbor的ip
2、改为自己的harbor账号和密码
在这里插入图片描述
3、重启containerd(每个节点都执行)

systemctl restart containerd

4、查看重启后的状态(每个节点都执行)

systemctl status containerd

在这里插入图片描述
5、把docker也再重新安装一下(每个节点都执行)

PS. 用containerd跑容器,用docker做镜像

yum install docker-ce -y
systemctl start docker

6、将镜像上传到harbor(node节点执行)

先拉取一个docker仓库里的镜像到本地

docker pull nginx

在这里插入图片描述
重新打镜像标签,标签规范

  • 192.168.40.184:harbor的IP地址
  • library:harbor里的项目名称
docker tag docker.io/library/nginx:latest 192.168.40.184/library/nginx:v1.6

在这里插入图片描述

vim /etc/docker/daemon.json
{"registry-mirrors":["https://vh3bm52y.mirror.aliyuncs.com","https://registry.docker-cn.com","https://docker.mirrors.ustc.edu.cn","https://dockerhub.azk8s.cn","http://hub-mirror.c.163.com"],
"insecure-registries": ["192.168.40.184","harbor"]
}

在这里插入图片描述
改配置后,重启docker使配置生效

systemctl restart docker

在node节点配置harbor主机名

vim /etc/hosts

在这里插入图片描述
登录harbor

docker login 192.168.40.184

在这里插入图片描述
上传镜像到harbor

docker push 192.168.40.184/library/nginx:v1.6

在这里插入图片描述
7、创建pod,从harbor上拉取镜像(master节点执行)

vim pod.yaml
apiVersion: v1
kind: Pod
metadata:name: nginxnamespace: default
spec:containers:- name: nginximage: 192.168.40.184/library/nginx:v1.6 # 镜像指定刚刚上传到harbor上的imagePullPolicy: Always

创建资源

kubectl apply -f pod.yaml

查看pod

kubectl get pods | grep nginx

已成功运行
在这里插入图片描述

kubectl describe pod nginx

使用的是harbor里的镜像
在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/598298.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

金三银四面试题(十六):MySQL面试都问什么(1)

在开发岗位面试中,MySQL基本是必考环节。所以接下来我们就进入MySQL八股文环节,看看都有哪些高频考题。 MySQL 中有哪些不同的表格? 在MySQL中,可以创建多种不同类型的表格,其中一些常见的类型包括: InnoD…

【边缘智能】00_边缘计算发展背景

本系列是个人学习《边缘就算基础知识入门》的笔记,仅为个人学习记录,欢迎交流,感谢批评指正 移动物联设备产生海量数据,数据密集型移动智能应用,计算密集、动态性高,实时性强 传统云计算架构 基于广域互联…

不开玩笑,你应该像「搬砖」一样写代码!斯坦福大学研究如是说

由于程序员不可避免要进行很多重复性的工作,并且工作强度很高,导致有一种自嘲的说法出现:程序员们自称自己每天都在搬砖(实际上很多职场人都这么自嘲)。我相信当我们说工作像「搬砖」的时候,只是在表达一种…

谷歌DeepMind发布Gecko:专攻检索,与大7倍模型相抗衡

ChatGPT狂飙160天,世界已经不是之前的样子。 新建了免费的人工智能中文站https://ai.weoknow.com 新建了收费的人工智能中文站https://ai.hzytsoft.cn/ 更多资源欢迎关注 Gecko 是一种通用的文本嵌入模型,可用于训练包括文档检索、语义相似度和分类等各…

2-django、http、web框架、django及django请求生命周期、路由控制、视图层

1 http 2 web框架 3 django 3.1 django请求生命周期 4 路由控制 5 视图层 1 http #1 http 是什么 #2 http特点 #3 请求协议详情-请求首行---》请求方式,请求地址,请求协议版本-请求头---》key:value形式-referer:上一次访问的地址-user-agen…

一开始我只是接单试试水而已,后来我居然财富自由了!

一开始我只是抱着试一试的心态,浅浅的尝试了一下网上接单,没办法,这风太大了!网上个个儿说的神乎其神的,尤其是动不动就几十W,没办法,我眼红啦!赚钱嘛,不丢人&#xff01…

【JavaWeb】百度地图API SDK导入

百度地图开放平台 | 百度地图API SDK | 地图开发 (baidu.com) 登录注册,创建应用,获取AK 地理编码 | 百度地图API SDK (baidu.com) 需要的接口一:获取店铺/用户 所在地址的经纬度坐标 轻量级路线规划 | 百度地图API SDK (baidu.com) 需要的…

图片批量高效管理,图片像素缩放支持自定义操作,让图像处理更轻松

在数字化时代,图片管理成为了我们生活和工作中不可或缺的一部分。无论是个人用户还是企业用户,都需要对大量的图片进行有效的管理和处理。然而,面对众多的图片,如何进行批量管理并对其进行像素缩放成为了一个挑战,该如…

【Linux】指令

1. 简单指令 whoami 显示当前登入账号名 ls /home 现在有的用户名 adduser 用户名 新加用户(必须在root目录下) passwd 用户名 给这个用户设置密码 userdel -r 用户名 删除这个用户 pwd 显示当前所处路径 stat 文件名 / 文件夹名 显示文件状…

基于JAVA+SSM+微信小程序+MySql的图书捐赠管理系统设计与实现(前后端分类)

一、项目背景介绍: 在当今社会,图书捐赠是一种普遍而有益的行为,旨在促进阅读、教育和知识传播。图书捐赠可以帮助改善教育资源不足的地区、学校和社区的阅读环境,提供更多的学习机会和知识获取途径。随着互联网和移动技术的发展&…

入门MyBatis

文章目录 入门MyBatisMyBatis快速入门创建user表添加数据创建模块导入坐标编写Mybatis核心配置文件编写SQL映射文件编码 使用idea编写sql代码链接数据库调出console控制台 Mapper代理开发定义与SQL映射文件同名的Mapper接口编码 MyBatis核心配置文件安装mybatisx插件配置文件完…

MES系统 DE 生产绩效功能及分析

在制造企业中,绩效管理是一项至关重要的工作。通过科学有效的绩效管理,能够帮助企业提高生产效率、优化资源配置、提升员工积极性,从而实现持续发展。什么是制造企业的绩效管理? 制造企业的绩效管理是指通过设定明确的目标和标准&…