配置containerd与Harbor连接

1.修改containerd配置文件

vim /etc/containerd/config.toml

[plugins."io.containerd.grpc.v1.cri".registry.configs]    #找到这一行,在添加如下5行
  [plugins."io.containerd.grpc.v1.cri".registry.configs."192.168.200.101:88".tls]   #这里定义了一个名为192.168.200.101:88的 registry 配置
    insecure_skip_verify = true  #表示跳过 TLS 证书的安全验证,也就是不验证证书的有效性
  [plugins."io.containerd.grpc.v1.cri".registry.configs."192.168.200.101:88".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.200.101:88"]
    endpoint = ["http://192.168.200.101:88"]    #这两行主要定义使用 192.168.200.101:88 作为容器镜像的默认仓库,拉取镜像。
#重启containerd
systemctl restart containerd.service 

注意:所有工作节点都需要配置

2.上传镜像

#登录harbor
docker login 192.168.200.101 -u admin -p Harbor12345

#下载nginx镜像
docker pull nginx
#打标签  
docker tag nginx:latest 192.168.200.101/test01/nginx:v1

#上传至仓库
docker push 192.168.200.101/test01/nginx:v1

注意:这里test01仓库已在Harbor创建

3.在k8s上使用Harbor镜像

#创建一个pod使用nginx:v1的镜像

vim nginx.yaml

apiVersion: v1
kind: Pod
metadata:
  name: nginx
spec:
  containers:
  - name: nginx
    image: 192.168.200.101:88/test01/nginx:v1
    ports:
    - containerPort: 88
      hostPort: 88
kubectl apply -f nginx.yaml
#查看pod
root@k8s-master01:~# kubectl describe pod nginx |grep Image
    Image:          192.168.200.101:88/test01/nginx:v1
    Image ID:       192.168.200.101:88/test01/nginx@sha256:066edc156bcada86155fd88ae03667cf3811c499df73815a2b76e43755ebbc76
Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐